[PATCH] D122542: [flang][driver] Make --version and -version consistent with clang

Emil Kieri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 27 00:47:50 PDT 2022


ekieri created this revision.
ekieri added reviewers: PeteSteinfeld, awarzynski.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
ekieri requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

This patch makes -version valid, and --version invalid, for
flang-new -fc1. The invocation

  flang-new --version

remains valid. This behaviour is consistent with clang
(and with clang -cc1 and clang -cc1as).

Previously, flang-new -fc1 accepted --version (as per Options.td), but
the frontend driver acutally checks for -version. As a result,

  flang-new -fc1 --version

triggered no action, emitted no messaged, and stalled waiting for
standard input.

Fixes #51438


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122542

Files:
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help.f90
  flang/test/Driver/driver-version.f90


Index: flang/test/Driver/driver-version.f90
===================================================================
--- flang/test/Driver/driver-version.f90
+++ flang/test/Driver/driver-version.f90
@@ -2,15 +2,21 @@
 !-----------
 ! RUN LINES
 !-----------
-! RUN: %flang --version 2>&1 | FileCheck %s
+! RUN: %flang --version 2>&1 | FileCheck %s --check-prefix=VERSION
 ! RUN: not %flang --versions 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: %flang_fc1 -version 2>&1 | FileCheck %s --check-prefix=VERSION-FC1
+! RUN: not %flang_fc1 --version 2>&1 | FileCheck %s --check-prefix=ERROR-FC1
 
 !-----------------------
 ! EXPECTED OUTPUT
 !-----------------------
-! CHECK: flang-new version
-! CHECK-NEXT: Target:
-! CHECK-NEXT: Thread model:
-! CHECK-NEXT: InstalledDir:
+! VERSION: flang-new version
+! VERSION-NEXT: Target:
+! VERSION-NEXT: Thread model:
+! VERSION-NEXT: InstalledDir:
 
 ! ERROR: flang-new: error: unsupported option '--versions'; did you mean '--version'?
+
+! VERSION-FC1: LLVM version
+
+! ERROR-FC1: error: unknown argument '--version'; did you mean '-version'?
Index: flang/test/Driver/driver-help.f90
===================================================================
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -135,7 +135,7 @@
 ! HELP-FC1-NEXT: -test-io               Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -triple <value>        Specify target triple (e.g. i686-apple-darwin9)
 ! HELP-FC1-NEXT: -U <macro>             Undefine macro <macro>
-! HELP-FC1-NEXT: --version              Print version information
+! HELP-FC1-NEXT: -version               Print the compiler version
 ! HELP-FC1-NEXT: -W<warning>            Enable the specified warning
 
 !---------------
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4203,7 +4203,7 @@
   HelpText<"Serialize compiler diagnostics to a file">;
 // We give --version different semantics from -version.
 def _version : Flag<["--"], "version">,
-  Flags<[CoreOption, FC1Option, FlangOption]>,
+  Flags<[CoreOption, FlangOption]>,
   HelpText<"Print version information">;
 def _signed_char : Flag<["--"], "signed-char">, Alias<fsigned_char>;
 def _std : Separate<["--"], "std">, Alias<std_EQ>;
@@ -5747,11 +5747,16 @@
 // Language Options
 //===----------------------------------------------------------------------===//
 
-let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
+let Flags = [CC1Option, CC1AsOption, FC1Option, NoDriverOption] in {
 
 def version : Flag<["-"], "version">,
   HelpText<"Print the compiler version">,
   MarshallingInfoFlag<FrontendOpts<"ShowVersion">>;
+
+}
+
+let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
+
 def main_file_name : Separate<["-"], "main-file-name">,
   HelpText<"Main file name to use for debug info and source if missing">,
   MarshallingInfoString<CodeGenOpts<"MainFileName">>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122542.418441.patch
Type: text/x-patch
Size: 3053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220327/e73e3d6c/attachment-0001.bin>


More information about the cfe-commits mailing list