Home | History | Annotate | Download | only in cc
      1 package cc
      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 	"-Wmaybe-uninitialized",
     19 	"-Wno-error=clobbered",
     20 	"-Wno-error=maybe-uninitialized",
     21 	"-Wno-error=unused-but-set-parameter",
     22 	"-Wno-error=unused-but-set-variable",
     23 	"-Wno-free-nonheap-object",
     24 	"-Wno-literal-suffix",
     25 	"-Wno-maybe-uninitialized",
     26 	"-Wno-old-style-declaration",
     27 	"-Wno-psabi",
     28 	"-Wno-unused-but-set-parameter",
     29 	"-Wno-unused-but-set-variable",
     30 	"-Wno-unused-local-typedefs",
     31 	"-Wunused-but-set-parameter",
     32 	"-Wunused-but-set-variable",
     33 	"-fdiagnostics-color",
     34 
     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",
     43 
     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",
     56 	"-mno-synci",
     57 	"-mno-fused-madd",
     58 
     59 	// x86 + x86_64
     60 	"-finline-limit=300",
     61 	"-fno-inline-functions-called-once",
     62 	"-mfpmath=sse",
     63 	"-mbionic",
     64 })
     65 
     66 func init() {
     67 	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 
     73 		// Disable overly aggressive warning for macros defined with a leading underscore
     74 		// This happens in AndroidConfig.h, which is included nearly everywhere.
     75 		// TODO: can we remove this now?
     76 		"-Wno-reserved-id-macro",
     77 
     78 		// Disable overly aggressive warning for format strings.
     79 		// Bug: 20148343
     80 		"-Wno-format-pedantic",
     81 
     82 		// Workaround for ccache with clang.
     83 		// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
     84 		"-Wno-unused-command-line-argument",
     85 
     86 		// 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",
     89 	}, " "))
     90 
     91 	pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
     92 		"-std=gnu99",
     93 	}, " "))
     94 
     95 	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 
    101 	pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
    102 		"-nostdlibinc",
    103 	}, " "))
    104 
    105 	pctx.StaticVariable("clangExtraNoOverrideCflags", strings.Join([]string{
    106 		"-Werror=address-of-temporary",
    107 		"-Werror=null-dereference",
    108 		"-Werror=return-type",
    109 	}, " "))
    110 }
    111 
    112 func 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 
    123 func 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 }
    133 
    134 func sorted(list []string) []string {
    135 	sort.Strings(list)
    136 	return list
    137 }
    138