[flang-commits] [clang] [flang] [llvm] [flang] Improvise the error message for the option "-fconvert" with allowed values (PR #215966)
Kiran Kumar T P via flang-commits
flang-commits at lists.llvm.org
Wed Aug 12 23:34:12 PDT 2026
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 <kirankumar.tp at amd.com>
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<f_Group>
file}]>;
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
def fconvert_EQ : Joined<["-"], "fconvert=">, Group<f_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<f_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 {
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; }
More information about the flang-commits
mailing list