github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/config/clang.go (about)

     1  // Copyright 2017 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"sort"
    19  	"strings"
    20  )
    21  
    22  // Cflags that should be filtered out when compiling with clang
    23  var ClangUnknownCflags = sorted([]string{
    24  	"-finline-functions",
    25  	"-finline-limit=64",
    26  	"-fno-canonical-system-headers",
    27  	"-Wno-clobbered",
    28  	"-fno-devirtualize",
    29  	"-fno-tree-sra",
    30  	"-fprefetch-loop-arrays",
    31  	"-funswitch-loops",
    32  	"-Werror=unused-but-set-parameter",
    33  	"-Werror=unused-but-set-variable",
    34  	"-Wmaybe-uninitialized",
    35  	"-Wno-error=clobbered",
    36  	"-Wno-error=maybe-uninitialized",
    37  	"-Wno-error=unused-but-set-parameter",
    38  	"-Wno-error=unused-but-set-variable",
    39  	"-Wno-free-nonheap-object",
    40  	"-Wno-literal-suffix",
    41  	"-Wno-maybe-uninitialized",
    42  	"-Wno-old-style-declaration",
    43  	"-Wno-psabi",
    44  	"-Wno-unused-but-set-parameter",
    45  	"-Wno-unused-but-set-variable",
    46  	"-Wno-unused-local-typedefs",
    47  	"-Wunused-but-set-parameter",
    48  	"-Wunused-but-set-variable",
    49  	"-fdiagnostics-color",
    50  
    51  	// arm + arm64 + mips + mips64
    52  	"-fgcse-after-reload",
    53  	"-frerun-cse-after-loop",
    54  	"-frename-registers",
    55  	"-fno-strict-volatile-bitfields",
    56  
    57  	// arm + arm64
    58  	"-fno-align-jumps",
    59  
    60  	// arm
    61  	"-mthumb-interwork",
    62  	"-fno-builtin-sin",
    63  	"-fno-caller-saves",
    64  	"-fno-early-inlining",
    65  	"-fno-move-loop-invariants",
    66  	"-fno-partial-inlining",
    67  	"-fno-tree-copy-prop",
    68  	"-fno-tree-loop-optimize",
    69  
    70  	// mips + mips64
    71  	"-msynci",
    72  	"-mno-synci",
    73  	"-mno-fused-madd",
    74  
    75  	// x86 + x86_64
    76  	"-finline-limit=300",
    77  	"-fno-inline-functions-called-once",
    78  	"-mfpmath=sse",
    79  	"-mbionic",
    80  
    81  	// windows
    82  	"--enable-stdcall-fixup",
    83  })
    84  
    85  var ClangLibToolingUnknownCflags = []string{
    86  	"-flto*",
    87  	"-fsanitize*",
    88  }
    89  
    90  func init() {
    91  	pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
    92  		"-D__compiler_offsetof=__builtin_offsetof",
    93  
    94  		// Help catch common 32/64-bit errors.
    95  		"-Werror=int-conversion",
    96  
    97  		// Disable overly aggressive warning for macros defined with a leading underscore
    98  		// This happens in AndroidConfig.h, which is included nearly everywhere.
    99  		// TODO: can we remove this now?
   100  		"-Wno-reserved-id-macro",
   101  
   102  		// Disable overly aggressive warning for format strings.
   103  		// Bug: 20148343
   104  		"-Wno-format-pedantic",
   105  
   106  		// Workaround for ccache with clang.
   107  		// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
   108  		"-Wno-unused-command-line-argument",
   109  
   110  		// Force clang to always output color diagnostics. Ninja will strip the ANSI
   111  		// color codes if it is not running in a terminal.
   112  		"-fcolor-diagnostics",
   113  
   114  		// http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
   115  		"-Wno-expansion-to-defined",
   116  
   117  		// http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
   118  		"-Wno-zero-as-null-pointer-constant",
   119  
   120  		// http://b/36463318 Clang executes with an absolute path, so clang-provided
   121  		// headers are now absolute.
   122  		"-fdebug-prefix-map=$$PWD/=",
   123  	}, " "))
   124  
   125  	pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
   126  		// Disable -Winconsistent-missing-override until we can clean up the existing
   127  		// codebase for it.
   128  		"-Wno-inconsistent-missing-override",
   129  
   130  		// Bug: http://b/29823425 Disable -Wnull-dereference until the
   131  		// new instances detected by this warning are fixed.
   132  		"-Wno-null-dereference",
   133  
   134  		// Enable clang's thread-safety annotations in libcxx.
   135  		// Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything.
   136  		"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
   137  		"-Wno-thread-safety-negative",
   138  
   139  		// libc++'s math.h has an #include_next outside of system_headers.
   140  		"-Wno-gnu-include-next",
   141  	}, " "))
   142  
   143  	pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
   144  		"-nostdlibinc",
   145  	}, " "))
   146  
   147  	pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
   148  		"-Werror=address-of-temporary",
   149  		// Bug: http://b/29823425 Disable -Wnull-dereference until the
   150  		// new cases detected by this warning in Clang r271374 are
   151  		// fixed.
   152  		//"-Werror=null-dereference",
   153  		"-Werror=return-type",
   154  
   155  		// http://b/72331526 Disable -Wtautological-* until the instances detected by these
   156  		// new warnings are fixed.
   157  		"-Wno-tautological-constant-compare",
   158  
   159  		// http://b/72331524 Allow null pointer arithmetic until the instances detected by
   160  		// this new warning are fixed.
   161  		"-Wno-null-pointer-arithmetic",
   162  
   163  		// http://b/72330874 Disable -Wenum-compare until the instances detected by this new
   164  		// warning are fixed.
   165  		"-Wno-enum-compare",
   166  		"-Wno-enum-compare-switch",
   167  	}, " "))
   168  }
   169  
   170  func ClangFilterUnknownCflags(cflags []string) []string {
   171  	ret := make([]string, 0, len(cflags))
   172  	for _, f := range cflags {
   173  		if !inListSorted(f, ClangUnknownCflags) {
   174  			ret = append(ret, f)
   175  		}
   176  	}
   177  
   178  	return ret
   179  }
   180  
   181  func inListSorted(s string, list []string) bool {
   182  	for _, l := range list {
   183  		if s == l {
   184  			return true
   185  		} else if s < l {
   186  			return false
   187  		}
   188  	}
   189  	return false
   190  }
   191  
   192  func sorted(list []string) []string {
   193  	sort.Strings(list)
   194  	return list
   195  }