[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-27 Thread Kiran Kumar T P via cfe-commits

https://github.com/kiranktp updated 
https://github.com/llvm/llvm-project/pull/215966

>From 97d254cf09e26dac2728566976f6cac90fdc1066 Mon Sep 17 00:00:00 2001
From: Kiran Kumar T P 
Date: Thu, 13 Aug 2026 12:01:45 +0530
Subject: [PATCH] [flang] Improvise the error message for the option
 "-fconvert" with allowed values

For the option "-fconvert=foobar"

Earlier error message:
error: invalid value 'foobar' in '-fconvert=foobar'

Updated Error message:
error: invalid value 'foobar' in '-fconvert=foobar', expected one of: 
unknown,native,little-endian,big-endian,swap
---
 clang/include/clang/Options/FlangOptions.td | 1 +
 flang/lib/Frontend/CompilerInvocation.cpp   | 6 --
 flang/test/Driver/convert.f90   | 5 -
 llvm/include/llvm/Option/OptTable.h | 7 +++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 7a3dfd84fd4e7..7dc65eeb6bfc4 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -148,6 +148,7 @@ def ffixed_line_length_EQ : Joined<["-"], 
"ffixed-line-length=">, Group
 file}]>;
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
 def fconvert_EQ : Joined<["-"], "fconvert=">, Group,
+  Values<"unknown,native,little-endian,big-endian,swap">,
   HelpText<"Set endian conversion of data for unformatted files">;
 def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
   HelpText<"Set the default double precision kind to an 8 byte wide type">;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 87a25f3101ddd..f57b793ed8acb 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -877,8 +877,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 if (auto convert = parseConvertArg(argValue))
   opts.envDefaults.push_back({"FORT_CONVERT", *convert});
 else
-  diags.Report(clang::diag::err_drv_invalid_value)
-  << arg->getAsString(args) << argValue;
+  diags.Report(clang::diag::err_drv_invalid_value_with_suggestion)
+  << arg->getAsString(args) << argValue
+  << clang::getDriverOptTable().getOptionValues(
+ clang::options::OPT_fconvert_EQ);
   }
 
   // -f{no-}implicit-none
diff --git a/flang/test/Driver/convert.f90 b/flang/test/Driver/convert.f90
index 0b4da0282f3a7..ce88f5eb12b1e 100755
--- a/flang/test/Driver/convert.f90
+++ b/flang/test/Driver/convert.f90
@@ -10,6 +10,7 @@
 ! RUN: %flang -### -fconvert=big-endian %s  2>&1 | FileCheck %s 
--check-prefix=VALID
 ! RUN: %flang -### -fconvert=swap %s  2>&1 | FileCheck %s --check-prefix=VALID
 ! RUN: not %flang -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
 
 !-
 ! FRONTEND FLANG DRIVER (flang -fc1)
@@ -20,10 +21,12 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
 
 ! Only test that the command executes without error. Correct handling of each
 ! option is handled in Lowering tests.
 ! VALID: -fconvert
 ! VALID_FC1: module
 
-! INVALID: error: invalid value 'foobar' in '-fconvert=foobar'
+! INVALID: error: invalid value 'foobar' in '-fconvert=foobar', expected one 
of: unknown,native,little-endian,big-endian,swap
+! INVALID-BIG-ENDIAN: error: invalid value 'big_endian' in 
'-fconvert=big_endian', expected one of: 
unknown,native,little-endian,big-endian,swap
diff --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 45083b31c11f4..1a7c2006095ce 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -299,6 +299,13 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+return StringRef(getInfo(id).Values);
+  }
+
   /// Specify the environment variable where initial options should be read.
   void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; }
 

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-27 Thread Kiran Kumar T P via cfe-commits


@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();

kiranktp wrote:

Apologies for the delay. You are right, StringRef  takes care of nullptr. I wil 
do the needed changes and push it for review.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-19 Thread Kiran Kumar T P via cfe-commits

kiranktp wrote:

