[OPENMP] Do not crash on codegen for CXX member functions.
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 30 Apr 2018 18:09:40 +0000 (18:09 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 30 Apr 2018 18:09:40 +0000 (18:09 +0000)
Non-static member functions should not be emitted as a standalone
functions, this leads to compiler crash.

llvm-svn: 331206

clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_target_codegen.cpp

index 33dfe71..0500f23 100644 (file)
@@ -898,6 +898,9 @@ static void EmitOMPAggregateInit(CodeGenFunction &CGF, Address DestAddr,
 
 static llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
 isDeclareTargetDeclaration(const ValueDecl *VD) {
+  if (const auto *MD = dyn_cast<CXXMethodDecl>(VD))
+    if (!MD->isStatic())
+      return llvm::None;
   for (const Decl *D : VD->redecls()) {
     if (!D->hasAttrs())
       continue;
index 86c0c02..a5a51bc 100644 (file)
@@ -32,6 +32,11 @@ int baz2();
 int baz4() { return 5; }
 
 #pragma omp declare target
+struct S {
+  int a;
+  S(int a) : a(a) {}
+};
+
 int foo() { return 0; }
 int b = 15;
 int d;
@@ -47,6 +52,7 @@ int maini1() {
 #pragma omp target map(tofrom \
                        : a, b)
   {
+    S s(a);
     static long aaa = 23;
     a = foo() + bar() + b + c + d + aa + aaa;
   }