aboutsummaryrefslogtreecommitdiff
path: root/flang/tools
diff options
context:
space:
mode:
authorHussain Kadhem <hmk@berkeley.edu>2023-06-01 12:31:51 -0400
committerHussain Kadhem <hmk@berkeley.edu>2023-06-01 12:35:16 -0400
commit541f5c4a6db35870091dd15dfa09dde751229a17 (patch)
tree573564dd1a43db4ae3e42666ff5e13eb15011d39 /flang/tools
parent2129cc1b3a14df5c24e5b2a680f18b88d5af4142 (diff)
downloadllvm-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/tools')
-rw-r--r--flang/tools/flang-driver/driver.cpp24
-rw-r--r--flang/tools/flang-driver/fc1_main.cpp4
2 files changed, 26 insertions, 2 deletions
diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index a4c57f8..d8c597a 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -28,7 +28,9 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
+#include <stdlib.h>
using llvm::StringRef;
@@ -135,6 +137,28 @@ int main(int argc, const char **argv) {
llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4>
failingCommands;
+ // Set the environment variable, FLANG_COMPILER_OPTIONS_STRING, to contain all
+ // the compiler options. This is intended for the frontend driver,
+ // flang-new -fc1, to enable the implementation of the COMPILER_OPTIONS
+ // intrinsic. To this end, the frontend driver requires the list of the
+ // original compiler options, which is not available through other means.
+ // TODO: This way of passing information between the compiler and frontend
+ // drivers is discouraged. We should find a better way not involving env
+ // variables.
+ std::string compilerOptsGathered;
+ llvm::raw_string_ostream os(compilerOptsGathered);
+ for (int i = 0; i < argc; ++i) {
+ os << argv[i];
+ if (i < argc - 1) {
+ os << ' ';
+ }
+ }
+#ifdef _WIN32
+ _putenv_s("FLANG_COMPILER_OPTIONS_STRING", compilerOptsGathered.c_str());
+#else
+ setenv("FLANG_COMPILER_OPTIONS_STRING", compilerOptsGathered.c_str(), 1);
+#endif
+
// Run the driver
int res = 1;
bool isCrash = false;
diff --git a/flang/tools/flang-driver/fc1_main.cpp b/flang/tools/flang-driver/fc1_main.cpp
index d9c9881..b5b062a 100644
--- a/flang/tools/flang-driver/fc1_main.cpp
+++ b/flang/tools/flang-driver/fc1_main.cpp
@@ -50,8 +50,8 @@ int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
new clang::DiagnosticOptions();
clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagsBuffer);
- bool success =
- CompilerInvocation::createFromArgs(flang->getInvocation(), argv, diags);
+ bool success = CompilerInvocation::createFromArgs(flang->getInvocation(),
+ argv, diags, argv0);
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();