blob: 9cfe28f28075c75bf419c27b1e40ecfe185c1c47 [file] [log] [blame]
// Copyright 2017 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"sort"
"strings"
"android/soong/android"
)
// Cflags that should be filtered out when compiling with clang
var ClangUnknownCflags = sorted([]string{
"-finline-functions",
"-finline-limit=64",
"-fno-canonical-system-headers",
"-Wno-clobbered",
"-fno-devirtualize",
"-fno-tree-sra",
"-fprefetch-loop-arrays",
"-funswitch-loops",
"-Werror=unused-but-set-parameter",
"-Werror=unused-but-set-variable",
"-Wmaybe-uninitialized",
"-Wno-error=clobbered",
"-Wno-error=maybe-uninitialized",
"-Wno-error=unused-but-set-parameter",
"-Wno-error=unused-but-set-variable",
"-Wno-extended-offsetof",
"-Wno-free-nonheap-object",
"-Wno-literal-suffix",
"-Wno-maybe-uninitialized",
"-Wno-old-style-declaration",
"-Wno-unused-but-set-parameter",
"-Wno-unused-but-set-variable",
"-Wno-unused-local-typedefs",
"-Wunused-but-set-parameter",
"-Wunused-but-set-variable",
"-fdiagnostics-color",
// http://b/153759688
"-fuse-init-array",
// arm + arm64
"-fgcse-after-reload",
"-frerun-cse-after-loop",
"-frename-registers",
"-fno-strict-volatile-bitfields",
// arm + arm64
"-fno-align-jumps",
// arm
"-mthumb-interwork",
"-fno-builtin-sin",
"-fno-caller-saves",
"-fno-early-inlining",
"-fno-move-loop-invariants",
"-fno-partial-inlining",
"-fno-tree-copy-prop",
"-fno-tree-loop-optimize",
// x86 + x86_64
"-finline-limit=300",
"-fno-inline-functions-called-once",
"-mfpmath=sse",
"-mbionic",
// windows
"--enable-stdcall-fixup",
})
var ClangLibToolingUnknownCflags = sorted([]string{})
// List of tidy checks that should be disabled globally. When the compiler is
// updated, some checks enabled by this module may be disabled if they have
// become more strict, or if they are a new match for a wildcard group like
// `modernize-*`.
var ClangTidyDisableChecks = []string{
"misc-no-recursion",
"readability-function-cognitive-complexity", // http://b/175055536
}
func init() {
exportStringListStaticVariable("ClangExtraCflags", []string{
"-D__compiler_offsetof=__builtin_offsetof",
// Emit address-significance table which allows linker to perform safe ICF. Clang does
// not emit the table by default on Android since NDK still uses GNU binutils.
"-faddrsig",
// Turn on -fcommon explicitly, since Clang now defaults to -fno-common. The cleanup bug
// tracking this is http://b/151457797.
"-fcommon",
// Help catch common 32/64-bit errors.
"-Werror=int-conversion",
// Enable the new pass manager.
"-fexperimental-new-pass-manager",
// Disable overly aggressive warning for macros defined with a leading underscore
// This happens in AndroidConfig.h, which is included nearly everywhere.
// TODO: can we remove this now?
"-Wno-reserved-id-macro",
// Workaround for ccache with clang.
// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
"-Wno-unused-command-line-argument",
// Force clang to always output color diagnostics. Ninja will strip the ANSI
// color codes if it is not running in a terminal.
"-fcolor-diagnostics",
// Warnings from clang-7.0
"-Wno-sign-compare",
// Warnings from clang-8.0
"-Wno-defaulted-function-deleted",
// Disable -Winconsistent-missing-override until we can clean up the existing
// codebase for it.
"-Wno-inconsistent-missing-override",
// Warnings from clang-10
// Nested and array designated initialization is nice to have.
"-Wno-c99-designator",
// Warnings from clang-12
"-Wno-gnu-folding-constant",
// Calls to the APIs that are newer than the min sdk version of the caller should be
// guarded with __builtin_available.
"-Wunguarded-availability",
// This macro allows the bionic versioning.h to indirectly determine whether the
// option -Wunguarded-availability is on or not.
"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
})
}
func ClangFilterUnknownCflags(cflags []string) []string {
result, _ := android.FilterList(cflags, ClangUnknownCflags)
return result
}
func clangTidyNegateChecks(checks []string) []string {
ret := make([]string, 0, len(checks))
for _, c := range checks {
if strings.HasPrefix(c, "-") {
ret = append(ret, c)
} else {
ret = append(ret, "-"+c)
}
}
return ret
}
func ClangRewriteTidyChecks(checks []string) []string {
checks = append(checks, clangTidyNegateChecks(ClangTidyDisableChecks)...)
// clang-tidy does not allow later arguments to override earlier arguments,
// so if we just disabled an argument that was explicitly enabled we must
// remove the enabling argument from the list.
result, _ := android.FilterList(checks, ClangTidyDisableChecks)
return result
}
func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string {
return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags)
}
func sorted(list []string) []string {
sort.Strings(list)
return list
}