From 187ab37a05b8f7015b9f39cc8cd9129a0c6d0b48 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 12 Mar 2010 04:21:28 +0000 Subject: [PATCH] Extend the builtin syntax to allow address-space qualifiers on pointers and references. Based on a patch by Arnaud de Grandmaison! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98327 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Builtins.def | 4 ++-- lib/AST/ASTContext.cpp | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index af233b81e0..3afdaf5b0e 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -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 diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 079c16ac6b..ea121165fc 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4973,13 +4973,24 @@ static QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context, 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': -- 2.40.0