2017-11-18 02:55:38 +08:00
|
|
|
// 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.
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
package config
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
import (
|
2020-08-15 07:53:21 +08:00
|
|
|
"android/soong/android"
|
2015-01-31 09:27:36 +08:00
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cflags that should be filtered out when compiling with clang
|
2016-07-30 04:44:28 +08:00
|
|
|
var ClangUnknownCflags = sorted([]string{
|
2015-01-31 09:27:36 +08:00
|
|
|
"-finline-functions",
|
|
|
|
"-finline-limit=64",
|
|
|
|
"-fno-canonical-system-headers",
|
2015-09-12 08:41:10 +08:00
|
|
|
"-Wno-clobbered",
|
|
|
|
"-fno-devirtualize",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-fno-tree-sra",
|
2015-03-17 07:22:28 +08:00
|
|
|
"-fprefetch-loop-arrays",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-funswitch-loops",
|
2016-05-20 07:57:11 +08:00
|
|
|
"-Werror=unused-but-set-parameter",
|
|
|
|
"-Werror=unused-but-set-variable",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-Wmaybe-uninitialized",
|
2015-09-12 08:41:10 +08:00
|
|
|
"-Wno-error=clobbered",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-Wno-error=maybe-uninitialized",
|
2015-04-29 04:30:13 +08:00
|
|
|
"-Wno-error=unused-but-set-parameter",
|
|
|
|
"-Wno-error=unused-but-set-variable",
|
2018-01-11 06:30:44 +08:00
|
|
|
"-Wno-extended-offsetof",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-Wno-free-nonheap-object",
|
|
|
|
"-Wno-literal-suffix",
|
|
|
|
"-Wno-maybe-uninitialized",
|
|
|
|
"-Wno-old-style-declaration",
|
|
|
|
"-Wno-unused-but-set-parameter",
|
2015-04-29 04:30:13 +08:00
|
|
|
"-Wno-unused-but-set-variable",
|
2015-01-31 09:27:36 +08:00
|
|
|
"-Wno-unused-local-typedefs",
|
2015-03-19 08:20:28 +08:00
|
|
|
"-Wunused-but-set-parameter",
|
2015-04-29 04:30:13 +08:00
|
|
|
"-Wunused-but-set-variable",
|
2015-10-21 06:21:33 +08:00
|
|
|
"-fdiagnostics-color",
|
2020-04-11 04:36:41 +08:00
|
|
|
// http://b/153759688
|
|
|
|
"-fuse-init-array",
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2020-03-07 08:55:28 +08:00
|
|
|
// arm + arm64
|
2015-01-31 09:27:36 +08:00
|
|
|
"-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",
|
2017-12-01 05:31:26 +08:00
|
|
|
|
|
|
|
// windows
|
|
|
|
"--enable-stdcall-fixup",
|
2015-10-21 06:21:33 +08:00
|
|
|
})
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2018-04-04 02:33:34 +08:00
|
|
|
// Ldflags that should be filtered out when linking with clang lld
|
|
|
|
var ClangUnknownLldflags = sorted([]string{
|
|
|
|
"-Wl,--fix-cortex-a8",
|
|
|
|
"-Wl,--no-fix-cortex-a8",
|
|
|
|
})
|
|
|
|
|
2018-12-07 04:12:41 +08:00
|
|
|
var ClangLibToolingUnknownCflags = sorted([]string{})
|
2017-06-16 05:45:18 +08:00
|
|
|
|
2020-08-15 07:53:21 +08:00
|
|
|
// 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-*`.
|
2020-07-16 02:11:57 +08:00
|
|
|
var ClangTidyDisableChecks = []string{
|
|
|
|
"misc-no-recursion",
|
2020-12-01 07:47:45 +08:00
|
|
|
"readability-function-cognitive-complexity", // http://b/175055536
|
2020-07-16 02:11:57 +08:00
|
|
|
}
|
2020-08-15 07:53:21 +08:00
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
func init() {
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
|
2015-01-31 09:27:36 +08:00
|
|
|
"-D__compiler_offsetof=__builtin_offsetof",
|
|
|
|
|
2019-03-20 11:05:05 +08:00
|
|
|
// 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",
|
|
|
|
|
2020-07-16 02:11:57 +08:00
|
|
|
// Turn on -fcommon explicitly, since Clang now defaults to -fno-common. The cleanup bug
|
|
|
|
// tracking this is http://b/151457797.
|
|
|
|
"-fcommon",
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Help catch common 32/64-bit errors.
|
|
|
|
"-Werror=int-conversion",
|
|
|
|
|
2019-04-23 13:33:23 +08:00
|
|
|
// Enable the new pass manager.
|
|
|
|
"-fexperimental-new-pass-manager",
|
|
|
|
|
2015-04-29 04:30:13 +08:00
|
|
|
// Disable overly aggressive warning for macros defined with a leading underscore
|
|
|
|
// This happens in AndroidConfig.h, which is included nearly everywhere.
|
2015-09-12 08:41:10 +08:00
|
|
|
// TODO: can we remove this now?
|
2015-04-29 04:30:13 +08:00
|
|
|
"-Wno-reserved-id-macro",
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Workaround for ccache with clang.
|
|
|
|
// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
|
|
|
|
"-Wno-unused-command-line-argument",
|
|
|
|
|
2015-10-21 06:21:33 +08:00
|
|
|
// Force clang to always output color diagnostics. Ninja will strip the ANSI
|
|
|
|
// color codes if it is not running in a terminal.
|
|
|
|
"-fcolor-diagnostics",
|
2016-06-29 01:56:03 +08:00
|
|
|
|
2018-01-11 06:30:44 +08:00
|
|
|
// Warnings from clang-7.0
|
|
|
|
"-Wno-sign-compare",
|
2018-10-31 06:31:38 +08:00
|
|
|
|
|
|
|
// Warnings from clang-8.0
|
|
|
|
"-Wno-defaulted-function-deleted",
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-13 08:22:40 +08:00
|
|
|
// Disable -Winconsistent-missing-override until we can clean up the existing
|
|
|
|
// codebase for it.
|
|
|
|
"-Wno-inconsistent-missing-override",
|
2019-12-13 02:15:42 +08:00
|
|
|
|
|
|
|
// Warnings from clang-10
|
|
|
|
// Nested and array designated initialization is nice to have.
|
|
|
|
"-Wno-c99-designator",
|
2020-08-11 08:35:08 +08:00
|
|
|
|
2021-02-04 09:52:16 +08:00
|
|
|
// Warnings from clang-12
|
|
|
|
"-Wno-gnu-folding-constant",
|
|
|
|
|
2020-08-11 08:35:08 +08:00
|
|
|
// 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.
|
2021-02-12 05:20:42 +08:00
|
|
|
"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
|
2019-03-28 09:26:22 +08:00
|
|
|
}, " "))
|
2016-06-29 01:56:03 +08:00
|
|
|
|
2019-03-28 09:26:22 +08:00
|
|
|
pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
|
2019-10-31 04:55:26 +08:00
|
|
|
// -Wimplicit-fallthrough is not enabled by -Wall.
|
|
|
|
"-Wimplicit-fallthrough",
|
|
|
|
|
2017-04-27 11:26:14 +08:00
|
|
|
// Enable clang's thread-safety annotations in libcxx.
|
|
|
|
"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
|
2018-02-08 09:24:42 +08:00
|
|
|
|
|
|
|
// libc++'s math.h has an #include_next outside of system_headers.
|
|
|
|
"-Wno-gnu-include-next",
|
2016-01-13 08:22:40 +08:00
|
|
|
}, " "))
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
|
2015-01-31 09:27:36 +08:00
|
|
|
"-nostdlibinc",
|
|
|
|
}, " "))
|
2016-03-04 09:21:04 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
|
2016-03-04 09:21:04 +08:00
|
|
|
"-Werror=address-of-temporary",
|
2016-06-29 01:56:03 +08:00
|
|
|
// Bug: http://b/29823425 Disable -Wnull-dereference until the
|
|
|
|
// new cases detected by this warning in Clang r271374 are
|
|
|
|
// fixed.
|
|
|
|
//"-Werror=null-dereference",
|
2016-03-04 09:21:04 +08:00
|
|
|
"-Werror=return-type",
|
2017-12-07 11:56:34 +08:00
|
|
|
|
|
|
|
// http://b/72331526 Disable -Wtautological-* until the instances detected by these
|
|
|
|
// new warnings are fixed.
|
2018-02-07 06:49:42 +08:00
|
|
|
"-Wno-tautological-constant-compare",
|
2018-01-11 06:30:44 +08:00
|
|
|
"-Wno-tautological-type-limit-compare",
|
2019-12-13 02:15:42 +08:00
|
|
|
// http://b/145210666
|
|
|
|
"-Wno-reorder-init-list",
|
|
|
|
// http://b/145211066
|
|
|
|
"-Wno-implicit-int-float-conversion",
|
2020-02-11 11:01:14 +08:00
|
|
|
// New warnings to be fixed after clang-r377782.
|
2020-02-15 02:10:22 +08:00
|
|
|
"-Wno-int-in-bool-context", // http://b/148287349
|
|
|
|
"-Wno-sizeof-array-div", // http://b/148815709
|
|
|
|
"-Wno-tautological-overlap-compare", // http://b/148815696
|
2020-04-11 04:36:41 +08:00
|
|
|
// New warnings to be fixed after clang-r383902.
|
|
|
|
"-Wno-deprecated-copy", // http://b/153746672
|
|
|
|
"-Wno-range-loop-construct", // http://b/153747076
|
|
|
|
"-Wno-misleading-indentation", // http://b/153746954
|
|
|
|
"-Wno-zero-as-null-pointer-constant", // http://b/68236239
|
|
|
|
"-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485
|
|
|
|
"-Wno-deprecated-enum-enum-conversion", // http://b/153746563
|
|
|
|
"-Wno-string-compare", // http://b/153764102
|
|
|
|
"-Wno-enum-enum-conversion", // http://b/154138986
|
|
|
|
"-Wno-enum-float-conversion", // http://b/154255917
|
|
|
|
"-Wno-pessimizing-move", // http://b/154270751
|
2020-07-16 02:11:57 +08:00
|
|
|
// New warnings to be fixed after clang-r399163
|
|
|
|
"-Wno-non-c-typedef-for-linkage", // http://b/161304145
|
2020-12-01 07:47:45 +08:00
|
|
|
// New warnings to be fixed after clang-r407598
|
|
|
|
"-Wno-string-concatenation", // http://b/175068488
|
2016-03-04 09:21:04 +08:00
|
|
|
}, " "))
|
2018-06-07 05:42:44 +08:00
|
|
|
|
2019-10-08 17:27:17 +08:00
|
|
|
// Extra cflags for external third-party projects to disable warnings that
|
|
|
|
// are infeasible to fix in all the external projects and their upstream repos.
|
2018-06-07 05:42:44 +08:00
|
|
|
pctx.StaticVariable("ClangExtraExternalCflags", strings.Join([]string{
|
2018-06-30 04:20:38 +08:00
|
|
|
"-Wno-enum-compare",
|
|
|
|
"-Wno-enum-compare-switch",
|
2018-12-13 19:55:29 +08:00
|
|
|
|
|
|
|
// http://b/72331524 Allow null pointer arithmetic until the instances detected by
|
|
|
|
// this new warning are fixed.
|
|
|
|
"-Wno-null-pointer-arithmetic",
|
2018-12-18 09:18:37 +08:00
|
|
|
|
|
|
|
// Bug: http://b/29823425 Disable -Wnull-dereference until the
|
|
|
|
// new instances detected by this warning are fixed.
|
|
|
|
"-Wno-null-dereference",
|
2019-12-13 02:15:42 +08:00
|
|
|
|
|
|
|
// http://b/145211477
|
|
|
|
"-Wno-pointer-compare",
|
|
|
|
// http://b/145211022
|
|
|
|
"-Wno-xor-used-as-pow",
|
|
|
|
// http://b/145211022
|
|
|
|
"-Wno-final-dtor-non-final-class",
|
2020-07-16 02:11:57 +08:00
|
|
|
|
|
|
|
// http://b/165945989
|
|
|
|
"-Wno-psabi",
|
2018-06-07 05:42:44 +08:00
|
|
|
}, " "))
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
func ClangFilterUnknownCflags(cflags []string) []string {
|
2020-08-15 07:53:21 +08:00
|
|
|
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)
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-08-15 07:53:21 +08:00
|
|
|
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
|
|
|
|
}
|
2018-04-04 02:33:34 +08:00
|
|
|
|
2020-08-15 07:53:21 +08:00
|
|
|
func ClangFilterUnknownLldflags(lldflags []string) []string {
|
|
|
|
result, _ := android.FilterList(lldflags, ClangUnknownLldflags)
|
|
|
|
return result
|
2018-04-04 02:33:34 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 16:30:49 +08:00
|
|
|
func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string {
|
|
|
|
return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags)
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
func inListSorted(s string, list []string) bool {
|
|
|
|
for _, l := range list {
|
|
|
|
if s == l {
|
|
|
|
return true
|
|
|
|
} else if s < l {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-10-21 06:21:33 +08:00
|
|
|
|
|
|
|
func sorted(list []string) []string {
|
|
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
|
|
}
|