diff options
author | Hussain Kadhem <hmk@berkeley.edu> | 2023-06-01 12:31:51 -0400 |
---|---|---|
committer | Hussain Kadhem <hmk@berkeley.edu> | 2023-06-01 12:35:16 -0400 |
commit | 541f5c4a6db35870091dd15dfa09dde751229a17 (patch) | |
tree | 573564dd1a43db4ae3e42666ff5e13eb15011d39 /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 2129cc1b3a14df5c24e5b2a680f18b88d5af4142 (diff) | |
download | llvm-541f5c4a6db35870091dd15dfa09dde751229a17.zip llvm-541f5c4a6db35870091dd15dfa09dde751229a17.tar.gz llvm-541f5c4a6db35870091dd15dfa09dde751229a17.tar.bz2 |
Flang implementation for COMPILER_VERSION and COMPILER_OPTIONS intrinsics
This revision implements the Fortran intrinsic procedures COMPILER_VERSION and COMPILER_OPTIONS from the iso_fortran_env module.
To be able to set the COMPILER_OPTIONS string according to the original compiler driver invocation, a string is passed to the frontend driver using the environment variable FLANG_COMPILER_OPTIONS_STRING, for lack of a better mechanism.
Fixes #59233
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D140524
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 1264907..98a8714 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -12,6 +12,7 @@ #include "flang/Frontend/CompilerInvocation.h" #include "flang/Common/Fortran-features.h" +#include "flang/Common/Version.h" #include "flang/Frontend/CodeGenOptions.h" #include "flang/Frontend/PreprocessorOptions.h" #include "flang/Frontend/TargetOptions.h" @@ -36,6 +37,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/Triple.h" +#include <cstdlib> #include <memory> #include <optional> @@ -869,7 +871,7 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc, bool CompilerInvocation::createFromArgs( CompilerInvocation &res, llvm::ArrayRef<const char *> commandLineArgs, - clang::DiagnosticsEngine &diags) { + clang::DiagnosticsEngine &diags, const char *argv0) { bool success = true; @@ -929,6 +931,23 @@ bool CompilerInvocation::createFromArgs( success &= parseFloatingPointArgs(res, args, diags); + // Set the string to be used as the return value of the COMPILER_OPTIONS + // intrinsic of iso_fortran_env. This is either passed in from the parent + // compiler driver invocation with an environment variable, or failing that + // set to the command line arguments of the frontend driver invocation. + res.allCompilerInvocOpts = std::string(); + llvm::raw_string_ostream os(res.allCompilerInvocOpts); + char *compilerOptsEnv = std::getenv("FLANG_COMPILER_OPTIONS_STRING"); + if (compilerOptsEnv != nullptr) { + os << compilerOptsEnv; + } else { + os << argv0 << ' '; + for (auto it = commandLineArgs.begin(), e = commandLineArgs.end(); it != e; + ++it) { + os << ' ' << *it; + } + } + return success; } @@ -1078,6 +1097,11 @@ void CompilerInvocation::setSemanticsOpts( semanticsContext->targetCharacteristics().DisableType( Fortran::common::TypeCategory::Real, /*kind=*/10); } + + std::string version = Fortran::common::getFlangFullVersion(); + semanticsContext->targetCharacteristics() + .set_compilerOptionsString(allCompilerInvocOpts) + .set_compilerVersionString(version); } /// Set \p loweringOptions controlling lowering behavior based |