@tarunprabhu, I have incorporated your review comments. Please review.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-18 Thread Kiran Kumar T P via cfe-commits

https://github.com/kiranktp updated 
https://github.com/llvm/llvm-project/pull/215966

>From 662932d7e819b26c6e716a1c3328ef3a41cb0d47 Mon Sep 17 00:00:00 2001
From: Kiran Kumar T P 
Date: Thu, 13 Aug 2026 12:01:45 +0530
Subject: [PATCH] [flang] Improvise the error message for the option
 "-fconvert" with allowed values

For the option "-fconvert=foobar"

Earlier error message:
error: invalid value 'foobar' in '-fconvert=foobar'

Updated Error message:
error: invalid value 'foobar' in '-fconvert=foobar', expected one of: 
unknown,native,little-endian,big-endian,swap
---
 clang/include/clang/Options/FlangOptions.td | 1 +
 flang/lib/Frontend/CompilerInvocation.cpp   | 6 --
 flang/test/Driver/convert.f90   | 5 -
 llvm/include/llvm/Option/OptTable.h | 8 
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index cf40d0b909d8f..d1bf28d2cb103 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -148,6 +148,7 @@ def ffixed_line_length_EQ : Joined<["-"], 
"ffixed-line-length=">, Group
 file}]>;
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
 def fconvert_EQ : Joined<["-"], "fconvert=">, Group,
+  Values<"unknown,native,little-endian,big-endian,swap">,
   HelpText<"Set endian conversion of data for unformatted files">;
 def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
   HelpText<"Set the default double precision kind to an 8 byte wide type">;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index b57bc4583be38..7c40ee6550288 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -873,8 +873,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 if (auto convert = parseConvertArg(argValue))
   opts.envDefaults.push_back({"FORT_CONVERT", *convert});
 else
-  diags.Report(clang::diag::err_drv_invalid_value)
-  << arg->getAsString(args) << argValue;
+  diags.Report(clang::diag::err_drv_invalid_value_with_suggestion)
+  << arg->getAsString(args) << argValue
+  << clang::getDriverOptTable().getOptionValues(
+ clang::options::OPT_fconvert_EQ);
   }
 
   // -f{no-}implicit-none
diff --git a/flang/test/Driver/convert.f90 b/flang/test/Driver/convert.f90
index 0b4da0282f3a7..ce88f5eb12b1e 100755
--- a/flang/test/Driver/convert.f90
+++ b/flang/test/Driver/convert.f90
@@ -10,6 +10,7 @@
 ! RUN: %flang -### -fconvert=big-endian %s  2>&1 | FileCheck %s 
--check-prefix=VALID
 ! RUN: %flang -### -fconvert=swap %s  2>&1 | FileCheck %s --check-prefix=VALID
 ! RUN: not %flang -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
 
 !-
 ! FRONTEND FLANG DRIVER (flang -fc1)
@@ -20,10 +21,12 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
 
 ! Only test that the command executes without error. Correct handling of each
 ! option is handled in Lowering tests.
 ! VALID: -fconvert
 ! VALID_FC1: module
 
-! INVALID: error: invalid value 'foobar' in '-fconvert=foobar'
+! INVALID: error: invalid value 'foobar' in '-fconvert=foobar', expected one 
of: unknown,native,little-endian,big-endian,swap
+! INVALID-BIG-ENDIAN: error: invalid value 'big_endian' in 
'-fconvert=big_endian', expected one of: 
unknown,native,little-endian,big-endian,swap
diff --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 45083b31c11f4..0d00bcd896805 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();
+  }
+
   /// Specify the environment variable where initial options should be read.
   void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; }
 

___
cfe-commits mailing list
[email protected]

