[PATCH] D47627: [ASTContext] Make getAddrSpaceQualType replace address spaces.

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 1 05:56:06 PDT 2018


ebevhan created this revision.
ebevhan added reviewers: rjmccall, arichardson.
Herald added a subscriber: cfe-commits.

The documentation for getAddrSpaceQualType says: "If T already
has an address space specifier, it is silently replaced."

The function did not do this; it asserted instead. Fix it so
that it behaves according to the comment.


Repository:
  rC Clang

https://reviews.llvm.org/D47627

Files:
  lib/AST/ASTContext.cpp


Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -2496,12 +2496,16 @@
   const Type *TypeNode = Quals.strip(T);
 
   // If this type already has an address space specified, it cannot get
-  // another one.
-  assert(!Quals.hasAddressSpace() &&
-         "Type cannot be in multiple addr spaces!");
-  Quals.addAddressSpace(AddressSpace);
+  // another one. Replace it.
+  if (Quals.hasAddressSpace())
+    Quals.removeAddressSpace();
+  if (AddressSpace != LangAS::Default)
+    Quals.addAddressSpace(AddressSpace);
 
-  return getExtQualType(TypeNode, Quals);
+  if (Quals.hasNonFastQualifiers())
+    return getExtQualType(TypeNode, Quals);
+  else
+    return QualType(TypeNode, Quals.getFastQualifiers());
 }
 
 QualType ASTContext::removeAddrSpaceQualType(QualType T) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47627.149437.patch
Type: text/x-patch
Size: 887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180601/4f81873f/attachment-0001.bin>


More information about the cfe-commits mailing list