2017-11-17 19:55:38 +01: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-29 22:44:28 +02:00
|
|
|
package config
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
2021-07-15 02:56:21 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Cflags that should be filtered out when compiling with clang
|
2016-07-29 22:44:28 +02:00
|
|
|
var ClangUnknownCflags = sorted([]string{
|
2015-01-31 02:27:36 +01:00
|
|
|
"-finline-functions",
|
|
|
|
"-finline-limit=64",
|
|
|
|
"-fno-canonical-system-headers",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wno-clobbered",
|
|
|
|
"-fno-devirtualize",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-fno-tree-sra",
|
2015-03-17 00:22:28 +01:00
|
|
|
"-fprefetch-loop-arrays",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-funswitch-loops",
|
|
|
|
"-Wmaybe-uninitialized",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wno-error=clobbered",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-error=maybe-uninitialized",
|
2018-01-10 23:30:44 +01:00
|
|
|
"-Wno-extended-offsetof",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-free-nonheap-object",
|
|
|
|
"-Wno-literal-suffix",
|
|
|
|
"-Wno-maybe-uninitialized",
|
|
|
|
"-Wno-old-style-declaration",
|
|
|
|
"-Wno-unused-local-typedefs",
|
2015-10-21 00:21:33 +02:00
|
|
|
"-fdiagnostics-color",
|
2020-04-10 22:36:41 +02:00
|
|
|
// http://b/153759688
|
|
|
|
"-fuse-init-array",
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-03-07 01:55:28 +01:00
|
|
|
// arm + arm64
|
2015-01-31 02:27:36 +01: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-11-30 22:31:26 +01:00
|
|
|
|
|
|
|
// windows
|
|
|
|
"--enable-stdcall-fixup",
|
2015-10-21 00:21:33 +02:00
|
|
|
})
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-12-06 21:12:41 +01:00
|
|
|
var ClangLibToolingUnknownCflags = sorted([]string{})
|
2017-06-15 23:45:18 +02:00
|
|
|
|
2020-08-15 01:53:21 +02: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-15 20:11:57 +02:00
|
|
|
var ClangTidyDisableChecks = []string{
|
|
|
|
"misc-no-recursion",
|
2020-12-01 00:47:45 +01:00
|
|
|
"readability-function-cognitive-complexity", // http://b/175055536
|
2020-07-15 20:11:57 +02:00
|
|
|
}
|
2020-08-15 01:53:21 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func ClangFilterUnknownCflags(cflags []string) []string {
|
2020-08-15 01:53:21 +02: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 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-08-15 01:53:21 +02: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-03 20:33:34 +02:00
|
|
|
|
2020-11-19 09:30:49 +01:00
|
|
|
func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string {
|
|
|
|
return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags)
|
|
|
|
}
|
|
|
|
|
2015-10-21 00:21:33 +02:00
|
|
|
func sorted(list []string) []string {
|
|
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
|
|
}
|