[flang-commits] [flang] [flang] Pass Argv0 to getIntriniscDir and getOpenMPHeadersDir (PR #73254)
via flang-commits
flang-commits at lists.llvm.org
Mon Dec 4 09:56:25 PST 2023
https://github.com/madanial0 updated https://github.com/llvm/llvm-project/pull/73254
>From 8af3ddd14666343a411853fae07d28edb8fd8a6f Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Tue, 21 Nov 2023 12:18:40 -0500
Subject: [PATCH 1/2] Pass the correct path to getIntriniscDir and
getOpenMPHeadersDir
---
.../include/flang/Frontend/CompilerInvocation.h | 6 ++++++
flang/lib/Frontend/CompilerInvocation.cpp | 16 ++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 7ce072cd1ec09..aec29ce94d3f4 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -98,6 +98,8 @@ class CompilerInvocation : public CompilerInvocationBase {
bool warnAsErr = false;
+ const char *argv0;
+
/// This flag controls the unparsing and is used to decide whether to print
/// out the semantically analyzed version of an object or expression or the
/// plain version that does not include any information from semantic
@@ -184,6 +186,8 @@ class CompilerInvocation : public CompilerInvocationBase {
return enableConformanceChecks;
}
+ const char *getArgv0() { return argv0; }
+
bool &getEnableUsageChecks() { return enableUsageChecks; }
const bool &getEnableUsageChecks() const { return enableUsageChecks; }
@@ -217,6 +221,8 @@ class CompilerInvocation : public CompilerInvocationBase {
void setEnableUsageChecks() { enableUsageChecks = true; }
/// Useful setters
+ void setArgv0(const char *dir) { argv0 = dir; }
+
void setModuleDir(std::string &dir) { moduleDir = dir; }
void setModuleFileSuffix(const char *suffix) {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ec04727fb2641..62b6c38768773 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -700,19 +700,19 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
}
// Generate the path to look for intrinsic modules
-static std::string getIntrinsicDir() {
+static std::string getIntrinsicDir(const char *argv) {
// TODO: Find a system independent API
llvm::SmallString<128> driverPath;
- driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
+ driverPath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
llvm::sys::path::remove_filename(driverPath);
driverPath.append("/../include/flang/");
return std::string(driverPath);
}
// Generate the path to look for OpenMP headers
-static std::string getOpenMPHeadersDir() {
+static std::string getOpenMPHeadersDir(const char *argv) {
llvm::SmallString<128> includePath;
- includePath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
+ includePath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
llvm::sys::path::remove_filename(includePath);
includePath.append("/../include/flang/OpenMP/");
return std::string(includePath);
@@ -1216,6 +1216,8 @@ bool CompilerInvocation::createFromArgs(
}
}
+ res.setArgv0(argv0);
+
return success;
}
@@ -1258,7 +1260,8 @@ void CompilerInvocation::setDefaultFortranOpts() {
// Add the location of omp_lib.h to the search directories. Currently this is
// identical to the modules' directory.
- fortranOptions.searchDirectories.emplace_back(getOpenMPHeadersDir());
+ fortranOptions.searchDirectories.emplace_back(
+ getOpenMPHeadersDir(getArgv0()));
fortranOptions.isFixedForm = false;
}
@@ -1323,7 +1326,8 @@ void CompilerInvocation::setFortranOpts() {
preprocessorOptions.searchDirectoriesFromIntrModPath.end());
// Add the default intrinsic module directory
- fortranOptions.intrinsicModuleDirectories.emplace_back(getIntrinsicDir());
+ fortranOptions.intrinsicModuleDirectories.emplace_back(
+ getIntrinsicDir(getArgv0()));
// Add the directory supplied through -J/-module-dir to the list of search
// directories
>From ace7dc1cebe09ff8183d9c92165222a7e4dceb92 Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Mon, 4 Dec 2023 12:54:00 -0500
Subject: [PATCH 2/2] Adding executable name as a comment
---
flang/include/flang/Frontend/CompilerInvocation.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index aec29ce94d3f4..6324bcdc1863c 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -98,6 +98,7 @@ class CompilerInvocation : public CompilerInvocationBase {
bool warnAsErr = false;
+ // Executable name
const char *argv0;
/// This flag controls the unparsing and is used to decide whether to print
More information about the flang-commits
mailing list