From 87a7e436c0b9b248aa99741815b23c58a648e1a6 Mon Sep 17 00:00:00 2001 From: Andrew Savonichev Date: Wed, 12 Dec 2018 09:51:23 +0000 Subject: [PATCH] [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 llvm-svn: 348919 --- clang/lib/CodeGen/CGExpr.cpp | 5 +++-- .../CodeGenOpenCLCXX/address-space-deduction2.cl | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenOpenCLCXX/address-space-deduction2.cl diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 3c5eea4..b6f26a6 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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/clang/test/CodeGenOpenCLCXX/address-space-deduction2.cl b/clang/test/CodeGenOpenCLCXX/address-space-deduction2.cl new file mode 100644 index 0000000..6772cdc --- /dev/null +++ b/clang/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; +} -- 2.7.4