]> granicus.if.org Git - clang/commitdiff
[OpenCL] Fix for TBAA information of pointer after addresspacecast
authorAndrew Savonichev <andrew.savonichev@intel.com>
Wed, 12 Dec 2018 09:51:23 +0000 (09:51 +0000)
committerAndrew Savonichev <andrew.savonichev@intel.com>
Wed, 12 Dec 2018 09:51:23 +0000 (09:51 +0000)
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

lib/CodeGen/CGExpr.cpp
test/CodeGenOpenCLCXX/address-space-deduction2.cl [new file with mode: 0644]

index 3c5eea49d1af4c39b9c43cec3e036b1efdab1548..b6f26a683e40290b0e77adfb80e0f90109c5fe4d 100644 (file)
@@ -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 (file)
index 0000000..6772cdc
--- /dev/null
@@ -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;
+}