From ea39f03c83a0842bcbc103c21223bb7885455eae Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Wed, 27 Sep 2017 14:37:00 +0000 Subject: [OpenCL] Handle address space conversion while setting type alignment. Added missing addrspacecast case in alignment computation logic of pointer type emission in IR generation. Differential Revision: https://reviews.llvm.org/D37804 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314304 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBuilder.h | 7 +++++++ lib/CodeGen/CGExpr.cpp | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/CGBuilder.h b/lib/CodeGen/CGBuilder.h index 42f9a428bb..61fe4aac3a 100644 --- a/lib/CodeGen/CGBuilder.h +++ b/lib/CodeGen/CGBuilder.h @@ -145,6 +145,13 @@ public: Addr.getAlignment()); } + using CGBuilderBaseTy::CreateAddrSpaceCast; + Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, + const llvm::Twine &Name = "") { + return Address(CreateAddrSpaceCast(Addr.getPointer(), Ty, Name), + Addr.getAlignment()); + } + /// Cast the element type of the given address to a different type, /// preserving information like the alignment and address space. Address CreateElementBitCast(Address Addr, llvm::Type *Ty, diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index cf3dc49ef2..4659d1b520 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -925,6 +925,7 @@ Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E, // Non-converting casts (but not C's implicit conversion from void*). case CK_BitCast: case CK_NoOp: + case CK_AddressSpaceConversion: if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) { if (PtrTy->getPointeeType()->isVoidType()) break; @@ -953,8 +954,10 @@ Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E, CodeGenFunction::CFITCK_UnrelatedCast, CE->getLocStart()); } - - return Builder.CreateBitCast(Addr, ConvertType(E->getType())); + return CE->getCastKind() != CK_AddressSpaceConversion + ? Builder.CreateBitCast(Addr, ConvertType(E->getType())) + : Builder.CreateAddrSpaceCast(Addr, + ConvertType(E->getType())); } break; -- cgit v1.2.1