Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | package cc |
| 2 | |
| 3 | import ( |
| 4 | "sort" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // Cflags that should be filtered out when compiling with clang |
| 9 | var clangUnknownCflags = []string{ |
| 10 | "-finline-functions", |
| 11 | "-finline-limit=64", |
| 12 | "-fno-canonical-system-headers", |
| 13 | "-fno-tree-sra", |
Colin Cross | a360e8b | 2015-03-16 16:22:28 -0700 | [diff] [blame] | 14 | "-fprefetch-loop-arrays", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 15 | "-funswitch-loops", |
| 16 | "-Wmaybe-uninitialized", |
| 17 | "-Wno-error=maybe-uninitialized", |
| 18 | "-Wno-free-nonheap-object", |
| 19 | "-Wno-literal-suffix", |
| 20 | "-Wno-maybe-uninitialized", |
| 21 | "-Wno-old-style-declaration", |
| 22 | "-Wno-psabi", |
| 23 | "-Wno-unused-but-set-variable", |
| 24 | "-Wno-unused-but-set-parameter", |
| 25 | "-Wno-unused-local-typedefs", |
Colin Cross | 62ec5f4 | 2015-03-18 17:20:28 -0700 | [diff] [blame] | 26 | "-Wunused-but-set-parameter", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | |
| 28 | // arm + arm64 + mips + mips64 |
| 29 | "-fgcse-after-reload", |
| 30 | "-frerun-cse-after-loop", |
| 31 | "-frename-registers", |
| 32 | "-fno-strict-volatile-bitfields", |
| 33 | |
| 34 | // arm + arm64 |
| 35 | "-fno-align-jumps", |
| 36 | "-Wa,--noexecstack", |
| 37 | |
| 38 | // arm |
| 39 | "-mthumb-interwork", |
| 40 | "-fno-builtin-sin", |
| 41 | "-fno-caller-saves", |
| 42 | "-fno-early-inlining", |
| 43 | "-fno-move-loop-invariants", |
| 44 | "-fno-partial-inlining", |
| 45 | "-fno-tree-copy-prop", |
| 46 | "-fno-tree-loop-optimize", |
| 47 | |
| 48 | // mips + mips64 |
| 49 | "-msynci", |
| 50 | "-mno-fused-madd", |
| 51 | |
| 52 | // x86 + x86_64 |
| 53 | "-finline-limit=300", |
| 54 | "-fno-inline-functions-called-once", |
| 55 | "-mfpmath=sse", |
| 56 | "-mbionic", |
| 57 | } |
| 58 | |
| 59 | func init() { |
| 60 | sort.Strings(clangUnknownCflags) |
| 61 | |
| 62 | pctx.StaticVariable("clangExtraCflags", strings.Join([]string{ |
| 63 | "-D__compiler_offsetof=__builtin_offsetof", |
| 64 | |
| 65 | // Help catch common 32/64-bit errors. |
| 66 | "-Werror=int-conversion", |
| 67 | |
| 68 | // Workaround for ccache with clang. |
| 69 | // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. |
| 70 | "-Wno-unused-command-line-argument", |
| 71 | |
| 72 | // Disable -Winconsistent-missing-override until we can clean up the existing |
| 73 | // codebase for it. |
| 74 | "-Wno-inconsistent-missing-override", |
| 75 | }, " ")) |
| 76 | |
| 77 | pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{ |
| 78 | "-std=gnu99", |
| 79 | }, " ")) |
| 80 | |
| 81 | pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{ |
| 82 | "-nostdlibinc", |
| 83 | }, " ")) |
| 84 | } |
| 85 | |
| 86 | func clangFilterUnknownCflags(cflags []string) []string { |
| 87 | ret := make([]string, 0, len(cflags)) |
| 88 | for _, f := range cflags { |
| 89 | if !inListSorted(f, clangUnknownCflags) { |
| 90 | ret = append(ret, f) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return ret |
| 95 | } |
| 96 | |
| 97 | func inListSorted(s string, list []string) bool { |
| 98 | for _, l := range list { |
| 99 | if s == l { |
| 100 | return true |
| 101 | } else if s < l { |
| 102 | return false |
| 103 | } |
| 104 | } |
| 105 | return false |
| 106 | } |