[clang] 6aaf4fa - Bring our handling of -Wframe-larger-than more in line with GCC.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 17 20:29:28 PDT 2021


Author: Richard Smith
Date: 2021-06-17T20:29:13-07:00
New Revision: 6aaf4fa2885600b0e31042071ad06f78218ab0f2

URL: https://github.com/llvm/llvm-project/commit/6aaf4fa2885600b0e31042071ad06f78218ab0f2
DIFF: https://github.com/llvm/llvm-project/commit/6aaf4fa2885600b0e31042071ad06f78218ab0f2.diff

LOG: 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.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticFrontendKinds.td
    clang/include/clang/Basic/DiagnosticGroups.td
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/Wframe-larger-than.c
    clang/test/Frontend/backend-diagnostic.c
    clang/test/Misc/backend-stack-frame-diagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 5122770316cde..e68058dd19b5b 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -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;
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index b4be0fcfb454f..ca8e05f27fc5f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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">;

diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 151968de1789e..0ccf5ef891990 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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.

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ddec79abd45f8..f6e3447eccb02 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -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();
   }
 

diff  --git a/clang/test/Driver/Wframe-larger-than.c b/clang/test/Driver/Wframe-larger-than.c
index 178632570d0e9..cc5b5d0a2ca1a 100644
--- a/clang/test/Driver/Wframe-larger-than.c
+++ b/clang/test/Driver/Wframe-larger-than.c
@@ -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.
-
-// 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=
+// 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 {{.*}} -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"

diff  --git a/clang/test/Frontend/backend-diagnostic.c b/clang/test/Frontend/backend-diagnostic.c
index 8ec3b90cdd96a..01029d7f83d66 100644
--- a/clang/test/Frontend/backend-diagnostic.c
+++ b/clang/test/Frontend/backend-diagnostic.c
@@ -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

diff  --git a/clang/test/Misc/backend-stack-frame-diagnostics.cpp b/clang/test/Misc/backend-stack-frame-diagnostics.cpp
index e460294e1c7c9..b02e7f4c471d5 100644
--- a/clang/test/Misc/backend-stack-frame-diagnostics.cpp
+++ b/clang/test/Misc/backend-stack-frame-diagnostics.cpp
@@ -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 at +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'}}


        


More information about the cfe-commits mailing list