mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Refactor the call to llvm::sys::fs::getMainExecutable
.
Taking the address of `main` is UB in C++. Reading LLVM's source, any function address can be used (that's what clang does too).
This commit is contained in:
parent
246c0c359c
commit
c3fe8f3fdd
4 changed files with 12 additions and 5 deletions
|
@ -19,9 +19,15 @@ namespace {
|
|||
string exePath;
|
||||
}
|
||||
|
||||
void exe_path::initialize(const char *arg0, void *mainAddress) {
|
||||
void exe_path::initialize(const char *arg0) {
|
||||
assert(exePath.empty());
|
||||
exePath = llvm::sys::fs::getMainExecutable(arg0, mainAddress);
|
||||
|
||||
// Some platforms can't implement LLVM's getMainExecutable
|
||||
// without being given the address of a function in the main executable.
|
||||
// Thus getMainExecutable needs the address of a function;
|
||||
// any function address in the main executable will do.
|
||||
exePath = llvm::sys::fs::getMainExecutable(
|
||||
arg0, reinterpret_cast<void *>(&exe_path::initialize));
|
||||
}
|
||||
|
||||
const string &exe_path::getExePath() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue