Bring our handling of -Wframe-larger-than more in line with GCC.

Support -Wno-frame-larger-than (with no =) and make it properly
interoperate with -Wframe-larger-than. Reject -Wframe-larger-than with
no argument.

We continue to support Clang's old spelling, -Wframe-larger-than=, for
compatibility with existing users of that facility.

In passing, stop the driver from accepting and ignoring
-fwarn-stack-size and make it a cc1-only flag as intended.
This commit is contained in:
Richard Smith 2021-06-17 20:26:15 -07:00
parent 3522167efd
commit 6aaf4fa288
7 changed files with 52 additions and 31 deletions

View File

@ -26,9 +26,9 @@ def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
DefaultFatal;
def warn_fe_frame_larger_than : Warning<"stack frame size of %0 bytes in %q1">,
BackendInfo, InGroup<BackendFrameLargerThanEQ>;
BackendInfo, InGroup<BackendFrameLargerThan>;
def warn_fe_backend_frame_larger_than: Warning<"%0">,
BackendInfo, InGroup<BackendFrameLargerThanEQ>;
BackendInfo, InGroup<BackendFrameLargerThan>;
def err_fe_backend_frame_larger_than: Error<"%0">, BackendInfo;
def note_fe_backend_frame_larger_than: Note<"%0">, BackendInfo;

View File

@ -1192,7 +1192,9 @@ def OpenMP : DiagGroup<"openmp", [
// Backend warnings.
def BackendInlineAsm : DiagGroup<"inline-asm">;
def BackendSourceMgr : DiagGroup<"source-mgr">;
def BackendFrameLargerThanEQ : DiagGroup<"frame-larger-than=">;
def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;
// Compatibility flag name from old versions of Clang.
def : DiagGroup<"frame-larger-than=", [BackendFrameLargerThan]>;
def BackendPlugin : DiagGroup<"backend-plugin">;
def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">;
def BackendOptimizationRemark : DiagGroup<"pass">;

View File

@ -1488,9 +1488,6 @@ defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
PosFlag<SetTrue>>;
def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,
Flags<[CC1Option]>, MarshallingInfoString<CodeGenOpts<"SymbolPartition">>;
def fwarn_stack_size_EQ : Joined<["-"], "fwarn-stack-size=">, Group<f_Group>,
Flags<[CC1Option]>,
MarshallingInfoInt<CodeGenOpts<"WarnStackSize">, "UINT_MAX">;
defm memory_profile : OptInFFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@ -2590,7 +2587,12 @@ def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1
// Just silence warnings about -Wlarger-than for now.
def Wlarger_than_EQ : Joined<["-"], "Wlarger-than=">, Group<clang_ignored_f_Group>;
def Wlarger_than_ : Joined<["-"], "Wlarger-than-">, Alias<Wlarger_than_EQ>;
def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group<f_Group>, Flags<[NoXarchOption]>;
// This is converted to -fwarn-stack-size=N and also passed through by the driver.
// FIXME: The driver should strip out the =<value> when passing W_value_Group through.
def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group<W_value_Group>,
Flags<[NoXarchOption, CC1Option]>;
def Wframe_larger_than : Flag<["-"], "Wframe-larger-than">, Alias<Wframe_larger_than_EQ>;
def : Flag<["-"], "fterminated-vtables">, Alias<fapple_kext>;
defm threadsafe_statics : BoolFOption<"threadsafe-statics",
@ -5047,6 +5049,9 @@ def fverify_debuginfo_preserve_export
"into specified (JSON) file (should be abs path as we use "
"append mode to insert new JSON objects).">,
MarshallingInfoString<CodeGenOpts<"DIBugsReportFilePath">>;
def fwarn_stack_size_EQ
: Joined<["-"], "fwarn-stack-size=">,
MarshallingInfoInt<CodeGenOpts<"WarnStackSize">, "UINT_MAX">;
// The driver option takes the key as a parameter to the -msign-return-address=
// and -mbranch-protection= options, but CC1 has a separate option so we
// don't have to parse the parameter twice.

View File

@ -4828,7 +4828,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
StringRef v = A->getValue();
CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v));
// FIXME: Validate the argument here so we don't produce meaningless errors
// about -fwarn-stack-size=.
if (v.empty())
D.Diag(diag::err_drv_missing_argument) << A->getSpelling() << 1;
else
CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v));
A->claim();
}

View File

@ -1,15 +1,31 @@
// RUN: %clang -Wframe-larger-than=42 \
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=ENABLE
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= \
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=DISABLE
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= -Wframe-larger-than=43 \
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=REENABLE
//
// TODO: we might want to look into being able to disable, then re-enable this
// warning properly. We could have the driver turn -Wframe-larger-than=X into
// -Wframe-larger-than -fwarn-stack-size=X. Also, we should support
// -Wno-frame-larger-than (no = suffix) like GCC.
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=ENABLE
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than \
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=DISABLE
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43 \
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=REENABLE
// RUN: not %clang -Wframe-larger-than= \
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG
// RUN: not %clang -Wframe-larger-than \
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG
// ENABLE: cc1 {{.*}} -fwarn-stack-size=42
// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wno-frame-larger-than=
// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wno-frame-larger-than=
// ENABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42
// ENABLE: frame-larger-than:
// ENABLE-SAME: warning
// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than
// DISABLE: frame-larger-than:
// DISABLE-SAME: ignored
// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43
// REENABLE: frame-larger-than:
// REENABLE-SAME: warning
// NOARG: error: argument to '-Wframe-larger-than=' is missing
// We need to create some state transitions before the pragma will dump anything.
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wframe-larger-than"
#pragma clang diagnostic pop
#pragma clang __debug diag_mapping "frame-larger-than"

View File

@ -6,9 +6,9 @@
//
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin 2> %t.err
// RUN: FileCheck < %t.err %s --check-prefix=REGULAR --check-prefix=ASM
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Werror=frame-larger-than= 2> %t.err
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Werror=frame-larger-than 2> %t.err
// RUN: FileCheck < %t.err %s --check-prefix=PROMOTE --check-prefix=ASM
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Wno-frame-larger-than= 2> %t.err
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Wno-frame-larger-than 2> %t.err
// RUN: FileCheck < %t.err %s --check-prefix=IGNORE --check-prefix=ASM
//
// RUN: %clang_cc1 %s -S -o - -triple=i386-apple-darwin -verify -no-integrated-as

View File

@ -36,20 +36,13 @@ void frameSizeWarning();
void frameSizeWarning(int) {}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-larger-than="
#pragma GCC diagnostic ignored "-Wframe-larger-than"
void frameSizeWarningIgnored() {
char buffer[80];
doIt(buffer);
}
#pragma GCC diagnostic pop
#pragma GCC diagnostic push
#ifndef IS_SYSHEADER
// expected-warning@+2 {{unknown warning group '-Wframe-larger-than'}}
#endif
#pragma GCC diagnostic ignored "-Wframe-larger-than"
#pragma GCC diagnostic pop
void frameSizeLocalClassWarning() {
struct S {
S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeLocalClassWarning()::S::S'}}