r354893 - [OpenCL] Fix assertion due to blocks

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 26 08:20:41 PST 2019


Author: yaxunl
Date: Tue Feb 26 08:20:41 2019
New Revision: 354893

URL: http://llvm.org/viewvc/llvm-project?rev=354893&view=rev
Log:
[OpenCL] Fix assertion due to blocks

A recent change caused assertion in CodeGenFunction::EmitBlockCallExpr when a block is called.

There is code

  Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
getCalleeDecl calls Expr::getReferencedDeclOfCallee, which does not handle
BlockExpr and returns nullptr, which causes isa to assert.

This patch fixes that.

Differential Revision: https://reviews.llvm.org/D58658

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/CodeGenOpenCL/blocks.cl

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=354893&r1=354892&r2=354893&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Feb 26 08:20:41 2019
@@ -1358,6 +1358,8 @@ Decl *Expr::getReferencedDeclOfCallee()
     return DRE->getDecl();
   if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
     return ME->getMemberDecl();
+  if (auto *BE = dyn_cast<BlockExpr>(CEE))
+    return BE->getBlockDecl();
 
   return nullptr;
 }

Modified: cfe/trunk/test/CodeGenOpenCL/blocks.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/blocks.cl?rev=354893&r1=354892&r2=354893&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/blocks.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/blocks.cl Tue Feb 26 08:20:41 2019
@@ -90,6 +90,12 @@ int get42() {
   return blockArgFunc(^{return 42;});
 }
 
+// COMMON-LABEL: define {{.*}}@call_block
+// call {{.*}}@__call_block_block_invoke
+int call_block() {
+  return ^int(int num) { return num; } (11);
+}
+
 // CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
 // CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
 




More information about the cfe-commits mailing list