[flang-commits] [flang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)
via flang-commits
flang-commits at lists.llvm.org
Thu Oct 12 07:26:13 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: Yuanfang Chen (yuanfang-chen)
<details>
<summary>Changes</summary>
Match GCC driver. GCC has -cc1/-fc1 support too, but this patch does not address that.
---
Full diff: https://github.com/llvm/llvm-project/pull/68896.diff
7 Files Affected:
- (modified) clang/include/clang/Driver/Driver.h (+6-1)
- (modified) clang/include/clang/Driver/Options.td (+6-2)
- (modified) clang/lib/Driver/Driver.cpp (+5-4)
- (modified) flang/test/Driver/driver-help-hidden.f90 (+2)
- (modified) flang/test/Driver/driver-help.f90 (+2)
- (added) flang/test/Driver/dumpmachine.f90 (+8)
- (added) flang/test/Driver/immediate-options.f90 (+2)
``````````diff
diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..fdb8aaf3572ba31 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -12,6 +12,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/HeaderInclude.h"
#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Version.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/InputInfo.h"
@@ -188,6 +189,9 @@ class Driver {
/// Driver title to use with help.
std::string DriverTitle;
+ /// Driver version.
+ std::string DriverVersion;
+
/// Information about the host which can be overridden by the user.
std::string HostBits, HostMachine, HostSystem, HostRelease;
@@ -373,7 +377,8 @@ class Driver {
Driver(StringRef ClangExecutable, StringRef TargetTriple,
DiagnosticsEngine &Diags, std::string Title = "clang LLVM compiler",
- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr,
+ std::string Version = CLANG_VERSION_STRING);
/// @name Accessors
/// @{
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c272a7f1c398aa6..cae7bd07fc3cc54 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1375,9 +1375,13 @@ def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
def dumpdir : Separate<["-"], "dumpdir">, Visibility<[ClangOption, CC1Option]>,
MetaVarName<"<dumppfx>">,
HelpText<"Use <dumpfpx> as a prefix to form auxiliary and dump file names">;
-def dumpmachine : Flag<["-"], "dumpmachine">;
+def dumpmachine : Flag<["-"], "dumpmachine">,
+ Visibility<[ClangOption, FlangOption]>,
+ HelpText<"Display the compiler's target processor">;
+def dumpversion : Flag<["-"], "dumpversion">,
+ Visibility<[ClangOption, FlangOption]>,
+ HelpText<"Display the version of the compiler">;
def dumpspecs : Flag<["-"], "dumpspecs">, Flags<[Unsupported]>;
-def dumpversion : Flag<["-"], "dumpversion">;
def dylib__file : Separate<["-"], "dylib_file">;
def dylinker__install__name : JoinedOrSeparate<["-"], "dylinker_install_name">;
def dylinker : Flag<["-"], "dylinker">;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 77328e1f99e5021..c84acb2beb17a70 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -190,14 +190,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
DiagnosticsEngine &Diags, std::string Title,
- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
+ std::string Version)
: Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None),
ModulesModeCXX20(false), LTOMode(LTOK_None),
ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
- DriverTitle(Title), CCCPrintBindings(false), CCPrintOptions(false),
- CCLogDiagnostics(false), CCGenDiagnostics(false),
+ DriverTitle(Title), DriverVersion(Version), CCCPrintBindings(false),
+ CCPrintOptions(false), CCLogDiagnostics(false), CCGenDiagnostics(false),
CCPrintProcessStats(false), CCPrintInternalStats(false),
TargetTriple(TargetTriple), Saver(Alloc), PrependArg(nullptr),
CheckInputsExist(true), ProbePrecompiled(true),
@@ -2081,7 +2082,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
if (C.getArgs().hasArg(options::OPT_dumpversion)) {
// Since -dumpversion is only implemented for pedantic GCC compatibility, we
// return an answer which matches our definition of __VERSION__.
- llvm::outs() << CLANG_VERSION_STRING << "\n";
+ llvm::outs() << DriverVersion << "\n";
return false;
}
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 807b0f938d27b5c..caea8880ba8fb8e 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -21,6 +21,8 @@
! CHECK-NEXT: -ccc-print-phases Dump list of actions to perform
! CHECK-NEXT: -cpp Enable predefined and command line preprocessor macros
! CHECK-NEXT: -c Only run preprocess, compile, and assemble steps
+! CHECK-NEXT: -dumpmachine Display the compiler's target processor
+! CHECK-NEXT: -dumpversion Display the version of the compiler
! CHECK-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
! CHECK-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
! CHECK-NEXT: -E Only run the preprocessor
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 4894f90f5310439..1580c267cfc6ae6 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -17,6 +17,8 @@
! HELP-NEXT: -### Print (but do not run) the commands to run for this compilation
! HELP-NEXT: -cpp Enable predefined and command line preprocessor macros
! HELP-NEXT: -c Only run preprocess, compile, and assemble steps
+! HELP-NEXT: -dumpmachine Display the compiler's target processor
+! HELP-NEXT: -dumpversion Display the version of the compiler
! HELP-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
! HELP-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
! HELP-NEXT: -E Only run the preprocessor
diff --git a/flang/test/Driver/dumpmachine.f90 b/flang/test/Driver/dumpmachine.f90
new file mode 100644
index 000000000000000..b68705707eefa04
--- /dev/null
+++ b/flang/test/Driver/dumpmachine.f90
@@ -0,0 +1,8 @@
+! Test that -dumpmachine prints the target triple.
+
+! Note: Debian GCC may omit "unknown-".
+! RUN: %flang --target=x86_64-linux-gnu -dumpmachine | FileCheck %s --check-prefix=X86_64
+! X86_64: x86_64-unknown-linux-gnu
+
+! RUN: %flang --target=xxx-pc-freebsd -dumpmachine | FileCheck %s --check-prefix=FREEBSD
+! FREEBSD: xxx-pc-freebsd
diff --git a/flang/test/Driver/immediate-options.f90 b/flang/test/Driver/immediate-options.f90
new file mode 100644
index 000000000000000..81c1e7181ba7935
--- /dev/null
+++ b/flang/test/Driver/immediate-options.f90
@@ -0,0 +1,2 @@
+! RUN: %flang -dumpversion | FileCheck %s -check-prefix=DUMPVERSION
+! DUMPVERSION: {{[0-9]+\.[0-9.]+}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/68896
More information about the flang-commits
mailing list