summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch')
-rw-r--r--dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch53
1 files changed, 53 insertions, 0 deletions
diff --git a/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch b/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
new file mode 100644
index 00000000..0b4ee8c7
--- /dev/null
+++ b/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-0006-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
@@ -0,0 +1,53 @@
1From 2c53abd0008bbecfcfe871c6060f4bbf1c94c74a Mon Sep 17 00:00:00 2001
2From: Raphael Isemann <teemperor@gmail.com>
3Date: Thu, 1 Apr 2021 18:41:44 +0200
4Subject: [PATCH 6/7] Avoid calling ParseCommandLineOptions in BackendUtil if
5 possible
6
7Calling `ParseCommandLineOptions` should only be called from `main` as the
8CommandLine setup code isn't thread-safe. As BackendUtil is part of the
9generic Clang FrontendAction logic, a process which has several threads executing
10Clang FrontendActions will randomly crash in the unsafe setup code.
11
12This patch avoids calling the function unless either the debug-pass option or
13limit-float-precision option is set. Without these two options set the
14`ParseCommandLineOptions` call doesn't do anything beside parsing
15the command line `clang` which doesn't set any options.
16
17See also D99652 where LLDB received a workaround for this crash.
18
19Reviewed By: JDevlieghere
20
21Differential Revision: https://reviews.llvm.org/D99740
22
23Upstream-Status: Backport [Taken from opencl-clang patches; https://github.com/intel/opencl-clang/blob/ocl-open-100/patches/clang/0004-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch]
24
25Signed-off-by: Raphael Isemann <teemperor@gmail.com>
26Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
27---
28 clang/lib/CodeGen/BackendUtil.cpp | 8 ++++++++
29 1 file changed, 8 insertions(+)
30
31diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
32index 0bfcab88a3a9..db8fd4166d7a 100644
33--- a/clang/lib/CodeGen/BackendUtil.cpp
34+++ b/clang/lib/CodeGen/BackendUtil.cpp
35@@ -743,7 +743,15 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
36 BackendArgs.push_back("-limit-float-precision");
37 BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
38 }
39+ // Check for the default "clang" invocation that won't set any cl::opt values.
40+ // Skip trying to parse the command line invocation to avoid the issues
41+ // described below.
42+ if (BackendArgs.size() == 1)
43+ return;
44 BackendArgs.push_back(nullptr);
45+ // FIXME: The command line parser below is not thread-safe and shares a global
46+ // state, so this call might crash or overwrite the options of another Clang
47+ // instance in the same process.
48 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
49 BackendArgs.data());
50 }
51--
522.17.1
53