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 |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 9 | var clangUnknownCflags = sorted([]string{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 10 | "-finline-functions", |
| 11 | "-finline-limit=64", |
| 12 | "-fno-canonical-system-headers", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 13 | "-Wno-clobbered", |
| 14 | "-fno-devirtualize", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 15 | "-fno-tree-sra", |
Colin Cross | a360e8b | 2015-03-16 16:22:28 -0700 | [diff] [blame] | 16 | "-fprefetch-loop-arrays", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 17 | "-funswitch-loops", |
| 18 | "-Wmaybe-uninitialized", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 19 | "-Wno-error=clobbered", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | "-Wno-error=maybe-uninitialized", |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 21 | "-Wno-error=unused-but-set-parameter", |
| 22 | "-Wno-error=unused-but-set-variable", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "-Wno-free-nonheap-object", |
| 24 | "-Wno-literal-suffix", |
| 25 | "-Wno-maybe-uninitialized", |
| 26 | "-Wno-old-style-declaration", |
| 27 | "-Wno-psabi", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 28 | "-Wno-unused-but-set-parameter", |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 29 | "-Wno-unused-but-set-variable", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 30 | "-Wno-unused-local-typedefs", |
Colin Cross | 62ec5f4 | 2015-03-18 17:20:28 -0700 | [diff] [blame] | 31 | "-Wunused-but-set-parameter", |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 32 | "-Wunused-but-set-variable", |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 33 | "-fdiagnostics-color", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 34 | |
| 35 | // arm + arm64 + mips + mips64 |
| 36 | "-fgcse-after-reload", |
| 37 | "-frerun-cse-after-loop", |
| 38 | "-frename-registers", |
| 39 | "-fno-strict-volatile-bitfields", |
| 40 | |
| 41 | // arm + arm64 |
| 42 | "-fno-align-jumps", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 43 | |
| 44 | // arm |
| 45 | "-mthumb-interwork", |
| 46 | "-fno-builtin-sin", |
| 47 | "-fno-caller-saves", |
| 48 | "-fno-early-inlining", |
| 49 | "-fno-move-loop-invariants", |
| 50 | "-fno-partial-inlining", |
| 51 | "-fno-tree-copy-prop", |
| 52 | "-fno-tree-loop-optimize", |
| 53 | |
| 54 | // mips + mips64 |
| 55 | "-msynci", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 56 | "-mno-synci", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 57 | "-mno-fused-madd", |
| 58 | |
| 59 | // x86 + x86_64 |
| 60 | "-finline-limit=300", |
| 61 | "-fno-inline-functions-called-once", |
| 62 | "-mfpmath=sse", |
| 63 | "-mbionic", |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 64 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 65 | |
| 66 | func init() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 67 | pctx.StaticVariable("clangExtraCflags", strings.Join([]string{ |
| 68 | "-D__compiler_offsetof=__builtin_offsetof", |
| 69 | |
| 70 | // Help catch common 32/64-bit errors. |
| 71 | "-Werror=int-conversion", |
| 72 | |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 73 | // Disable overly aggressive warning for macros defined with a leading underscore |
| 74 | // This happens in AndroidConfig.h, which is included nearly everywhere. |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 75 | // TODO: can we remove this now? |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 76 | "-Wno-reserved-id-macro", |
| 77 | |
| 78 | // Disable overly aggressive warning for format strings. |
| 79 | // Bug: 20148343 |
| 80 | "-Wno-format-pedantic", |
| 81 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 82 | // Workaround for ccache with clang. |
| 83 | // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. |
| 84 | "-Wno-unused-command-line-argument", |
| 85 | |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 86 | // Force clang to always output color diagnostics. Ninja will strip the ANSI |
| 87 | // color codes if it is not running in a terminal. |
| 88 | "-fcolor-diagnostics", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 89 | }, " ")) |
| 90 | |
| 91 | pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{ |
| 92 | "-std=gnu99", |
| 93 | }, " ")) |
| 94 | |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 95 | pctx.StaticVariable("clangExtraCppflags", strings.Join([]string{ |
| 96 | // Disable -Winconsistent-missing-override until we can clean up the existing |
| 97 | // codebase for it. |
| 98 | "-Wno-inconsistent-missing-override", |
| 99 | }, " ")) |
| 100 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{ |
| 102 | "-nostdlibinc", |
| 103 | }, " ")) |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame^] | 104 | |
| 105 | pctx.StaticVariable("clangExtraNoOverrideCflags", strings.Join([]string{ |
| 106 | "-Werror=address-of-temporary", |
| 107 | "-Werror=null-dereference", |
| 108 | "-Werror=return-type", |
| 109 | }, " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | func clangFilterUnknownCflags(cflags []string) []string { |
| 113 | ret := make([]string, 0, len(cflags)) |
| 114 | for _, f := range cflags { |
| 115 | if !inListSorted(f, clangUnknownCflags) { |
| 116 | ret = append(ret, f) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return ret |
| 121 | } |
| 122 | |
| 123 | func inListSorted(s string, list []string) bool { |
| 124 | for _, l := range list { |
| 125 | if s == l { |
| 126 | return true |
| 127 | } else if s < l { |
| 128 | return false |
| 129 | } |
| 130 | } |
| 131 | return false |
| 132 | } |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 133 | |
| 134 | func sorted(list []string) []string { |
| 135 | sort.Strings(list) |
| 136 | return list |
| 137 | } |