[PATCH] [OpenCL] Fix assertion due to blocks
authorYaxun Liu <Yaxun.Liu@amd.com>
Tue, 26 Feb 2019 16:20:41 +0000 (16:20 +0000)
committerGianfranco Costamagna <locutusofborg@debian.org>
Sat, 15 Aug 2020 20:34:33 +0000 (21:34 +0100)
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

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

Gbp-Pq: Name OpenCL-Fix-assertion-due-to-blocks.patch

clang/lib/AST/Expr.cpp
clang/test/CodeGenOpenCL/blocks.cl

index 7cdd3b2c2a30c5fb0e4ee5b2ad8752cd3390b14c..50a65e02bf9edd044bd6f0d41fab3586b02e2247 100644 (file)
@@ -1359,6 +1359,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;
 }
index ab5a2c643c4fc0882b6b3912956708fb55a0dade..c3e26855dfe01ec91c7cbe518c9b3a2441647934 100644 (file)
@@ -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"