blob: f4c29f010dd52d1e99a89d0b0da81403c6639ae1 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001package cc
2
3import (
4 "sort"
5 "strings"
6)
7
8// Cflags that should be filtered out when compiling with clang
Dan Willemsene6540452015-10-20 15:21:33 -07009var clangUnknownCflags = sorted([]string{
Colin Cross3f40fa42015-01-30 17:27:36 -080010 "-finline-functions",
11 "-finline-limit=64",
12 "-fno-canonical-system-headers",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070013 "-Wno-clobbered",
14 "-fno-devirtualize",
Colin Cross3f40fa42015-01-30 17:27:36 -080015 "-fno-tree-sra",
Colin Crossa360e8b2015-03-16 16:22:28 -070016 "-fprefetch-loop-arrays",
Colin Cross3f40fa42015-01-30 17:27:36 -080017 "-funswitch-loops",
18 "-Wmaybe-uninitialized",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070019 "-Wno-error=clobbered",
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "-Wno-error=maybe-uninitialized",
Colin Cross74d1ec02015-04-28 13:30:13 -070021 "-Wno-error=unused-but-set-parameter",
22 "-Wno-error=unused-but-set-variable",
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "-Wno-free-nonheap-object",
24 "-Wno-literal-suffix",
25 "-Wno-maybe-uninitialized",
26 "-Wno-old-style-declaration",
27 "-Wno-psabi",
Colin Cross3f40fa42015-01-30 17:27:36 -080028 "-Wno-unused-but-set-parameter",
Colin Cross74d1ec02015-04-28 13:30:13 -070029 "-Wno-unused-but-set-variable",
Colin Cross3f40fa42015-01-30 17:27:36 -080030 "-Wno-unused-local-typedefs",
Colin Cross62ec5f42015-03-18 17:20:28 -070031 "-Wunused-but-set-parameter",
Colin Cross74d1ec02015-04-28 13:30:13 -070032 "-Wunused-but-set-variable",
Dan Willemsene6540452015-10-20 15:21:33 -070033 "-fdiagnostics-color",
Colin Cross3f40fa42015-01-30 17:27:36 -080034
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 Cross3f40fa42015-01-30 17:27:36 -080043
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 Willemsen3bf6b472015-09-11 17:41:10 -070056 "-mno-synci",
Colin Cross3f40fa42015-01-30 17:27:36 -080057 "-mno-fused-madd",
58
59 // x86 + x86_64
60 "-finline-limit=300",
61 "-fno-inline-functions-called-once",
62 "-mfpmath=sse",
63 "-mbionic",
Dan Willemsene6540452015-10-20 15:21:33 -070064})
Colin Cross3f40fa42015-01-30 17:27:36 -080065
66func init() {
Colin Cross3f40fa42015-01-30 17:27:36 -080067 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 Cross74d1ec02015-04-28 13:30:13 -070073 // Disable overly aggressive warning for macros defined with a leading underscore
74 // This happens in AndroidConfig.h, which is included nearly everywhere.
Dan Willemsen3bf6b472015-09-11 17:41:10 -070075 // TODO: can we remove this now?
Colin Cross74d1ec02015-04-28 13:30:13 -070076 "-Wno-reserved-id-macro",
77
78 // Disable overly aggressive warning for format strings.
79 // Bug: 20148343
80 "-Wno-format-pedantic",
81
Colin Cross3f40fa42015-01-30 17:27:36 -080082 // 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 Willemsene6540452015-10-20 15:21:33 -070086 // 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 Cross3f40fa42015-01-30 17:27:36 -080089 }, " "))
90
91 pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
92 "-std=gnu99",
93 }, " "))
94
Dan Willemsenac5e1cb2016-01-12 16:22:40 -080095 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 Cross3f40fa42015-01-30 17:27:36 -0800101 pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
102 "-nostdlibinc",
103 }, " "))
Dan Willemsenbe03f342016-03-03 17:21:04 -0800104
105 pctx.StaticVariable("clangExtraNoOverrideCflags", strings.Join([]string{
106 "-Werror=address-of-temporary",
107 "-Werror=null-dereference",
108 "-Werror=return-type",
109 }, " "))
Colin Cross3f40fa42015-01-30 17:27:36 -0800110}
111
112func 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
123func 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 Willemsene6540452015-10-20 15:21:33 -0700133
134func sorted(list []string) []string {
135 sort.Strings(list)
136 return list
137}