Skip to content

Commit

Permalink
[Driver] Don't try to spell check unsupported options
Browse files Browse the repository at this point in the history
We currently spell check options that are listed as unsupported, but
this doesn't make much sense. If an option is explicitly unsupported
why would one that's spelled similarly be useful?

It looks like the reason this was added was that we explicitly mark
all `--something` flags as Unsupported rather than just leaving them
undefined and treating them as unknown. Drop that handling so that we
don't regress on things like misspelling `--help`.

Differential Revision: https://reviews.llvm.org/D156925
  • Loading branch information
bogner committed Aug 2, 2023
1 parent 61af957 commit 7ef1718
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4773,7 +4773,6 @@ def _warn__EQ : Joined<["--"], "warn-=">, Alias<W_Joined>;
def _warn_ : Joined<["--"], "warn-">, Alias<W_Joined>;
def _write_dependencies : Flag<["--"], "write-dependencies">, Alias<MD>;
def _write_user_dependencies : Flag<["--"], "write-user-dependencies">, Alias<MMD>;
def _ : Joined<["--"], "">, Flags<[Unsupported]>;

// Hexagon feature flags.
let Flags = [TargetSpecific] in {
Expand Down
16 changes: 3 additions & 13 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,9 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
// Check for unsupported options.
for (const Arg *A : Args) {
if (A->getOption().hasFlag(options::Unsupported)) {
unsigned DiagID;
auto ArgString = A->getAsString(Args);
std::string Nearest;
if (getOpts().findNearest(
ArgString, Nearest, IncludedFlagsBitmask,
ExcludedFlagsBitmask | options::Unsupported) > 1) {
DiagID = diag::err_drv_unsupported_opt;
Diag(DiagID) << ArgString;
} else {
DiagID = diag::err_drv_unsupported_opt_with_suggestion;
Diag(DiagID) << ArgString << Nearest;
}
ContainsError |= Diags.getDiagnosticLevel(DiagID, SourceLocation()) >
Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args);
ContainsError |= Diags.getDiagnosticLevel(diag::err_drv_unsupported_opt,
SourceLocation()) >
DiagnosticsEngine::Warning;
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Driver/unsupported-option.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// RUN: not %clang %s --hedonism -### 2>&1 | \
// RUN: FileCheck %s
// CHECK: error: unsupported option '--hedonism'
// CHECK: error: unknown argument: '--hedonism'

// RUN: not %clang %s --hell -### 2>&1 | \
// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
// DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
// DID-YOU-MEAN: error: unknown argument '--hell'; did you mean '--help'?

// RUN: not %clang --target=powerpc-ibm-aix %s -mlong-double-128 2>&1 | \
// RUN: FileCheck %s --check-prefix=AIX-LONGDOUBLE128-ERR
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Driver/driver-version.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
! VERSION-NEXT: Thread model:
! VERSION-NEXT: InstalledDir:

! ERROR: flang-new: error: unsupported option '--versions'; did you mean '--version'?
! ERROR: flang-new: error: unknown argument '--versions'; did you mean '--version'?

! VERSION-FC1: LLVM version

Expand Down

0 comments on commit 7ef1718

Please sign in to comment.