Skip to content

Commit 6aaf4fa

Browse files
committed
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.
1 parent 3522167 commit 6aaf4fa

File tree

7 files changed

+53
-32
lines changed

7 files changed

+53
-32
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
2626
DefaultFatal;
2727

2828
def warn_fe_frame_larger_than : Warning<"stack frame size of %0 bytes in %q1">,
29-
BackendInfo, InGroup<BackendFrameLargerThanEQ>;
29+
BackendInfo, InGroup<BackendFrameLargerThan>;
3030
def warn_fe_backend_frame_larger_than: Warning<"%0">,
31-
BackendInfo, InGroup<BackendFrameLargerThanEQ>;
31+
BackendInfo, InGroup<BackendFrameLargerThan>;
3232
def err_fe_backend_frame_larger_than: Error<"%0">, BackendInfo;
3333
def note_fe_backend_frame_larger_than: Note<"%0">, BackendInfo;
3434

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,9 @@ def OpenMP : DiagGroup<"openmp", [
11921192
// Backend warnings.
11931193
def BackendInlineAsm : DiagGroup<"inline-asm">;
11941194
def BackendSourceMgr : DiagGroup<"source-mgr">;
1195-
def BackendFrameLargerThanEQ : DiagGroup<"frame-larger-than=">;
1195+
def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;
1196+
// Compatibility flag name from old versions of Clang.
1197+
def : DiagGroup<"frame-larger-than=", [BackendFrameLargerThan]>;
11961198
def BackendPlugin : DiagGroup<"backend-plugin">;
11971199
def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">;
11981200
def BackendOptimizationRemark : DiagGroup<"pass">;

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,6 @@ defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
14881488
PosFlag<SetTrue>>;
14891489
def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,
14901490
Flags<[CC1Option]>, MarshallingInfoString<CodeGenOpts<"SymbolPartition">>;
1491-
def fwarn_stack_size_EQ : Joined<["-"], "fwarn-stack-size=">, Group<f_Group>,
1492-
Flags<[CC1Option]>,
1493-
MarshallingInfoInt<CodeGenOpts<"WarnStackSize">, "UINT_MAX">;
14941491

14951492
defm memory_profile : OptInFFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
14961493
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@@ -2590,7 +2587,12 @@ def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1
25902587
// Just silence warnings about -Wlarger-than for now.
25912588
def Wlarger_than_EQ : Joined<["-"], "Wlarger-than=">, Group<clang_ignored_f_Group>;
25922589
def Wlarger_than_ : Joined<["-"], "Wlarger-than-">, Alias<Wlarger_than_EQ>;
2593-
def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group<f_Group>, Flags<[NoXarchOption]>;
2590+
2591+
// This is converted to -fwarn-stack-size=N and also passed through by the driver.
2592+
// FIXME: The driver should strip out the =<value> when passing W_value_Group through.
2593+
def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group<W_value_Group>,
2594+
Flags<[NoXarchOption, CC1Option]>;
2595+
def Wframe_larger_than : Flag<["-"], "Wframe-larger-than">, Alias<Wframe_larger_than_EQ>;
25942596

25952597
def : Flag<["-"], "fterminated-vtables">, Alias<fapple_kext>;
25962598
defm threadsafe_statics : BoolFOption<"threadsafe-statics",
@@ -5047,6 +5049,9 @@ def fverify_debuginfo_preserve_export
50475049
"into specified (JSON) file (should be abs path as we use "
50485050
"append mode to insert new JSON objects).">,
50495051
MarshallingInfoString<CodeGenOpts<"DIBugsReportFilePath">>;
5052+
def fwarn_stack_size_EQ
5053+
: Joined<["-"], "fwarn-stack-size=">,
5054+
MarshallingInfoInt<CodeGenOpts<"WarnStackSize">, "UINT_MAX">;
50505055
// The driver option takes the key as a parameter to the -msign-return-address=
50515056
// and -mbranch-protection= options, but CC1 has a separate option so we
50525057
// don't have to parse the parameter twice.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4828,7 +4828,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48284828

48294829
if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
48304830
StringRef v = A->getValue();
4831-
CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v));
4831+
// FIXME: Validate the argument here so we don't produce meaningless errors
4832+
// about -fwarn-stack-size=.
4833+
if (v.empty())
4834+
D.Diag(diag::err_drv_missing_argument) << A->getSpelling() << 1;
4835+
else
4836+
CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v));
48324837
A->claim();
48334838
}
48344839

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
// RUN: %clang -Wframe-larger-than=42 \
2-
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=ENABLE
3-
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= \
4-
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=DISABLE
5-
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= -Wframe-larger-than=43 \
6-
// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=REENABLE
7-
//
8-
// TODO: we might want to look into being able to disable, then re-enable this
9-
// warning properly. We could have the driver turn -Wframe-larger-than=X into
10-
// -Wframe-larger-than -fwarn-stack-size=X. Also, we should support
11-
// -Wno-frame-larger-than (no = suffix) like GCC.
12-
13-
// ENABLE: cc1 {{.*}} -fwarn-stack-size=42
14-
// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wno-frame-larger-than=
15-
// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wno-frame-larger-than=
2+
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=ENABLE
3+
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than \
4+
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=DISABLE
5+
// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43 \
6+
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=REENABLE
7+
// RUN: not %clang -Wframe-larger-than= \
8+
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG
9+
// RUN: not %clang -Wframe-larger-than \
10+
// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG
11+
12+
// ENABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42
13+
// ENABLE: frame-larger-than:
14+
// ENABLE-SAME: warning
15+
16+
// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than
17+
// DISABLE: frame-larger-than:
18+
// DISABLE-SAME: ignored
19+
20+
// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43
21+
// REENABLE: frame-larger-than:
22+
// REENABLE-SAME: warning
23+
24+
// NOARG: error: argument to '-Wframe-larger-than=' is missing
25+
26+
// We need to create some state transitions before the pragma will dump anything.
27+
#pragma clang diagnostic push
28+
#pragma clang diagnostic warning "-Wframe-larger-than"
29+
#pragma clang diagnostic pop
30+
31+
#pragma clang __debug diag_mapping "frame-larger-than"

