Home | History | Annotate | Download | only in config
      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 func init() {
     69 	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 
     75 		// Disable overly aggressive warning for macros defined with a leading underscore
     76 		// This happens in AndroidConfig.h, which is included nearly everywhere.
     77 		// TODO: can we remove this now?
     78 		"-Wno-reserved-id-macro",
     79 
     80 		// Disable overly aggressive warning for format strings.
     81 		// Bug: 20148343
     82 		"-Wno-format-pedantic",
     83 
     84 		// 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 		// Force clang to always output color diagnostics. Ninja will strip the ANSI
     89 		// color codes if it is not running in a terminal.
     90 		"-fcolor-diagnostics",
     91 
     92 		// http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
     93 		"-Wno-expansion-to-defined",
     94 
     95 		// http://b/36463318 Clang executes with an absolute path, so clang-provided
     96 		// headers are now absolute.
     97 		"-fdebug-prefix-map=$$PWD/=",
     98 	}, " "))
     99 
    100 	pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
    101 		// Disable -Winconsistent-missing-override until we can clean up the existing
    102 		// codebase for it.
    103 		"-Wno-inconsistent-missing-override",
    104 
    105 		// Bug: http://b/29823425 Disable -Wnull-dereference until the
    106 		// new instances detected by this warning are fixed.
    107 		"-Wno-null-dereference",
    108 	}, " "))
    109 
    110 	pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
    111 		"-nostdlibinc",
    112 	}, " "))
    113 
    114 	pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
    115 		"-Werror=address-of-temporary",
    116 		// Bug: http://b/29823425 Disable -Wnull-dereference until the
    117 		// new cases detected by this warning in Clang r271374 are
    118 		// fixed.
    119 		//"-Werror=null-dereference",
    120 		"-Werror=return-type",
    121 	}, " "))
    122 }
    123 
    124 func ClangFilterUnknownCflags(cflags []string) []string {
    125 	ret := make([]string, 0, len(cflags))
    126 	for _, f := range cflags {
    127 		if !inListSorted(f, ClangUnknownCflags) {
    128 			ret = append(ret, f)
    129 		}
    130 	}
    131 
    132 	return ret
    133 }
    134 
    135 func inListSorted(s string, list []string) bool {
    136 	for _, l := range list {
    137 		if s == l {
    138 			return true
    139 		} else if s < l {
    140 			return false
    141 		}
    142 	}
    143 	return false
    144 }
    145 
    146 func sorted(list []string) []string {
    147 	sort.Strings(list)
    148 	return list
    149 }
    150