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", |
| 26 | |
| 27 | // arm + arm64 + mips + mips64 |
| 28 | "-fgcse-after-reload", |
| 29 | "-frerun-cse-after-loop", |
| 30 | "-frename-registers", |
| 31 | "-fno-strict-volatile-bitfields", |
| 32 | |
| 33 | // arm + arm64 |
| 34 | "-fno-align-jumps", |
| 35 | "-Wa,--noexecstack", |
| 36 | |
| 37 | // arm |
| 38 | "-mthumb-interwork", |
| 39 | "-fno-builtin-sin", |
| 40 | "-fno-caller-saves", |
| 41 | "-fno-early-inlining", |
| 42 | "-fno-move-loop-invariants", |
| 43 | "-fno-partial-inlining", |
| 44 | "-fno-tree-copy-prop", |
| 45 | "-fno-tree-loop-optimize", |
| 46 | |
| 47 | // mips + mips64 |
| 48 | "-msynci", |
| 49 | "-mno-fused-madd", |
| 50 | |
| 51 | // x86 + x86_64 |
| 52 | "-finline-limit=300", |
| 53 | "-fno-inline-functions-called-once", |
| 54 | "-mfpmath=sse", |
| 55 | "-mbionic", |
| 56 | } |
| 57 | |
| 58 | func init() { |
| 59 | sort.Strings(clangUnknownCflags) |
| 60 | |
| 61 | pctx.StaticVariable("clangExtraCflags", strings.Join([]string{ |
| 62 | "-D__compiler_offsetof=__builtin_offsetof", |
| 63 | |
| 64 | // Help catch common 32/64-bit errors. |
| 65 | "-Werror=int-conversion", |
| 66 | |
| 67 | // Workaround for ccache with clang. |
| 68 | // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. |
| 69 | "-Wno-unused-command-line-argument", |
| 70 | |
| 71 | // Disable -Winconsistent-missing-override until we can clean up the existing |
| 72 | // codebase for it. |
| 73 | "-Wno-inconsistent-missing-override", |
| 74 | }, " ")) |
| 75 | |
| 76 | pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{ |
| 77 | "-std=gnu99", |
| 78 | }, " ")) |
| 79 | |
| 80 | pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{ |
| 81 | "-nostdlibinc", |
| 82 | }, " ")) |
| 83 | } |
| 84 | |
| 85 | func clangFilterUnknownCflags(cflags []string) []string { |
| 86 | ret := make([]string, 0, len(cflags)) |
| 87 | for _, f := range cflags { |
| 88 | if !inListSorted(f, clangUnknownCflags) { |
| 89 | ret = append(ret, f) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return ret |
| 94 | } |
| 95 | |
| 96 | func inListSorted(s string, list []string) bool { |
| 97 | for _, l := range list { |
| 98 | if s == l { |
| 99 | return true |
| 100 | } else if s < l { |
| 101 | return false |
| 102 | } |
| 103 | } |
| 104 | return false |
| 105 | } |