[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-17 Thread Kiran Kumar T P via cfe-commits


@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();

kiranktp wrote:

Yes. That was my understanding and I did use AI to explain it and it did convey 
the same.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-17 Thread Kiran Kumar T P via cfe-commits


@@ -20,10 +22,17 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
+! RUN: not %flang_fc1 -fconver=Foobar %s  2>&1 | FileCheck %s 
--check-prefix=UNKNOWN-OPTION

kiranktp wrote:

Agree. I would remove the same.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-14 Thread Tarun Prabhu via cfe-commits


@@ -20,10 +22,17 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
+! RUN: not %flang_fc1 -fconver=Foobar %s  2>&1 | FileCheck %s 
--check-prefix=UNKNOWN-OPTION

tarunprabhu wrote:

The closest option that is returned would depend on totally unrelated options 
that may be supported by the compiler. Would the test fail if an option like 
`fconverg` were added in the future? In this case, what is the "correct" 
behavior?

It seems to me that this has the potential to fail in the future for completely 
unrelated reasons. I am also not sure how valuable it is. I would recommend 
removing it.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-14 Thread Tarun Prabhu via cfe-commits


@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();

tarunprabhu wrote:

I believe that a `StringRef` is only valid for as long as the underlying string 
is valid. So you're saying that `Values` will not go out of scope before the 
program terminates, right?

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-14 Thread Tom Eccles via cfe-commits

https://github.com/tblah approved this pull request.

LGTM with Tarun's comments

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-13 Thread Kiran Kumar T P via cfe-commits


@@ -20,10 +22,17 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
+! RUN: not %flang_fc1 -fconver=Foobar %s  2>&1 | FileCheck %s 
--check-prefix=UNKNOWN-OPTION

kiranktp wrote:

I added this test to make sure the compiler is suggesting the closest option 
available. 
this test fails when the suggestion changes. 
If its redundant, I can remove this test.

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-13 Thread Kiran Kumar T P via cfe-commits


@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();

kiranktp wrote:

As I understood, "Returned StringRef" is valid for as long as the process runs. 

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-13 Thread Tom Eccles via cfe-commits


@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {
 return getInfo(id).MetaVar;
   }
 
+  /// Get the comma-separated list of values accepted by this option, as
+  /// declared by `Values` in its TableGen definition. Returns an empty string
+  /// for options that do not declare any.
+  StringRef getOptionValues(OptSpecifier id) const {
+const char *Values = getInfo(id).Values;
+return Values ? StringRef(Values) : StringRef();

tblah wrote:

Where is the buffer for Values stored? I'm worried about the lifetime of the 
StringRef?

https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-12 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-flang-driver

Author: Kiran Kumar T P (kiranktp)


Changes

For the option "-fconvert=foobar"

Earlier error message:
error: invalid value 'foobar' in '-fconvert=foobar'

Updated Error message:
error: invalid value 'foobar' in '-fconvert=foobar', expected one of: 
unknown,native,little-endian,big-endian,swap

---
Full diff: https://github.com/llvm/llvm-project/pull/215966.diff


4 Files Affected:

- (modified) clang/include/clang/Options/FlangOptions.td (+1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+4-2) 
- (modified) flang/test/Driver/convert.f90 (+10-1) 
- (modified) llvm/include/llvm/Option/OptTable.h (+8) 


``diff

``




https://github.com/llvm/llvm-project/pull/215966
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)

2026-08-12 Thread Kiran Kumar T P via cfe-commits

https://github.com/kiranktp created 
https://github.com/llvm/llvm-project/pull/215966

For the option "-fconvert=foobar"

Earlier error message:
error: invalid value 'foobar' in '-fconvert=foobar'

Updated Error message:
error: invalid value 'foobar' in '-fconvert=foobar', expected one of: 
unknown,native,little-endian,big-endian,swap

>From a4b7af11a6f7f01ba8c9e3bddd73c57084fc97b8 Mon Sep 17 00:00:00 2001
From: Kiran Kumar T P 
Date: Thu, 13 Aug 2026 12:01:45 +0530
Subject: [PATCH] [flang] Improvise the error message for the option
 "-fconvert" with allowed values

For the option "-fconvert=foobar"

Earlier error message:
error: invalid value 'foobar' in '-fconvert=foobar'

Updated Error message:
error: invalid value 'foobar' in '-fconvert=foobar', expected one of: 
unknown,native,little-endian,big-endian,swap
---
 clang/include/clang/Options/FlangOptions.td |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp   |  6 --
 flang/test/Driver/convert.f90   | 11 ++-
 llvm/include/llvm/Option/OptTable.h |  8 
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index cf40d0b909d8f..d1bf28d2cb103 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -148,6 +148,7 @@ def ffixed_line_length_EQ : Joined<["-"], 
"ffixed-line-length=">, Group
 file}]>;
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
 def fconvert_EQ : Joined<["-"], "fconvert=">, Group,
