From: Andrew Savonichev Date: Wed, 12 Dec 2018 09:51:23 +0000 (+0000) Subject: [OpenCL] Fix for TBAA information of pointer after addresspacecast X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8e1f22522af0fa8a6e20b01839b7121baf7bcdf;p=clang [OpenCL] Fix for TBAA information of pointer after addresspacecast Summary: When addresspacecast is generated resulting pointer should preserve TBAA information from original value. Reviewers: rjmccall, yaxunl, Anastasia Reviewed By: rjmccall Subscribers: asavonic, kosarev, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D55262 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348919 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3c5eea49d1..b6f26a683e 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -4269,8 +4269,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { QualType DestTy = getContext().getPointerType(E->getType()); llvm::Value *V = getTargetHooks().performAddrSpaceCast( *this, LV.getPointer(), E->getSubExpr()->getType().getAddressSpace(), - DestTy.getAddressSpace(), ConvertType(DestTy)); - return MakeNaturalAlignPointeeAddrLValue(V, DestTy); + E->getType().getAddressSpace(), ConvertType(DestTy)); + return MakeAddrLValue(Address(V, LV.getAddress().getAlignment()), + E->getType(), LV.getBaseInfo(), LV.getTBAAInfo()); } case CK_ObjCObjectLValueCast: { LValue LV = EmitLValue(E->getSubExpr()); diff --git a/test/CodeGenOpenCLCXX/address-space-deduction2.cl b/test/CodeGenOpenCLCXX/address-space-deduction2.cl new file mode 100644 index 0000000000..6772cdcb11 --- /dev/null +++ b/test/CodeGenOpenCLCXX/address-space-deduction2.cl @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -O0 -emit-llvm -o - | FileCheck %s + +class P { +public: + P(const P &Rhs) = default; + + long A; + long B; +}; + +void foo(__global P *GPtr) { +// CHECK: call void @llvm.memcpy{{.*}}, {{.*}}, i32 16 + P Val = GPtr[0]; +} + +struct __attribute__((packed)) A { int X; }; +int test(__global A *GPtr) { +// CHECK: {{.*}} = load i32, {{.*}}, align 1 + return static_cast<__generic A &>(*GPtr).X; +}