r340191 - [OPENMP] Fix crash on the emission of the weak function declaration.

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 21 15:40:37 PDT 2018


Merged to 7.0 in r340351.

On Mon, Aug 20, 2018 at 11:03 AM, Alexey Bataev via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: abataev
> Date: Mon Aug 20 11:03:40 2018
> New Revision: 340191
>
> URL: http://llvm.org/viewvc/llvm-project?rev=340191&view=rev
> Log:
> [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.
>
> Modified:
>     cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>     cfe/trunk/test/OpenMP/declare_target_codegen.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=340191&r1=340190&r2=340191&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Aug 20 11:03:40 2018
> @@ -2558,15 +2558,17 @@ llvm::Constant *CodeGenModule::GetOrCrea
>      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()) {
>
> 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=340191&r1=340190&r2=340191&view=diff
> ==============================================================================
> --- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
> +++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Mon Aug 20 11:03:40 2018
> @@ -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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list