Skip to content

Commit 8dc474c

Browse files
madanial0Mark Danial
andauthored
[flang] Pass Argv0 to getIntriniscDir and getOpenMPHeadersDir (#73254)
The `llvm::sys::fs::getMainExecutable(nullptr, nullptr)` is not able to obtain the correct executable path on AIX without Argv0 due to the lack of a current process on AIX's `proc` filesystem. This causes a build failure on AIX as intrinsic module directory is missing. --------- Co-authored-by: Mark Danial <[email protected]>
1 parent 0d59cfc commit 8dc474c

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class CompilerInvocation : public CompilerInvocationBase {
9898

9999
bool warnAsErr = false;
100100

101+
// Executable name
102+
const char *argv0;
103+
101104
/// This flag controls the unparsing and is used to decide whether to print
102105
/// out the semantically analyzed version of an object or expression or the
103106
/// plain version that does not include any information from semantic
@@ -184,6 +187,8 @@ class CompilerInvocation : public CompilerInvocationBase {
184187
return enableConformanceChecks;
185188
}
186189

190+
const char *getArgv0() { return argv0; }
191+
187192
bool &getEnableUsageChecks() { return enableUsageChecks; }
188193
const bool &getEnableUsageChecks() const { return enableUsageChecks; }
189194

@@ -217,6 +222,8 @@ class CompilerInvocation : public CompilerInvocationBase {
217222
void setEnableUsageChecks() { enableUsageChecks = true; }
218223

219224
/// Useful setters
225+
void setArgv0(const char *dir) { argv0 = dir; }
226+
220227
void setModuleDir(std::string &dir) { moduleDir = dir; }
221228

222229
void setModuleFileSuffix(const char *suffix) {

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,19 +700,19 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
700700
}
701701

702702
// Generate the path to look for intrinsic modules
703-
static std::string getIntrinsicDir() {
703+
static std::string getIntrinsicDir(const char *argv) {
704704
// TODO: Find a system independent API
705705
llvm::SmallString<128> driverPath;
706-
driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
706+
driverPath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
707707
llvm::sys::path::remove_filename(driverPath);
708708
driverPath.append("/../include/flang/");
709709
return std::string(driverPath);
710710
}
711711

712712
// Generate the path to look for OpenMP headers
713-
static std::string getOpenMPHeadersDir() {
713+
static std::string getOpenMPHeadersDir(const char *argv) {
714714
llvm::SmallString<128> includePath;
715-
includePath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
715+
includePath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
716716
llvm::sys::path::remove_filename(includePath);
717717
includePath.append("/../include/flang/OpenMP/");
718718
return std::string(includePath);
@@ -1216,6 +1216,8 @@ bool CompilerInvocation::createFromArgs(
12161216
}
12171217
}
12181218

1219+
res.setArgv0(argv0);
1220+
12191221
return success;
12201222
}
12211223

@@ -1258,7 +1260,8 @@ void CompilerInvocation::setDefaultFortranOpts() {
12581260

12591261
// Add the location of omp_lib.h to the search directories. Currently this is
12601262
// identical to the modules' directory.
1261-
fortranOptions.searchDirectories.emplace_back(getOpenMPHeadersDir());
1263+
fortranOptions.searchDirectories.emplace_back(
1264+
getOpenMPHeadersDir(getArgv0()));
12621265

12631266
fortranOptions.isFixedForm = false;
12641267
}
@@ -1323,7 +1326,8 @@ void CompilerInvocation::setFortranOpts() {
13231326
preprocessorOptions.searchDirectoriesFromIntrModPath.end());
13241327

13251328
// Add the default intrinsic module directory
1326-
fortranOptions.intrinsicModuleDirectories.emplace_back(getIntrinsicDir());
1329+
fortranOptions.intrinsicModuleDirectories.emplace_back(
1330+
getIntrinsicDir(getArgv0()));
13271331

13281332
// Add the directory supplied through -J/-module-dir to the list of search
13291333
// directories

0 commit comments

Comments
 (0)