0003-OpenCL-Fix-assertion-due-to-blocks.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 94a65066cccbe50358dca0a9da7712cf5294912a Mon Sep 17 00:00:00 2001
  2. From: Yaxun Liu <Yaxun.Liu@amd.com>
  3. Date: Tue, 26 Feb 2019 16:20:41 +0000
  4. Subject: [PATCH 3/3] [OpenCL] Fix assertion due to blocks
  5. A recent change caused assertion in CodeGenFunction::EmitBlockCallExpr when a block is called.
  6. There is code
  7. Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
  8. getCalleeDecl calls Expr::getReferencedDeclOfCallee, which does not handle
  9. BlockExpr and returns nullptr, which causes isa to assert.
  10. This patch fixes that.
  11. Differential Revision: https://reviews.llvm.org/D58658
  12. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354893 91177308-0d34-0410-b5e6-96231b3b80d8
  13. ---
  14. lib/AST/Expr.cpp | 2 ++
  15. test/CodeGenOpenCL/blocks.cl | 6 ++++++
  16. 2 files changed, 8 insertions(+)
  17. diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
  18. index 7cdd3b2c2a..50a65e02bf 100644
  19. --- a/lib/AST/Expr.cpp
  20. +++ b/lib/AST/Expr.cpp
  21. @@ -1359,6 +1359,8 @@ Decl *Expr::getReferencedDeclOfCallee() {
  22. return DRE->getDecl();
  23. if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
  24. return ME->getMemberDecl();
  25. + if (auto *BE = dyn_cast<BlockExpr>(CEE))
  26. + return BE->getBlockDecl();
  27. return nullptr;
  28. }
  29. diff --git a/test/CodeGenOpenCL/blocks.cl b/test/CodeGenOpenCL/blocks.cl
  30. index ab5a2c643c..c3e26855df 100644
  31. --- a/test/CodeGenOpenCL/blocks.cl
  32. +++ b/test/CodeGenOpenCL/blocks.cl
  33. @@ -90,6 +90,12 @@ int get42() {
  34. return blockArgFunc(^{return 42;});
  35. }
  36. +// COMMON-LABEL: define {{.*}}@call_block
  37. +// call {{.*}}@__call_block_block_invoke
  38. +int call_block() {
  39. + return ^int(int num) { return num; } (11);
  40. +}
  41. +
  42. // CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
  43. // CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
  44. --
  45. 2.21.0