[Beignet] [PATCH] Backend: Fix mutlithread coredump for LLVM3.7+

Pan Xiuli xiuli.pan at intel.com
Thu Jan 28 19:23:36 PST 2016


As llvm has refined the ParseCommandLineOptions, we need to follow
the change as LLVM to avoid leak.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 backend/src/backend/program.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 0bbcb77..f6e56f6 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -625,14 +625,23 @@ namespace gbe {
     //llvm flags need command line parsing to take effect
     if (!Clang.getFrontendOpts().LLVMArgs.empty()) {
       unsigned NumArgs = Clang.getFrontendOpts().LLVMArgs.size();
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
+      auto Args = llvm::make_unique<const char*[]>(NumArgs + 2);
+#else
       const char **Args = new const char*[NumArgs + 2];
+#endif
       Args[0] = "clang (LLVM option parsing)";
       for (unsigned i = 0; i != NumArgs; ++i){
         Args[i + 1] = Clang.getFrontendOpts().LLVMArgs[i].c_str();
       }
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
+      Args[NumArgs + 1] = nullptr;
+      llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
+#else
       Args[NumArgs + 1] = 0;
       llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args);
       delete [] Args;
+#endif
     }
   
     // Create an action and make the compiler instance carry it out
-- 
2.1.4



More information about the Beignet mailing list