r331206 - [OPENMP] Do not crash on codegen for CXX member functions.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 30 11:09:40 PDT 2018


Author: abataev
Date: Mon Apr 30 11:09:40 2018
New Revision: 331206

URL: http://llvm.org/viewvc/llvm-project?rev=331206&view=rev
Log:
[OPENMP] Do not crash on codegen for CXX member functions.

Non-static member functions should not be emitted as a standalone
functions, this leads to compiler crash.

Modified:
    cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
    cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331206&r1=331205&r2=331206&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Apr 30 11:09:40 2018
@@ -898,6 +898,9 @@ static void EmitOMPAggregateInit(CodeGen
 
 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;

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=331206&r1=331205&r2=331206&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Mon Apr 30 11:09:40 2018
@@ -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;
   }




More information about the cfe-commits mailing list