diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2017-09-27 14:37:00 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2017-09-27 14:37:00 +0000 |
commit | ea39f03c83a0842bcbc103c21223bb7885455eae (patch) | |
tree | 1920098658107f4fc8053c405c225e003ef63fec /lib/CodeGen | |
parent | cf6309caa0488734daee4edd2623edc2dd94a42a (diff) | |
download | clang-ea39f03c83a0842bcbc103c21223bb7885455eae.tar.gz |
[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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGBuilder.h | 7 | ||||
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 7 |
2 files changed, 12 insertions, 2 deletions
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<PointerType>()) { 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; |