1 package config 2 3 import ( 4 "sort" 5 "strings" 6 ) 7 8 // Cflags that should be filtered out when compiling with clang 9 var ClangUnknownCflags = sorted([]string{ 10 "-finline-functions", 11 "-finline-limit=64", 12 "-fno-canonical-system-headers", 13 "-Wno-clobbered", 14 "-fno-devirtualize", 15 "-fno-tree-sra", 16 "-fprefetch-loop-arrays", 17 "-funswitch-loops", 18 "-Werror=unused-but-set-parameter", 19 "-Werror=unused-but-set-variable", 20 "-Wmaybe-uninitialized", 21 "-Wno-error=clobbered", 22 "-Wno-error=maybe-uninitialized", 23 "-Wno-error=unused-but-set-parameter", 24 "-Wno-error=unused-but-set-variable", 25 "-Wno-free-nonheap-object", 26 "-Wno-literal-suffix", 27 "-Wno-maybe-uninitialized", 28 "-Wno-old-style-declaration", 29 "-Wno-psabi", 30 "-Wno-unused-but-set-parameter", 31 "-Wno-unused-but-set-variable", 32 "-Wno-unused-local-typedefs", 33 "-Wunused-but-set-parameter", 34 "-Wunused-but-set-variable", 35 "-fdiagnostics-color", 36 37 // arm + arm64 + mips + mips64 38 "-fgcse-after-reload", 39 "-frerun-cse-after-loop", 40 "-frename-registers", 41 "-fno-strict-volatile-bitfields", 42 43 // arm + arm64 44 "-fno-align-jumps", 45 46 // arm 47 "-mthumb-interwork", 48 "-fno-builtin-sin", 49 "-fno-caller-saves", 50 "-fno-early-inlining", 51 "-fno-move-loop-invariants", 52 "-fno-partial-inlining", 53 "-fno-tree-copy-prop", 54 "-fno-tree-loop-optimize", 55 56 // mips + mips64 57 "-msynci", 58 "-mno-synci", 59 "-mno-fused-madd", 60 61 // x86 + x86_64 62 "-finline-limit=300", 63 "-fno-inline-functions-called-once", 64 "-mfpmath=sse", 65 "-mbionic", 66 }) 67 68 var ClangLibToolingUnknownCflags = []string{ 69 "-flto", 70 "-fsanitize*", 71 } 72 73 func init() { 74 pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{ 75 "-D__compiler_offsetof=__builtin_offsetof", 76 77 // Help catch common 32/64-bit errors. 78 "-Werror=int-conversion", 79 80 // Disable overly aggressive warning for macros defined with a leading underscore 81 // This happens in AndroidConfig.h, which is included nearly everywhere. 82 // TODO: can we remove this now? 83 "-Wno-reserved-id-macro", 84 85 // Disable overly aggressive warning for format strings. 86 // Bug: 20148343 87 "-Wno-format-pedantic", 88 89 // Workaround for ccache with clang. 90 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. 91 "-Wno-unused-command-line-argument", 92 93 // Force clang to always output color diagnostics. Ninja will strip the ANSI 94 // color codes if it is not running in a terminal. 95 "-fcolor-diagnostics", 96 97 // http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374 98 "-Wno-expansion-to-defined", 99 100 // http://b/36463318 Clang executes with an absolute path, so clang-provided 101 // headers are now absolute. 102 "-fdebug-prefix-map=$$PWD/=", 103 }, " ")) 104 105 pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{ 106 // Disable -Winconsistent-missing-override until we can clean up the existing 107 // codebase for it. 108 "-Wno-inconsistent-missing-override", 109 110 // Bug: http://b/29823425 Disable -Wnull-dereference until the 111 // new instances detected by this warning are fixed. 112 "-Wno-null-dereference", 113 114 // Enable clang's thread-safety annotations in libcxx. 115 // Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything. 116 "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS", 117 "-Wno-thread-safety-negative", 118 }, " ")) 119 120 pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{ 121 "-nostdlibinc", 122 }, " ")) 123 124 pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{ 125 "-Werror=address-of-temporary", 126 // Bug: http://b/29823425 Disable -Wnull-dereference until the 127 // new cases detected by this warning in Clang r271374 are 128 // fixed. 129 //"-Werror=null-dereference", 130 "-Werror=return-type", 131 }, " ")) 132 } 133 134 func ClangFilterUnknownCflags(cflags []string) []string { 135 ret := make([]string, 0, len(cflags)) 136 for _, f := range cflags { 137 if !inListSorted(f, ClangUnknownCflags) { 138 ret = append(ret, f) 139 } 140 } 141 142 return ret 143 } 144 145 func inListSorted(s string, list []string) bool { 146 for _, l := range list { 147 if s == l { 148 return true 149 } else if s < l { 150 return false 151 } 152 } 153 return false 154 } 155 156 func sorted(list []string) []string { 157 sort.Strings(list) 158 return list 159 } 160