Skip to content

Commit

Permalink
-Wframe-larger-than=: improve error with an invalid argument
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaskRay committed Apr 25, 2023
1 parent f40d186 commit e66c2db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Driver/Wframe-larger-than.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit e66c2db

Please sign in to comment.