blob: 6a01010d29ab091cc72b47600e0fc2bfda7ab627 [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",
Colin Cross3f40fa42015-01-30 17:27:36 -080044
45 // arm
46 "-mthumb-interwork",
47 "-fno-builtin-sin",
48 "-fno-caller-saves",
49 "-fno-early-inlining",
50 "-fno-move-loop-invariants",
51 "-fno-partial-inlining",
52 "-fno-tree-copy-prop",
53 "-fno-tree-loop-optimize",
54
55 // mips + mips64
56 "-msynci",
Dan Willemsen3bf6b472015-09-11 17:41:10 -070057 "-mno-synci",
Colin Cross3f40fa42015-01-30 17:27:36 -080058 "-mno-fused-madd",
59
60 // x86 + x86_64
61 "-finline-limit=300",
62 "-fno-inline-functions-called-once",
63 "-mfpmath=sse",
64 "-mbionic",
Dan Willemsene6540452015-10-20 15:21:33 -070065})
Colin Cross3f40fa42015-01-30 17:27:36 -080066
67func init() {
Colin Cross3f40fa42015-01-30 17:27:36 -080068 pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
69 "-D__compiler_offsetof=__builtin_offsetof",
70
71 // Help catch common 32/64-bit errors.
72 "-Werror=int-conversion",
73
Colin Cross74d1ec02015-04-28 13:30:13 -070074 // Disable overly aggressive warning for macros defined with a leading underscore
75 // This happens in AndroidConfig.h, which is included nearly everywhere.
Dan Willemsen3bf6b472015-09-11 17:41:10 -070076 // TODO: can we remove this now?
Colin Cross74d1ec02015-04-28 13:30:13 -070077 "-Wno-reserved-id-macro",
78
79 // Disable overly aggressive warning for format strings.
80 // Bug: 20148343
81 "-Wno-format-pedantic",
82
Colin Cross3f40fa42015-01-30 17:27:36 -080083 // Workaround for ccache with clang.
84 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
85 "-Wno-unused-command-line-argument",
86
87 // Disable -Winconsistent-missing-override until we can clean up the existing
88 // codebase for it.
89 "-Wno-inconsistent-missing-override",
Dan Willemsene6540452015-10-20 15:21:33 -070090
91 // Force clang to always output color diagnostics. Ninja will strip the ANSI
92 // color codes if it is not running in a terminal.
93 "-fcolor-diagnostics",
Colin Cross3f40fa42015-01-30 17:27:36 -080094 }, " "))
95
96 pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
97 "-std=gnu99",
98 }, " "))
99
100 pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
101 "-nostdlibinc",
102 }, " "))
103}
104
105func clangFilterUnknownCflags(cflags []string) []string {
106 ret := make([]string, 0, len(cflags))
107 for _, f := range cflags {
108 if !inListSorted(f, clangUnknownCflags) {
109 ret = append(ret, f)
110 }
111 }
112
113 return ret
114}
115
116func inListSorted(s string, list []string) bool {
117 for _, l := range list {
118 if s == l {
119 return true
120 } else if s < l {
121 return false
122 }
123 }
124 return false
125}
Dan Willemsene6540452015-10-20 15:21:33 -0700126
127func sorted(list []string) []string {
128 sort.Strings(list)
129 return list
130}