From 577827cbbf1033612d6ce15169f33ee5709abbfc Mon Sep 17 00:00:00 2001 From: Emil Kieri Date: Mon, 28 Mar 2022 20:28:51 +0200 Subject: [PATCH] [flang][driver] Make --version and -version consistent with 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 message, and stalled waiting for standard input. Fixes #51438 Reviewed By: PeteSteinfeld, awarzynski Differential Revision: https://reviews.llvm.org/D122542 --- clang/include/clang/Driver/Options.td | 9 +++++++-- flang/test/Driver/driver-help.f90 | 2 +- flang/test/Driver/driver-version.f90 | 16 +++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ac2f479f159e..8c488f254b1e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4205,7 +4205,7 @@ def _serialize_diags : Separate<["-", "--"], "serialize-diagnostics">, Flags<[No 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; def _std : Separate<["--"], "std">, Alias; @@ -5749,11 +5749,16 @@ def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">, // 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>; + +} // let Flags = [CC1Option, CC1AsOption, FC1Option, NoDriverOption] + +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>; diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 index 16cc6c428082..e020fa3801fd 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/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 Specify target triple (e.g. i686-apple-darwin9) ! HELP-FC1-NEXT: -U Undefine macro -! HELP-FC1-NEXT: --version Print version information +! HELP-FC1-NEXT: -version Print the compiler version ! HELP-FC1-NEXT: -W Enable the specified warning !--------------- diff --git a/flang/test/Driver/driver-version.f90 b/flang/test/Driver/driver-version.f90 index c3569be12a1a..e38a1e58b60b 100644 --- a/flang/test/Driver/driver-version.f90 +++ b/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'?