blob: c348eeac4ce9e6d21e25bc725a4ab64964a9c86a [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
9var clangUnknownCflags = []string{
10 "-finline-functions",
11 "-finline-limit=64",
12 "-fno-canonical-system-headers",
13 "-fno-tree-sra",
14 "-funswitch-loops",
15 "-Wmaybe-uninitialized",
16 "-Wno-error=maybe-uninitialized",
17 "-Wno-free-nonheap-object",
18 "-Wno-literal-suffix",
19 "-Wno-maybe-uninitialized",
20 "-Wno-old-style-declaration",
21 "-Wno-psabi",
22 "-Wno-unused-but-set-variable",
23 "-Wno-unused-but-set-parameter",
24 "-Wno-unused-local-typedefs",
25
26 // arm + arm64 + mips + mips64
27 "-fgcse-after-reload",
28 "-frerun-cse-after-loop",
29 "-frename-registers",
30 "-fno-strict-volatile-bitfields",
31
32 // arm + arm64
33 "-fno-align-jumps",
34 "-Wa,--noexecstack",
35
36 // arm
37 "-mthumb-interwork",
38 "-fno-builtin-sin",
39 "-fno-caller-saves",
40 "-fno-early-inlining",
41 "-fno-move-loop-invariants",
42 "-fno-partial-inlining",
43 "-fno-tree-copy-prop",
44 "-fno-tree-loop-optimize",
45
46 // mips + mips64
47 "-msynci",
48 "-mno-fused-madd",
49
50 // x86 + x86_64
51 "-finline-limit=300",
52 "-fno-inline-functions-called-once",
53 "-mfpmath=sse",
54 "-mbionic",
55}
56
57func init() {
58 sort.Strings(clangUnknownCflags)
59
60 pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
61 "-D__compiler_offsetof=__builtin_offsetof",
62
63 // Help catch common 32/64-bit errors.
64 "-Werror=int-conversion",
65
66 // Workaround for ccache with clang.
67 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
68 "-Wno-unused-command-line-argument",
69
70 // Disable -Winconsistent-missing-override until we can clean up the existing
71 // codebase for it.
72 "-Wno-inconsistent-missing-override",
73 }, " "))
74
75 pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
76 "-std=gnu99",
77 }, " "))
78
79 pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
80 "-nostdlibinc",
81 }, " "))
82}
83
84func clangFilterUnknownCflags(cflags []string) []string {
85 ret := make([]string, 0, len(cflags))
86 for _, f := range cflags {
87 if !inListSorted(f, clangUnknownCflags) {
88 ret = append(ret, f)
89 }
90 }
91
92 return ret
93}
94
95func inListSorted(s string, list []string) bool {
96 for _, l := range list {
97 if s == l {
98 return true
99 } else if s < l {
100 return false
101 }
102 }
103 return false
104}