]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix crash on the emission of the weak function declaration.
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 20 Aug 2018 18:03:40 +0000 (18:03 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 20 Aug 2018 18:03:40 +0000 (18:03 +0000)
If the function is actually a weak reference, it should not be marked as
deferred definition as this is only a declaration. Patch adds checks for
the definitions if they must be emitted. Otherwise, only declaration is
emitted.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340191 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/OpenMP/declare_target_codegen.cpp

index 76527b78c340df88b9f156f729b66f2afeec5a26..aaaf6c6d754cabc26b6c073d535c9726f652016d 100644 (file)
@@ -2558,15 +2558,17 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
     if (getLangOpts().OpenMPIsDevice && OpenMPRuntime &&
         !OpenMPRuntime->markAsGlobalTarget(GD) && FD->isDefined() &&
         !DontDefer && !IsForDefinition) {
-      const FunctionDecl *FDDef = FD->getDefinition();
-      GlobalDecl GDDef;
-      if (const auto *CD = dyn_cast<CXXConstructorDecl>(FDDef))
-        GDDef = GlobalDecl(CD, GD.getCtorType());
-      else if (const auto *DD = dyn_cast<CXXDestructorDecl>(FDDef))
-        GDDef = GlobalDecl(DD, GD.getDtorType());
-      else
-        GDDef = GlobalDecl(FDDef);
-      addDeferredDeclToEmit(GDDef);
+      if (const FunctionDecl *FDDef = FD->getDefinition())
+        if (getContext().DeclMustBeEmitted(FDDef)) {
+          GlobalDecl GDDef;
+          if (const auto *CD = dyn_cast<CXXConstructorDecl>(FDDef))
+            GDDef = GlobalDecl(CD, GD.getCtorType());
+          else if (const auto *DD = dyn_cast<CXXDestructorDecl>(FDDef))
+            GDDef = GlobalDecl(DD, GD.getDtorType());
+          else
+            GDDef = GlobalDecl(FDDef);
+          addDeferredDeclToEmit(GDDef);
+        }
     }
 
     if (FD->isMultiVersion()) {
index f4ef4225526e919194359ba629c1050563377d87..0cd611b06f9f63478f0d8504537e64e82bf379b1 100644 (file)
@@ -128,5 +128,19 @@ int baz2() {
   return 2 + baz3();
 }
 
+extern int create() throw();
+
+static __typeof(create) __t_create __attribute__((__weakref__("__create")));
+
+int baz5() {
+  bool a;
+// CHECK-DAG: define weak void @__omp_offloading_{{.*}}baz5{{.*}}_l[[@LINE+1]](i64 {{.*}})
+#pragma omp target
+  a = __extension__(void *) & __t_create != 0;
+  return a;
+}
+
+// CHECK-DAG: declare extern_weak signext i32 @__create()
+
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
 #endif // HEADER