Skip to content

Commit 5ac1e20

Browse files
authored
Merge pull request #2937 from Teemperor/cherry/60854c328d8729b2ef10b9bb4dcbcc282f43c5e7
Avoid calling ParseCommandLineOptions in BackendUtil if possible
2 parents 3153a10 + 585384a commit 5ac1e20

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,15 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
860860
BackendArgs.push_back("-limit-float-precision");
861861
BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
862862
}
863+
// Check for the default "clang" invocation that won't set any cl::opt values.
864+
// Skip trying to parse the command line invocation to avoid the issues
865+
// described below.
866+
if (BackendArgs.size() == 1)
867+
return;
863868
BackendArgs.push_back(nullptr);
869+
// FIXME: The command line parser below is not thread-safe and shares a global
870+
// state, so this call might crash or overwrite the options of another Clang
871+
// instance in the same process.
864872
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
865873
BackendArgs.data());
866874
}

0 commit comments

Comments
 (0)