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 15package config 16 17import ( 18 "sort" 19 "strings" 20 21 "android/soong/android" 22) 23 24// Cflags that should be filtered out when compiling with clang 25var ClangUnknownCflags = sorted([]string{ 26 "-finline-functions", 27 "-finline-limit=64", 28 "-fno-canonical-system-headers", 29 "-Wno-clobbered", 30 "-fno-devirtualize", 31 "-fno-tree-sra", 32 "-fprefetch-loop-arrays", 33 "-funswitch-loops", 34 "-Wmaybe-uninitialized", 35 "-Wno-error=clobbered", 36 "-Wno-error=maybe-uninitialized", 37 "-Wno-extended-offsetof", 38 "-Wno-free-nonheap-object", 39 "-Wno-literal-suffix", 40 "-Wno-maybe-uninitialized", 41 "-Wno-old-style-declaration", 42 "-Wno-unused-local-typedefs", 43 "-fdiagnostics-color", 44 // http://b/153759688 45 "-fuse-init-array", 46 47 // arm + arm64 48 "-fgcse-after-reload", 49 "-frerun-cse-after-loop", 50 "-frename-registers", 51 "-fno-strict-volatile-bitfields", 52 53 // arm + arm64 54 "-fno-align-jumps", 55 56 // arm 57 "-mthumb-interwork", 58 "-fno-builtin-sin", 59 "-fno-caller-saves", 60 "-fno-early-inlining", 61 "-fno-move-loop-invariants", 62 "-fno-partial-inlining", 63 "-fno-tree-copy-prop", 64 "-fno-tree-loop-optimize", 65 66 // x86 + x86_64 67 "-finline-limit=300", 68 "-fno-inline-functions-called-once", 69 "-mfpmath=sse", 70 "-mbionic", 71 72 // windows 73 "--enable-stdcall-fixup", 74}) 75 76var ClangLibToolingUnknownCflags = sorted([]string{}) 77 78// List of tidy checks that should be disabled globally. When the compiler is 79// updated, some checks enabled by this module may be disabled if they have 80// become more strict, or if they are a new match for a wildcard group like 81// `modernize-*`. 82var ClangTidyDisableChecks = []string{ 83 "misc-no-recursion", 84 "readability-function-cognitive-complexity", // http://b/175055536 85} 86 87func ClangFilterUnknownCflags(cflags []string) []string { 88 result, _ := android.FilterList(cflags, ClangUnknownCflags) 89 return result 90} 91 92func clangTidyNegateChecks(checks []string) []string { 93 ret := make([]string, 0, len(checks)) 94 for _, c := range checks { 95 if strings.HasPrefix(c, "-") { 96 ret = append(ret, c) 97 } else { 98 ret = append(ret, "-"+c) 99 } 100 } 101 return ret 102} 103 104func ClangRewriteTidyChecks(checks []string) []string { 105 checks = append(checks, clangTidyNegateChecks(ClangTidyDisableChecks)...) 106 // clang-tidy does not allow later arguments to override earlier arguments, 107 // so if we just disabled an argument that was explicitly enabled we must 108 // remove the enabling argument from the list. 109 result, _ := android.FilterList(checks, ClangTidyDisableChecks) 110 return result 111} 112 113func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string { 114 return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags) 115} 116 117func sorted(list []string) []string { 118 sort.Strings(list) 119 return list 120} 121