diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-08-21 22:39:17 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-08-21 22:39:17 +0000 |
commit | d86f02265fac1d8baf8b0c3f3c152c64a1900cb9 (patch) | |
tree | 2769cfcb327eb162e0164fefddcf31cfca26cb37 | |
parent | a0ca9e9cff065e39a12c5434fa8ce04d9be44318 (diff) |
Merging r340191:
------------------------------------------------------------------------
r340191 | abataev | 2018-08-20 20:03:40 +0200 (Mon, 20 Aug 2018) | 6 lines
[OPENMP] Fix crash on the emission of the weak function declaration.
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/branches/release_70@340351 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 20 | ||||
-rw-r--r-- | test/OpenMP/declare_target_codegen.cpp | 14 |
2 files changed, 25 insertions, 9 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 8c5e0df096..155ee6c6af 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2539,15 +2539,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()) { diff --git a/test/OpenMP/declare_target_codegen.cpp b/test/OpenMP/declare_target_codegen.cpp index 96bdc874ec..abd108a6e7 100644 --- a/test/OpenMP/declare_target_codegen.cpp +++ b/test/OpenMP/declare_target_codegen.cpp @@ -91,5 +91,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 |