Avoid calling ParseCommandLineOptions in BackendUtil if possible
authorRaphael Isemann <teemperor@gmail.com>
Thu, 1 Apr 2021 16:41:44 +0000 (18:41 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 1 Apr 2021 17:41:16 +0000 (19:41 +0200)
commit60854c328d8729b2ef10b9bb4dcbcc282f43c5e7
treeb9997ad5c6a571fb95323c819ddf8869bfde6535
parent232d3a3e4755057b51cec1c4c5eaa7ecdec9e70a
Avoid calling ParseCommandLineOptions in BackendUtil if possible

Calling `ParseCommandLineOptions` should only be called from `main` as the
CommandLine setup code isn't thread-safe. As BackendUtil is part of the
generic Clang FrontendAction logic, a process which has several threads executing
Clang FrontendActions will randomly crash in the unsafe setup code.

This patch avoids calling the function unless either the debug-pass option or
limit-float-precision option is set. Without these two options set the
`ParseCommandLineOptions` call doesn't do anything beside parsing
the command line `clang` which doesn't set any options.

See also D99652 where LLDB received a workaround for this crash.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D99740
clang/lib/CodeGen/BackendUtil.cpp