[PATCH] D59988: [PR41276] Generate address space cast of 'this' for objects attributed by an address space in C++

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 29 04:49:11 PDT 2019


Anastasia created this revision.
Anastasia added reviewers: rjmccall, brunodefraine.
Herald added a subscriber: ebevhan.

The example from the bugzilla triggered two issues:

1. In qualification conversion we are creating an address space conversion for non-pointer and non-reference type.
2. We are not taking an address space from the right type when attempting to cast argument of 'this' to its parameter type.


https://reviews.llvm.org/D59988

Files:
  lib/CodeGen/CGClass.cpp
  lib/Sema/SemaInit.cpp
  test/CodeGenCXX/address-space-of-this.cpp


Index: test/CodeGenCXX/address-space-of-this.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/address-space-of-this.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++14 -triple=spir -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -std=c++17 -triple=spir -emit-llvm -o - | FileCheck %s
+
+struct MyType {
+  MyType(int i) : i(i) {}
+  int i;
+};
+//CHECK: call void @_ZN6MyTypeC1Ei(%struct.MyType* addrspacecast (%struct.MyType addrspace(10)* @m to %struct.MyType*), i32 123)
+MyType __attribute__((address_space(10))) m = 123;
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -7321,7 +7321,8 @@
 ExprResult Sema::PerformQualificationConversion(Expr *E, QualType Ty,
                                                 ExprValueKind VK,
                                                 CheckedConversionKind CCK) {
-  CastKind CK = (Ty.getAddressSpace() != E->getType().getAddressSpace())
+  CastKind CK = (!(VK == VK_RValue && Ty->getPointeeType().isNull()) &&
+                 Ty.getAddressSpace() != E->getType().getAddressSpace())
                     ? CK_AddressSpaceConversion
                     : CK_NoOp;
   return ImpCastExprToType(E, Ty, CK, VK, /*BasePath=*/nullptr, CCK);
Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2013,16 +2013,16 @@
                                              bool NewPointerIsChecked) {
   CallArgList Args;
 
-  LangAS SlotAS = E->getType().getAddressSpace();
-  QualType ThisType = D->getThisType();
-  LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace();
   llvm::Value *ThisPtr = This.getPointer();
-  if (SlotAS != ThisAS) {
-    unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
+  QualType ThisType = D->getThisType();
+  auto ThisArgAS = ThisPtr->getType()->getPointerAddressSpace();
+  auto ThisParAS = getContext().getTargetAddressSpace(
+      ThisType.getTypePtr()->getPointeeType().getAddressSpace());
+  if (ThisArgAS != ThisParAS) {
     llvm::Type *NewType =
-        ThisPtr->getType()->getPointerElementType()->getPointerTo(TargetThisAS);
-    ThisPtr = getTargetHooks().performAddrSpaceCast(*this, This.getPointer(),
-                                                    ThisAS, SlotAS, NewType);
+        ThisPtr->getType()->getPointerElementType()->getPointerTo(ThisParAS);
+    ThisPtr =
+        Builder.CreatePointerBitCastOrAddrSpaceCast(This.getPointer(), NewType);
   }
   // Push the this ptr.
   Args.add(RValue::get(ThisPtr), D->getThisType());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59988.192804.patch
Type: text/x-patch
Size: 2731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190329/7c7696dd/attachment.bin>


More information about the cfe-commits mailing list