[clang] e66c2db - -Wframe-larger-than=: improve error with an invalid argument

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 20:11:27 PDT 2023


Author: Fangrui Song
Date: 2023-04-24T20:11:21-07:00
New Revision: e66c2db7996ed0ce8cd27548a623ce62246be33b

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

LOG: -Wframe-larger-than=: improve error with an invalid argument

Remove a FIXME. For simplicity, the error message for the missing argument case
has changed from err_drv_missing_argument to err_drv_invalid_argument_to_option,
which should be fine.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/Wframe-larger-than.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f7544c8f593c8..95ef79416acff 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5230,14 +5230,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
-    StringRef v = A->getValue();
-    // 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;
+    StringRef V = A->getValue(), V1 = V;
+    unsigned Size;
+    if (V1.consumeInteger(10, Size) || !V1.empty())
+      D.Diag(diag::err_drv_invalid_argument_to_option)
+          << V << A->getOption().getName();
     else
-      CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v));
-    A->claim();
+      CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + V));
   }
 
   Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,

diff  --git a/clang/test/Driver/Wframe-larger-than.c b/clang/test/Driver/Wframe-larger-than.c
index cc5b5d0a2ca1a..768ff4407624b 100644
--- a/clang/test/Driver/Wframe-larger-than.c
+++ b/clang/test/Driver/Wframe-larger-than.c
@@ -8,6 +8,7 @@
 // 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
+// RUN: not %clang -Wframe-larger-than=0x2a -E %s 2>&1 | FileCheck %s --check-prefix=INVALID
 
 // ENABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42
 // ENABLE: frame-larger-than:
@@ -21,7 +22,8 @@
 // REENABLE: frame-larger-than:
 // REENABLE-SAME: warning
 
-// NOARG: error: argument to '-Wframe-larger-than=' is missing
+// NOARG: error: invalid argument '' to -Wframe-larger-than=
+// INVALID: error: invalid argument '0x2a' to -Wframe-larger-than=
 
 // We need to create some state transitions before the pragma will dump anything.
 #pragma clang diagnostic push


        


More information about the cfe-commits mailing list