[cfe-commits] r98327 - in /cfe/trunk: include/clang/Basic/Builtins.def lib/AST/ASTContext.cpp

John McCall rjmccall at apple.com
Thu Mar 11 20:21:28 PST 2010


Author: rjmccall
Date: Thu Mar 11 22:21:28 2010
New Revision: 98327

URL: http://llvm.org/viewvc/llvm-project?rev=98327&view=rev
Log:
Extend the builtin syntax to allow address-space qualifiers on pointers and
references.  Based on a patch by Arnaud de Grandmaison!


Modified:
    cfe/trunk/include/clang/Basic/Builtins.def
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=98327&r1=98326&r2=98327&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Thu Mar 11 22:21:28 2010
@@ -46,8 +46,8 @@
 //  U   -> unsigned
 //
 // Types may be postfixed with the following modifiers:
-// * -> pointer
-// & -> reference
+// * -> pointer (optionally followed by an address space number)
+// & -> reference (optionally followed by an address space number)
 // C -> const
 // D -> volatile
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=98327&r1=98326&r2=98327&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Mar 11 22:21:28 2010
@@ -4973,13 +4973,24 @@
 
   Done = false;
   while (!Done) {
-    switch (*Str++) {
+    switch (char c = *Str++) {
       default: Done = true; --Str; break;
       case '*':
-        Type = Context.getPointerType(Type);
-        break;
       case '&':
-        Type = Context.getLValueReferenceType(Type);
+        {
+          // Both pointers and references can have their pointee types
+          // qualified with an address space.
+          char *End;
+          unsigned AddrSpace = strtoul(Str, &End, 10);
+          if (End != Str && AddrSpace != 0) {
+            Type = Context.getAddrSpaceQualType(Type, AddrSpace);
+            Str = End;
+          }
+        }
+        if (c == '*')
+          Type = Context.getPointerType(Type);
+        else
+          Type = Context.getLValueReferenceType(Type);
         break;
       // FIXME: There's no way to have a built-in with an rvalue ref arg.
       case 'C':





More information about the cfe-commits mailing list