blob: a87d56956501d0855efc1dcf3f054d335709a516 [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
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
// Cflags that should be filtered out when compiling with clang
var ClangUnknownCflags = sorted([]string{
// arm + arm64 + mips + mips64
// arm + arm64
// arm
// mips + mips64
// x86 + x86_64
// windows
// Ldflags that should be filtered out when linking with clang lld
var ClangUnknownLldflags = sorted([]string{
var ClangLibToolingUnknownCflags = sorted([]string{})
func init() {
pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
// 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.
// -Wimplicit-fallthrough is not enabled by -Wall.
// Help catch common 32/64-bit errors.
// 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?
// Disable overly aggressive warning for format strings.
// Bug: 20148343
// Workaround for ccache with clang.
// See
// Force clang to always output color diagnostics. Ninja will strip the ANSI
// color codes if it is not running in a terminal.
// http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
// Warnings from clang-7.0
// Warnings from clang-8.0
// Disable -Winconsistent-missing-override until we can clean up the existing
// codebase for it.
}, " "))
pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
// Enable clang's thread-safety annotations in libcxx.
// Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything.
// libc++'s math.h has an #include_next outside of system_headers.
}, " "))
pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
}, " "))
pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
// Bug: http://b/29823425 Disable -Wnull-dereference until the
// new cases detected by this warning in Clang r271374 are
// fixed.
// http://b/72331526 Disable -Wtautological-* until the instances detected by these
// new warnings are fixed.
// Disable c++98-specific warning since Android is not concerned with C++98
// compatibility.
// Disable this warning because we don't care about behavior with older compilers.
}, " "))
// Extra cflags for projects under external/ directory to disable warnings that are infeasible
// to fix in all the external projects and their upstream repos.
pctx.StaticVariable("ClangExtraExternalCflags", strings.Join([]string{
// http://b/72331524 Allow null pointer arithmetic until the instances detected by
// this new warning are fixed.
// Bug: http://b/29823425 Disable -Wnull-dereference until the
// new instances detected by this warning are fixed.
}, " "))
func ClangFilterUnknownCflags(cflags []string) []string {
ret := make([]string, 0, len(cflags))
for _, f := range cflags {
if !inListSorted(f, ClangUnknownCflags) {
ret = append(ret, f)
return ret
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
func inListSorted(s string, list []string) bool {
for _, l := range list {
if s == l {
return true
} else if s < l {
return false
return false
func sorted(list []string) []string {
return list