Skip to content

Instantly share code, notes, and snippets.

@yamaguchi1024
Created June 26, 2017 00:16
Show Gist options
  • Save yamaguchi1024/fca8ed72f8dacdf61d145859feb64856 to your computer and use it in GitHub Desktop.
Save yamaguchi1024/fca8ed72f8dacdf61d145859feb64856 to your computer and use it in GitHub Desktop.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3833f0f..106392f 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -127,7 +127,7 @@ def warn_drv_yc_multiple_inputs_clang_cl : Warning<
"support for '/Yc' with more than one source file not implemented yet; flag ignored">,
InGroup<ClangClPch>;
-def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
+def err_drv_invalid_value : Error<"invalid value '%1' in '%0'. Did you mean '%2'?">;
def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
def err_drv_invalid_remap_file : Error<
"invalid option '%0' not of the form <from-file>;<to-file>">;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 6254b00..bc13c8d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2555,7 +2555,7 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
.Default(llvm::EABI::Unknown);
if (EABIVersion == llvm::EABI::Unknown)
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
- << Value;
+ << Value << OptTable::findNearestValue(Opts, OPT_meabi, Value);
else
Opts.EABIVersion = Value;
}
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index 3e7b019..3ff3024 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -121,6 +121,12 @@ public:
return getInfo(id).MetaVar;
}
+ const char *getOptionValues(OptSpecifier id) const {
+ return getInfo(id).Values;
+ }
+
+ StringRef findNearestValue(const OptTable &Opts, OptSpecifier id, StringRef Value) const;
+
/// Find possible value for given flags. This is used for shell
/// autocompletion.
///
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index acb9e8d..339b5f7 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -203,6 +203,23 @@ static bool optionMatches(const OptTable::Info &In, StringRef Option) {
return false;
}
+StringRef findNearestValue(const OptTable &Opts, OptSpecifier Id, StringRef Value) {
+ SmallVector<StringRef, 8> Candidates;
+ StringRef(Opts.getOptionValues(Id)).split(Candidates, ",", -1, false);
+
+ int Max = 0;
+ StringRef Res;
+ for (StringRef Val : Candidates) {
+ int E = Value.edit_distance(Val);
+ if (E >= Max) {
+ Max = E;
+ Res = Val;
+ }
+ }
+
+ return Res;
+}
+
// This function is for flag value completion.
// Eg. When "-stdlib=" and "l" was passed to this function, it will return
// appropiriate values for stdlib, which starts with l.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment