blob: 67622474edfd1b610e99bd944e7094669b7180aa [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",
34 "-fdebug-prefix-map=/proc/self/cwd=",
Colin Cross3f40fa42015-01-30 17:27:36 -080035
36 // arm + arm64 + mips + mips64
37 "-fgcse-after-reload",
38 "-frerun-cse-after-loop",
39 "-frename-registers",
40 "-fno-strict-volatile-bitfields",
41
42 // arm + arm64
43 "-fno-align-jumps",
44 "-Wa,--noexecstack",
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",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070058 "-mno-synci",
Colin Cross3f40fa42015-01-30 17:27:36 -080059 "-mno-fused-madd",
60
61 // x86 + x86_64
62 "-finline-limit=300",
63 "-fno-inline-functions-called-once",
64 "-mfpmath=sse",
65 "-mbionic",
Dan Willemsene6540452015-10-20 15:21:33 -070066})
Colin Cross3f40fa42015-01-30 17:27:36 -080067
68func init() {
Colin Cross3f40fa42015-01-30 17:27:36 -080069 pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
70 "-D__compiler_offsetof=__builtin_offsetof",
71
72 // Help catch common 32/64-bit errors.
73 "-Werror=int-conversion",
74
Colin Cross74d1ec02015-04-28 13:30:13 -070075 // Disable overly aggressive warning for macros defined with a leading underscore
76 // This happens in AndroidConfig.h, which is included nearly everywhere.
Dan Willemsen3bf6b472015-09-11 17:41:10 -070077 // TODO: can we remove this now?
Colin Cross74d1ec02015-04-28 13:30:13 -070078 "-Wno-reserved-id-macro",
79
80 // Disable overly aggressive warning for format strings.
81 // Bug: 20148343
82 "-Wno-format-pedantic",
83
Colin Cross3f40fa42015-01-30 17:27:36 -080084 // Workaround for ccache with clang.
85 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
86 "-Wno-unused-command-line-argument",
87
88 // Disable -Winconsistent-missing-override until we can clean up the existing
89 // codebase for it.
90 "-Wno-inconsistent-missing-override",
Dan Willemsene6540452015-10-20 15:21:33 -070091
92 // Force clang to always output color diagnostics. Ninja will strip the ANSI
93 // color codes if it is not running in a terminal.
94 "-fcolor-diagnostics",
Colin Cross3f40fa42015-01-30 17:27:36 -080095 }, " "))
96
97 pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
98 "-std=gnu99",
99 }, " "))
100
101 pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
102 "-nostdlibinc",
103 }, " "))
104}
105
106func clangFilterUnknownCflags(cflags []string) []string {
107 ret := make([]string, 0, len(cflags))
108 for _, f := range cflags {
109 if !inListSorted(f, clangUnknownCflags) {
110 ret = append(ret, f)
111 }
112 }
113
114 return ret
115}
116
117func inListSorted(s string, list []string) bool {
118 for _, l := range list {
119 if s == l {
120 return true
121 } else if s < l {
122 return false
123 }
124 }
125 return false
126}
Dan Willemsene6540452015-10-20 15:21:33 -0700127
128func sorted(list []string) []string {
129 sort.Strings(list)
130 return list
131}