clang/test/Frontend/backend-diagnostic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin 2> %t.err
88
// RUN: FileCheck < %t.err %s --check-prefix=REGULAR --check-prefix=ASM
9-
// 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
9+
// 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
1010
// RUN: FileCheck < %t.err %s --check-prefix=PROMOTE --check-prefix=ASM
11-
// 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
11+
// 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
1212
// RUN: FileCheck < %t.err %s --check-prefix=IGNORE --check-prefix=ASM
1313
//
1414
// RUN: %clang_cc1 %s -S -o - -triple=i386-apple-darwin -verify -no-integrated-as

clang/test/Misc/backend-stack-frame-diagnostics.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,13 @@ void frameSizeWarning();
3636
void frameSizeWarning(int) {}
3737

3838
#pragma GCC diagnostic push
39-
#pragma GCC diagnostic ignored "-Wframe-larger-than="
39+
#pragma GCC diagnostic ignored "-Wframe-larger-than"
4040
void frameSizeWarningIgnored() {
4141
char buffer[80];
4242
doIt(buffer);
4343
}
4444
#pragma GCC diagnostic pop
4545

46-
#pragma GCC diagnostic push
47-
#ifndef IS_SYSHEADER
48-
// expected-warning@+2 {{unknown warning group '-Wframe-larger-than'}}
49-
#endif
50-
#pragma GCC diagnostic ignored "-Wframe-larger-than"
51-
#pragma GCC diagnostic pop
52-
5346
void frameSizeLocalClassWarning() {
5447
struct S {
5548
S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeLocalClassWarning()::S::S'}}

0 commit comments

Comments
 (0)