From 6a628fa0b507eefd3ed1608b39f4702ea56d1093 Mon Sep 17 00:00:00 2001 From: Naveen Saini Date: Fri, 20 Aug 2021 09:45:25 +0800 Subject: llvm/12.0.0: apply opencl-clang recommend patches https://github.com/intel/opencl-clang/tree/ocl-open-120/patches Signed-off-by: Naveen Saini Signed-off-by: Anuj Mittal --- ...ng-ParseCommandLineOptions-in-BackendUtil.patch | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch (limited to 'dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch') 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 new file mode 100644 index 00000000..4f7d3e51 --- /dev/null +++ b/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm12-0002-Avoid-calling-ParseCommandLineOptions-in-BackendUtil.patch @@ -0,0 +1,52 @@ +From 06cf750d2ef892eaa4f0ff5d0a9e9e5c49697264 Mon Sep 17 00:00:00 2001 +From: Raphael Isemann +Date: Thu, 1 Apr 2021 18:41:44 +0200 +Subject: [PATCH 2/3] 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 + +Upstream-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] + +Signed-off-by: Naveen Saini +--- + clang/lib/CodeGen/BackendUtil.cpp | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp +index 52bcd971dc8c..f9f891247530 100644 +--- a/clang/lib/CodeGen/BackendUtil.cpp ++++ b/clang/lib/CodeGen/BackendUtil.cpp +@@ -850,7 +850,15 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) { + BackendArgs.push_back("-limit-float-precision"); + BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str()); + } ++ // Check for the default "clang" invocation that won't set any cl::opt values. ++ // Skip trying to parse the command line invocation to avoid the issues ++ // described below. ++ if (BackendArgs.size() == 1) ++ return; + BackendArgs.push_back(nullptr); ++ // FIXME: The command line parser below is not thread-safe and shares a global ++ // state, so this call might crash or overwrite the options of another Clang ++ // instance in the same process. + llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1, + BackendArgs.data()); + } +-- +2.17.1 + -- cgit v1.2.3-54-g00ecf