diff --git a/wrappers/llvm-wrapper.c b/wrappers/llvm-wrapper.c index de7918a..064de57 100644 --- a/wrappers/llvm-wrapper.c +++ b/wrappers/llvm-wrapper.c @@ -21,8 +21,11 @@ int _tmain(int argc, TCHAR* argv[]) { const TCHAR *dir; const TCHAR *exe; - split_argv(argv[0], &dir, NULL, NULL, &exe); - TCHAR *exe_path = concat(dir, concat(_T("llvm-"), exe)); + const TCHAR *basename, *target; + split_argv(argv[0], &dir, &basename, &target, &exe); + if (_tcsncmp(exe, _T("llvm-"), 5)) + exe = concat(_T("llvm-"), exe); + TCHAR *exe_path = concat(dir, exe); return run_final(exe_path, (const TCHAR *const *) argv); } diff --git a/wrappers/native-wrapper.h b/wrappers/native-wrapper.h index 7b0c16f..0af9519 100644 --- a/wrappers/native-wrapper.h +++ b/wrappers/native-wrapper.h @@ -154,6 +154,21 @@ static inline void split_argv(const TCHAR *argv0, const TCHAR **dir_ptr, const T if (dash) { *dash = '\0'; exe = dash + 1; + // Handle [-]llvm- as exe=llvm- + TCHAR *dash2 = _tcsrchr(target, '-'); + if (dash2 && !_tcscmp(dash2, _T("-llvm"))) { + // Found -llvm-; move the llvm- prefix to + // exe. Convert the original dash which we overwrite with '\0' + // back into a dash and split the string at the preceding dash. + *dash = '-'; + *dash2 = '\0'; + exe = dash2 + 1; + } else if (!_tcscmp(target, _T("llvm"))) { + // Found llvm-; don't treat "llvm" as target but move + // it to the exe part. + exe = basename; + target = NULL; + } } else { target = NULL; }