+  Values<"unknown,native,little-endian,big-endian,swap">,
   HelpText<"Set endian conversion of data for unformatted files">;
 def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
   HelpText<"Set the default double precision kind to an 8 byte wide type">;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index b57bc4583be38..7c40ee6550288 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -873,8 +873,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 if (auto convert = parseConvertArg(argValue))
   opts.envDefaults.push_back({"FORT_CONVERT", *convert});
 else
-  diags.Report(clang::diag::err_drv_invalid_value)
-  << arg->getAsString(args) << argValue;
+  diags.Report(clang::diag::err_drv_invalid_value_with_suggestion)
+  << arg->getAsString(args) << argValue
+  << clang::getDriverOptTable().getOptionValues(
+ clang::options::OPT_fconvert_EQ);
   }
 
   // -f{no-}implicit-none
diff --git a/flang/test/Driver/convert.f90 b/flang/test/Driver/convert.f90
index 0b4da0282f3a7..64af61a8b9643 100755
--- a/flang/test/Driver/convert.f90
+++ b/flang/test/Driver/convert.f90
@@ -10,6 +10,8 @@
 ! RUN: %flang -### -fconvert=big-endian %s  2>&1 | FileCheck %s 
--check-prefix=VALID
 ! RUN: %flang -### -fconvert=swap %s  2>&1 | FileCheck %s --check-prefix=VALID
 ! RUN: not %flang -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
+! RUN: not %flang -fconver=Foobar %s  2>&1 | FileCheck %s 
--check-prefix=UNKNOWN-OPTION
 
 !-
 ! FRONTEND FLANG DRIVER (flang -fc1)
@@ -20,10 +22,17 @@
 ! RUN: %flang_fc1 -emit-mlir -fconvert=big-endian %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: %flang_fc1 -emit-mlir -fconvert=swap %s -o - | FileCheck %s 
--check-prefix=VALID_FC1
 ! RUN: not %flang_fc1 -fconvert=foobar %s  2>&1 | FileCheck %s 
--check-prefix=INVALID
+! RUN: not %flang_fc1 -fconvert=big_endian %s  2>&1 | FileCheck %s 
--check-prefix=INVALID-BIG-ENDIAN
+! RUN: not %flang_fc1 -fconver=Foobar %s  2>&1 | FileCheck %s 
--check-prefix=UNKNOWN-OPTION
 
 ! Only test that the command executes without error. Correct handling of each
 ! option is handled in Lowering tests.
 ! VALID: -fconvert
 ! VALID_FC1: module
 
-! INVALID: error: invalid value 'foobar' in '-fconvert=foobar'
+! INVALID: error: invalid value 'foobar' in '-fconvert=foobar', expected one 
of: unknown,native,little-endian,big-endian,swap
+! INVALID-BIG-ENDIAN: error: invalid value 'big_endian' in 
'-fconvert=big_endian', expected one of: 
unknown,native,little-endian,big-endian,swap
+
+! The option itself is misspelled, so the value is never reached and the driver
+! suggests the correct spelling instead.
+! UNKNOWN-OPTION: error: unknown argument '-fconver=Foobar'; did you mean 
'-fconvert=Foobar'?
diff --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 45083b31c11f4..0d00bcd896805 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -299,6 +299,14 @@ class LLVM_ABI OptTable {