summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch')
-rw-r--r--dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch52
1 files changed, 0 insertions, 52 deletions
diff --git a/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch b/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
deleted file mode 100644
index 4f7d3e51..00000000
--- a/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch
+++ /dev/null
@@ -1,52 +0,0 @@
1From 06cf750d2ef892eaa4f0ff5d0a9e9e5c49697264 Mon Sep 17 00:00:00 2001
2From: Raphael Isemann <teemperor@gmail.com>
3Date: Thu, 1 Apr 2021 18:41:44 +0200
4Subject: [PATCH 2/3] 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-120/patches/clang/0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch]
24
25Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
26---
27 clang/lib/CodeGen/BackendUtil.cpp | 8 ++++++++
28 1 file changed, 8 insertions(+)
29
30diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
31index 52bcd971dc8c..f9f891247530 100644
32--- a/clang/lib/CodeGen/BackendUtil.cpp
33+++ b/clang/lib/CodeGen/BackendUtil.cpp
34@@ -850,7 +850,15 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
35 BackendArgs.push_back("-limit-float-precision");
36 BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
37 }
38+ // Check for the default "clang" invocation that won't set any cl::opt values.
39+ // Skip trying to parse the command line invocation to avoid the issues
40+ // described below.
41+ if (BackendArgs.size() == 1)
42+ return;
43 BackendArgs.push_back(nullptr);
44+ // FIXME: The command line parser below is not thread-safe and shares a global
45+ // state, so this call might crash or overwrite the options of another Clang
46+ // instance in the same process.
47 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
48 BackendArgs.data());
49 }
50--
512.17.1
52