[Sema] Special case -Werror-implicit-function-declaration and reject other -Werror-

This is the only -Werror- form warning option GCC supports (gcc/c-family/c.opt).
Fortunately no other form is used anywhere.
This commit is contained in:
Fangrui Song 2020-11-05 10:25:30 -08:00
parent f253823398
commit c6a384df1f
6 changed files with 12 additions and 8 deletions

View File

@ -130,11 +130,14 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
}
// -Werror/-Wno-error is a special case, not controlled by the option
// table. It also has the "specifier" form of -Werror=foo and -Werror-foo.
// table. It also has the "specifier" form of -Werror=foo. GCC supports
// the deprecated -Werror-implicit-function-declaration which is used by
// a few projects.
if (Opt.startswith("error")) {
StringRef Specifier;
if (Opt.size() > 5) { // Specifier must be present.
if ((Opt[5] != '=' && Opt[5] != '-') || Opt.size() == 6) {
if (Opt[5] != '=' &&
Opt.substr(5) != "-implicit-function-declaration") {
if (Report)
Diags.Report(diag::warn_unknown_warning_specifier)
<< "-Werror" << ("-W" + OrigOpt.str());

View File

@ -1,5 +1,5 @@
// RUN: %clang_cc1 -Wno-error-vec-elem-size -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -Wno-error-vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -Wno-error=vec-elem-size -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -Wno-error=vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s
#ifdef EXT
typedef __attribute__((__ext_vector_type__(8))) char vector_char8;

View File

@ -1,7 +1,8 @@
// RUN: %clang_cc1 -Wmonkey -Wno-monkey -Wno-unused-command-line-arguments \
// RUN: -Wno-unused-command-line-argument -Wmodule-build -Rmodule-built %s 2>&1 | FileCheck %s
// RUN: -Wno-unused-command-line-argument -Wmodule-build -Werror-vla -Rmodule-built %s 2>&1 | FileCheck %s
// CHECK: unknown warning option '-Wmonkey'
// CHECK: unknown warning option '-Wno-monkey'
// CHECK: unknown warning option '-Wno-unused-command-line-arguments'; did you mean '-Wno-unused-command-line-argument'?
// CHECK: unknown warning option '-Wmodule-build'; did you mean '-Wmodule-conflict'?
// CHECK-NEXT: unknown -Werror warning specifier: '-Werror-vla'
// CHECK: unknown remark option '-Rmodule-built'; did you mean '-Rmodule-build'?

View File

@ -2,6 +2,9 @@
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/diagnose-missing-import \
// RUN: -Werror=implicit-function-declaration -fsyntax-only \
// RUN: -fimplicit-module-maps -verify %s
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/diagnose-missing-import \
// RUN: -Werror-implicit-function-declaration -fsyntax-only \
// RUN: -fimplicit-module-maps -verify %s
@import NCI;
void foo() {

View File

@ -1,5 +1,4 @@
// RUN: %clang_cc1 %s -Eonly -Werror=undef -verify
// RUN: %clang_cc1 %s -Eonly -Werror-undef -verify
extern int x;

View File

@ -1,7 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s
// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s
// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s
// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s
#ifdef EXT
typedef __attribute__((__ext_vector_type__(8))) char vector_char8;