[PATCH] D83325: [Sema] Iteratively strip sugar when removing address spaces.

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 08:52:09 PDT 2020


ebevhan updated this revision to Diff 284395.
ebevhan retitled this revision from "[Sema] Be more thorough when unpacking the AS-qualified pointee for a pointer conversion." to "[Sema] Iteratively strip sugar when removing address spaces.".
ebevhan edited the summary of this revision.
ebevhan added a comment.

Redid patch. Now we properly strip ASes from types by desugaring.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83325/new/

https://reviews.llvm.org/D83325

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGenCXX/address-space-cast.cpp


Index: clang/test/CodeGenCXX/address-space-cast.cpp
===================================================================
--- clang/test/CodeGenCXX/address-space-cast.cpp
+++ clang/test/CodeGenCXX/address-space-cast.cpp
@@ -6,6 +6,16 @@
 void func_pvoid(__private__ void *x);
 void func_pint(__private__ int *x);
 
+class Base {
+};
+
+class Derived : public Base {
+};
+
+void fn(Derived *p) {
+  __private__ Base *b = (__private__ Base *)p;
+}
+
 void test_cast(char *gen_char_ptr, void *gen_void_ptr, int *gen_int_ptr) {
   // CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
   // CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2934,14 +2934,27 @@
 }
 
 QualType ASTContext::removeAddrSpaceQualType(QualType T) const {
+  // If the type is not qualified with an address space, just return it
+  // immediately.
+  if (!T.hasAddressSpace())
+    return T;
+
   // If we are composing extended qualifiers together, merge together
   // into one ExtQuals node.
   QualifierCollector Quals;
-  const Type *TypeNode = Quals.strip(T);
+  const Type *TypeNode;
 
-  // If the qualifier doesn't have an address space just return it.
-  if (!Quals.hasAddressSpace())
-    return T;
+  while (T.hasAddressSpace()) {
+    TypeNode = Quals.strip(T);
+
+    // If the type no longer has an address space after stripping qualifiers,
+    // jump out.
+    if (!QualType(TypeNode, 0).hasAddressSpace())
+      break;
+
+    // There might be sugar in the way. Strip it and try again.
+    T = T.getSingleStepDesugaredType(*this);
+  }
 
   Quals.removeAddressSpace();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83325.284395.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200810/76d40743/attachment-0001.bin>


More information about the cfe-commits mailing list