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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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",
|
2016-05-20 01:57:11 +02:00
|
|
|
"-Werror=unused-but-set-parameter",
|
|
|
|
"-Werror=unused-but-set-variable",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-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",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-error=unused-but-set-parameter",
|
|
|
|
"-Wno-error=unused-but-set-variable",
|
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-psabi",
|
|
|
|
"-Wno-unused-but-set-parameter",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-unused-but-set-variable",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-unused-local-typedefs",
|
2015-03-19 01:20:28 +01:00
|
|
|
"-Wunused-but-set-parameter",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wunused-but-set-variable",
|
2015-10-21 00:21:33 +02:00
|
|
|
"-fdiagnostics-color",
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// arm + arm64 + mips + mips64
|
|
|
|
"-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",
|
|
|
|
|
|
|
|
// mips + mips64
|
|
|
|
"-msynci",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-mno-synci",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-mno-fused-madd",
|
|
|
|
|
|
|
|
// 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-04-03 20:33:34 +02:00
|
|
|
// Ldflags that should be filtered out when linking with clang lld
|
|
|
|
var ClangUnknownLldflags = sorted([]string{
|
|
|
|
"-fuse-ld=gold",
|
|
|
|
"-Wl,--fix-cortex-a8",
|
|
|
|
"-Wl,--no-fix-cortex-a8",
|
|
|
|
"-Wl,-m,aarch64_elf64_le_vec",
|
|
|
|
})
|
|
|
|
|
2018-10-16 11:39:50 +02:00
|
|
|
var ClangLibToolingUnknownCflags []string = nil
|
2017-06-15 23:45:18 +02:00
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func init() {
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
|
2015-01-31 02:27:36 +01:00
|
|
|
"-D__compiler_offsetof=__builtin_offsetof",
|
|
|
|
|
2018-08-14 22:20:38 +02:00
|
|
|
// Make implicit fallthrough an error in the future.
|
|
|
|
"-Wimplicit-fallthrough",
|
|
|
|
"-Wno-error=implicit-fallthrough",
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Help catch common 32/64-bit errors.
|
|
|
|
"-Werror=int-conversion",
|
|
|
|
|
2015-04-28 22:30:13 +02: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 02:41:10 +02:00
|
|
|
// TODO: can we remove this now?
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-reserved-id-macro",
|
|
|
|
|
|
|
|
// Disable overly aggressive warning for format strings.
|
|
|
|
// Bug: 20148343
|
|
|
|
"-Wno-format-pedantic",
|
|
|
|
|
2015-01-31 02:27:36 +01: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 00:21:33 +02: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-28 19:56:03 +02:00
|
|
|
|
|
|
|
// http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
|
|
|
|
"-Wno-expansion-to-defined",
|
2017-03-28 01:53:38 +02:00
|
|
|
|
2017-10-05 01:12:37 +02:00
|
|
|
// http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
|
|
|
|
"-Wno-zero-as-null-pointer-constant",
|
2018-01-10 23:30:44 +01:00
|
|
|
|
|
|
|
// Warnings from clang-7.0
|
|
|
|
"-Wno-deprecated-register",
|
|
|
|
"-Wno-sign-compare",
|
2015-01-31 02:27:36 +01:00
|
|
|
}, " "))
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
|
2016-01-13 01:22:40 +01:00
|
|
|
// Disable -Winconsistent-missing-override until we can clean up the existing
|
|
|
|
// codebase for it.
|
|
|
|
"-Wno-inconsistent-missing-override",
|
2016-06-28 19:56:03 +02:00
|
|
|
|
|
|
|
// Bug: http://b/29823425 Disable -Wnull-dereference until the
|
|
|
|
// new instances detected by this warning are fixed.
|
|
|
|
"-Wno-null-dereference",
|
2017-04-27 05:26:14 +02:00
|
|
|
|
|
|
|
// Enable clang's thread-safety annotations in libcxx.
|
|
|
|
// Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything.
|
|
|
|
"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
|
|
|
|
"-Wno-thread-safety-negative",
|
2018-02-08 02:24:42 +01:00
|
|
|
|
|
|
|
// libc++'s math.h has an #include_next outside of system_headers.
|
|
|
|
"-Wno-gnu-include-next",
|
2016-01-13 01:22:40 +01:00
|
|
|
}, " "))
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
|
2015-01-31 02:27:36 +01:00
|
|
|
"-nostdlibinc",
|
|
|
|
}, " "))
|
2016-03-04 02:21:04 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
|
2016-03-04 02:21:04 +01:00
|
|
|
"-Werror=address-of-temporary",
|
2016-06-28 19:56:03 +02: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 02:21:04 +01:00
|
|
|
"-Werror=return-type",
|
2017-12-07 04:56:34 +01:00
|
|
|
|
|
|
|
// http://b/72331526 Disable -Wtautological-* until the instances detected by these
|
|
|
|
// new warnings are fixed.
|
2018-02-06 23:49:42 +01:00
|
|
|
"-Wno-tautological-constant-compare",
|
2018-01-10 23:30:44 +01:00
|
|
|
"-Wno-tautological-type-limit-compare",
|
|
|
|
"-Wno-tautological-unsigned-enum-zero-compare",
|
|
|
|
"-Wno-tautological-unsigned-zero-compare",
|
2017-12-07 04:56:34 +01:00
|
|
|
|
|
|
|
// http://b/72331524 Allow null pointer arithmetic until the instances detected by
|
|
|
|
// this new warning are fixed.
|
2018-02-06 23:49:42 +01:00
|
|
|
"-Wno-null-pointer-arithmetic",
|
2017-12-07 04:56:34 +01:00
|
|
|
|
2018-06-05 23:43:46 +02:00
|
|
|
// Disable c++98-specific warning since Android is not concerned with C++98
|
|
|
|
// compatibility.
|
|
|
|
"-Wno-c++98-compat-extra-semi",
|
2018-09-21 03:01:39 +02:00
|
|
|
|
|
|
|
// Disable this warning until we can fix all instances where it fails.
|
|
|
|
"-Wno-self-assign-overloaded",
|
|
|
|
|
|
|
|
// Disable this warning until we can fix all instances where it fails.
|
|
|
|
"-Wno-constant-logical-operand",
|
|
|
|
|
|
|
|
// Disable this warning because we don't care about behavior with older compilers.
|
|
|
|
"-Wno-return-std-move-in-c++11",
|
|
|
|
|
|
|
|
// Disable this warning until we can fix all instances where it fails.
|
|
|
|
"-Wno-dangling-field",
|
2016-03-04 02:21:04 +01:00
|
|
|
}, " "))
|
2018-06-06 23:42:44 +02:00
|
|
|
|
2018-06-29 22:20:38 +02:00
|
|
|
// Extra cflags for projects under external/ directory to disable warnings that are infeasible
|
|
|
|
// to fix in all the external projects and their upstream repos.
|
2018-06-06 23:42:44 +02:00
|
|
|
pctx.StaticVariable("ClangExtraExternalCflags", strings.Join([]string{
|
2018-06-29 22:20:38 +02:00
|
|
|
"-Wno-enum-compare",
|
|
|
|
"-Wno-enum-compare-switch",
|
2018-06-06 23:42:44 +02:00
|
|
|
}, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func ClangFilterUnknownCflags(cflags []string) []string {
|
2015-01-31 02:27:36 +01:00
|
|
|
ret := make([]string, 0, len(cflags))
|
|
|
|
for _, f := range cflags {
|
2016-07-29 22:44:28 +02:00
|
|
|
if !inListSorted(f, ClangUnknownCflags) {
|
2015-01-31 02:27:36 +01:00
|
|
|
ret = append(ret, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2018-04-03 20:33:34 +02:00
|
|
|
func ClangFilterUnknownLldflags(lldflags []string) []string {
|
|
|
|
ret := make([]string, 0, len(lldflags))
|
|
|
|
for _, f := range lldflags {
|
|
|
|
if !inListSorted(f, ClangUnknownLldflags) {
|
|
|
|
ret = append(ret, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01: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 00:21:33 +02:00
|
|
|
|
|
|
|
func sorted(list []string) []string {
|
|
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
|
|
}
|