[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 14 14:16:20 PDT 2017


yaxunl created this revision.

There are cases when TargetCodeGenInfo::performAddrSpaceCast is called there is no basic block,
e.g. right after a `return` statement. This causes dangling addrspacecast.

This patch fixes that.


https://reviews.llvm.org/D35438

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenCXX/amdgcn-automatic-variable.cpp


Index: test/CodeGenCXX/amdgcn-automatic-variable.cpp
===================================================================
--- test/CodeGenCXX/amdgcn-automatic-variable.cpp
+++ test/CodeGenCXX/amdgcn-automatic-variable.cpp
@@ -81,4 +81,10 @@
   func1(&x);
 }
 
+// CHECK-LABEL: define void @_Z5func5v
+void func5() {
+  return;
+  int x = 0;
+}
+
 // CHECK-NOT: !opencl.ocl.version
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -432,6 +432,7 @@
   // space, an address space conversion may end up as a bitcast.
   if (auto *C = dyn_cast<llvm::Constant>(Src))
     return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
+  CGF.EnsureInsertPoint();
   return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DestTy);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35438.106706.patch
Type: text/x-patch
Size: 856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170714/8e0677ab/attachment.bin>


More information about the cfe-commits mailing list