https://github.com/kiranktp updated https://github.com/llvm/llvm-project/pull/215966
>From d85cfa6fb5f85e19e4fc2c2185ee6fbe409ff447 Mon Sep 17 00:00:00 2001 From: Kiran Kumar T P <[email protected]> Date: Thu, 13 Aug 2026 12:01:45 +0530 Subject: [PATCH 1/2] [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<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 ff4c7f6a18624..860683b92d250 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -887,8 +887,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; } >From a8775fafc67e1b91fe41b317305af0d864ee9ca0 Mon Sep 17 00:00:00 2001 From: Kiran Kumar T P <[email protected]> Date: Tue, 1 Sep 2026 12:31:26 +0530 Subject: [PATCH 2/2] Address review comments : removed redundent test --- flang/test/Driver/convert.f90 | 3 --- 1 file changed, 3 deletions(-) diff --git a/flang/test/Driver/convert.f90 b/flang/test/Driver/convert.f90 index ce88f5eb12b1e..757f22394c7f9 100755 --- a/flang/test/Driver/convert.f90 +++ b/flang/test/Driver/convert.f90 @@ -10,7 +10,6 @@ ! 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) @@ -21,7 +20,6 @@ ! 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. @@ -29,4 +27,3 @@ ! VALID_FC1: module ! 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
