浏览代码

ASTContext: Declare builtin types implicitly

__builtin_va_list and friends have been showing up where they shouldn't for way
to long, making unwanted appearences in -ast-print, tooling and source level
visitors and even the hello world tutorial on the clang website.

This commit factors down the implicit typedef and record creation facilities to
ensure they're marked implicit.

Also fixes a unit test that was testing incorrect behaviour, and removes old
hacks in the DeclPrinter that tried to skip implicit declarations manually.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197336 91177308-0d34-0410-b5e6-96231b3b80d8
Alp Toker 11 年之前
父节点
当前提交
7cec627f32
共有 4 个文件被更改,包括 80 次插入203 次删除
  1. 3 0
      include/clang/AST/ASTContext.h
  2. 71 184
      lib/AST/ASTContext.cpp
  3. 0 11
      lib/AST/DeclPrinter.cpp
  4. 6 8
      unittests/Frontend/FrontendActionTest.cpp

+ 3 - 0
include/clang/AST/ASTContext.h

@@ -832,6 +832,9 @@ public:
   void PrintStats() const;
   void PrintStats() const;
   const SmallVectorImpl<Type *>& getTypes() const { return Types; }
   const SmallVectorImpl<Type *>& getTypes() const { return Types; }
 
 
+  /// \brief Create a new implicit TU-level typedef declaration.
+  TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const;
+
   /// \brief Retrieve the declaration for the 128-bit signed integer type.
   /// \brief Retrieve the declaration for the 128-bit signed integer type.
   TypedefDecl *getInt128Decl() const;
   TypedefDecl *getInt128Decl() const;
 
 

+ 71 - 184
lib/AST/ASTContext.cpp

@@ -857,45 +857,49 @@ void ASTContext::PrintStats() const {
   BumpAlloc.PrintStats();
   BumpAlloc.PrintStats();
 }
 }
 
 
+/// CreateRecordDecl - Utility to build implicit CXXRecordDecl or RecordDecl
+/// instances.
+static RecordDecl *CreateRecordDecl(const ASTContext &Ctx,
+                                    RecordDecl::TagKind TK, DeclContext *DC,
+                                    IdentifierInfo *Id) {
+  SourceLocation Loc;
+  RecordDecl *NewDecl;
+  if (Ctx.getLangOpts().CPlusPlus)
+    NewDecl = CXXRecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id);
+  else
+    NewDecl = RecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id);
+  NewDecl->setImplicit();
+  return NewDecl;
+}
+
+TypedefDecl *ASTContext::buildImplicitTypedef(QualType T,
+                                              StringRef Name) const {
+  TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T);
+  TypedefDecl *NewDecl = TypedefDecl::Create(
+      const_cast<ASTContext &>(*this), getTranslationUnitDecl(),
+      SourceLocation(), SourceLocation(), &Idents.get(Name), TInfo);
+  NewDecl->setImplicit();
+  return NewDecl;
+}
+
 TypedefDecl *ASTContext::getInt128Decl() const {
 TypedefDecl *ASTContext::getInt128Decl() const {
-  if (!Int128Decl) {
-    TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(Int128Ty);
-    Int128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 
-                                     getTranslationUnitDecl(),
-                                     SourceLocation(),
-                                     SourceLocation(),
-                                     &Idents.get("__int128_t"),
-                                     TInfo);
-  }
-  
+  if (!Int128Decl)
+    Int128Decl = buildImplicitTypedef(Int128Ty, "__int128_t");
   return Int128Decl;
   return Int128Decl;
 }
 }
 
 
 TypedefDecl *ASTContext::getUInt128Decl() const {
 TypedefDecl *ASTContext::getUInt128Decl() const {
-  if (!UInt128Decl) {
-    TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(UnsignedInt128Ty);
-    UInt128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 
-                                     getTranslationUnitDecl(),
-                                     SourceLocation(),
-                                     SourceLocation(),
-                                     &Idents.get("__uint128_t"),
-                                     TInfo);
-  }
-  
+  if (!UInt128Decl)
+    UInt128Decl = buildImplicitTypedef(UnsignedInt128Ty, "__uint128_t");
   return UInt128Decl;
   return UInt128Decl;
 }
 }
 
 
 TypeDecl *ASTContext::getFloat128StubType() const {
 TypeDecl *ASTContext::getFloat128StubType() const {
   assert(LangOpts.CPlusPlus && "should only be called for c++");
   assert(LangOpts.CPlusPlus && "should only be called for c++");
-  if (!Float128StubDecl) {
-    Float128StubDecl = CXXRecordDecl::Create(const_cast<ASTContext &>(*this), 
-                                             TTK_Struct,
-                                             getTranslationUnitDecl(),
-                                             SourceLocation(),
-                                             SourceLocation(),
-                                             &Idents.get("__float128"));
-  }
-  
+  if (!Float128StubDecl)
+    Float128StubDecl = CreateRecordDecl(
+        *this, TTK_Struct, getTranslationUnitDecl(), &Idents.get("__float128"));
+
   return Float128StubDecl;
   return Float128StubDecl;
 }
 }
 
 
@@ -4557,16 +4561,6 @@ int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const {
   return 1;
   return 1;
 }
 }
 
 
-static RecordDecl *
-CreateRecordDecl(const ASTContext &Ctx, RecordDecl::TagKind TK,
-                 DeclContext *DC, IdentifierInfo *Id) {
-  SourceLocation Loc;
-  if (Ctx.getLangOpts().CPlusPlus)
-    return CXXRecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id);
-  else
-    return RecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id);
-}
-
 // getCFConstantStringType - Return the type used for constant CFStrings.
 // getCFConstantStringType - Return the type used for constant CFStrings.
 QualType ASTContext::getCFConstantStringType() const {
 QualType ASTContext::getCFConstantStringType() const {
   if (!CFConstantStringTypeDecl) {
   if (!CFConstantStringTypeDecl) {
@@ -4769,12 +4763,8 @@ bool ASTContext::getByrefLifetime(QualType Ty,
 
 
 TypedefDecl *ASTContext::getObjCInstanceTypeDecl() {
 TypedefDecl *ASTContext::getObjCInstanceTypeDecl() {
   if (!ObjCInstanceTypeDecl)
   if (!ObjCInstanceTypeDecl)
-    ObjCInstanceTypeDecl = TypedefDecl::Create(*this, 
-                                               getTranslationUnitDecl(),
-                                               SourceLocation(), 
-                                               SourceLocation(),
-                                               &Idents.get("instancetype"), 
-                                     getTrivialTypeSourceInfo(getObjCIdType()));
+    ObjCInstanceTypeDecl =
+        buildImplicitTypedef(getObjCIdType(), "instancetype");
   return ObjCInstanceTypeDecl;
   return ObjCInstanceTypeDecl;
 }
 }
 
 
@@ -5760,24 +5750,15 @@ TypedefDecl *ASTContext::getObjCIdDecl() const {
   if (!ObjCIdDecl) {
   if (!ObjCIdDecl) {
     QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0);
     QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0);
     T = getObjCObjectPointerType(T);
     T = getObjCObjectPointerType(T);
-    TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T);
-    ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
-                                     getTranslationUnitDecl(),
-                                     SourceLocation(), SourceLocation(),
-                                     &Idents.get("id"), IdInfo);
+    ObjCIdDecl = buildImplicitTypedef(T, "id");
   }
   }
-  
   return ObjCIdDecl;
   return ObjCIdDecl;
 }
 }
 
 
 TypedefDecl *ASTContext::getObjCSelDecl() const {
 TypedefDecl *ASTContext::getObjCSelDecl() const {
   if (!ObjCSelDecl) {
   if (!ObjCSelDecl) {
-    QualType SelT = getPointerType(ObjCBuiltinSelTy);
-    TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT);
-    ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
-                                      getTranslationUnitDecl(),
-                                      SourceLocation(), SourceLocation(),
-                                      &Idents.get("SEL"), SelInfo);
+    QualType T = getPointerType(ObjCBuiltinSelTy);
+    ObjCSelDecl = buildImplicitTypedef(T, "SEL");
   }
   }
   return ObjCSelDecl;
   return ObjCSelDecl;
 }
 }
@@ -5786,13 +5767,8 @@ TypedefDecl *ASTContext::getObjCClassDecl() const {
   if (!ObjCClassDecl) {
   if (!ObjCClassDecl) {
     QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0);
     QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0);
     T = getObjCObjectPointerType(T);
     T = getObjCObjectPointerType(T);
-    TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T);
-    ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
-                                        getTranslationUnitDecl(),
-                                        SourceLocation(), SourceLocation(),
-                                        &Idents.get("Class"), ClassInfo);
+    ObjCClassDecl = buildImplicitTypedef(T, "Class");
   }
   }
-  
   return ObjCClassDecl;
   return ObjCClassDecl;
 }
 }
 
 
@@ -5815,37 +5791,22 @@ ObjCInterfaceDecl *ASTContext::getObjCProtocolDecl() const {
 
 
 static TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) {
 static TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) {
   // typedef char* __builtin_va_list;
   // typedef char* __builtin_va_list;
-  QualType CharPtrType = Context->getPointerType(Context->CharTy);
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(CharPtrType);
-
-  TypedefDecl *VaListTypeDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
-  return VaListTypeDecl;
+  QualType T = Context->getPointerType(Context->CharTy);
+  return Context->buildImplicitTypedef(T, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) {
 static TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) {
   // typedef void* __builtin_va_list;
   // typedef void* __builtin_va_list;
-  QualType VoidPtrType = Context->getPointerType(Context->VoidTy);
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(VoidPtrType);
-
-  TypedefDecl *VaListTypeDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
-  return VaListTypeDecl;
+  QualType T = Context->getPointerType(Context->VoidTy);
+  return Context->buildImplicitTypedef(T, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *
 static TypedefDecl *
 CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
 CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
-  RecordDecl *VaListTagDecl;
+  // struct __va_list
+  RecordDecl *VaListTagDecl =
+      CreateRecordDecl(*Context, TTK_Struct, Context->getTranslationUnitDecl(),
+                       &Context->Idents.get("__va_list"));
   if (Context->getLangOpts().CPlusPlus) {
   if (Context->getLangOpts().CPlusPlus) {
     // namespace std { struct __va_list {
     // namespace std { struct __va_list {
     NamespaceDecl *NS;
     NamespaceDecl *NS;
@@ -5854,17 +5815,8 @@ CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
                                /*Inline*/false, SourceLocation(),
                                /*Inline*/false, SourceLocation(),
                                SourceLocation(), &Context->Idents.get("std"),
                                SourceLocation(), &Context->Idents.get("std"),
                                /*PrevDecl*/0);
                                /*PrevDecl*/0);
-
-    VaListTagDecl = CXXRecordDecl::Create(*Context, TTK_Struct,
-                                          Context->getTranslationUnitDecl(),
-                                          SourceLocation(), SourceLocation(),
-                                          &Context->Idents.get("__va_list"));
+    NS->setImplicit();
     VaListTagDecl->setDeclContext(NS);
     VaListTagDecl->setDeclContext(NS);
-  } else {
-    // struct __va_list
-    VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct,
-                                   Context->getTranslationUnitDecl(),
-                                   &Context->Idents.get("__va_list"));
   }
   }
 
 
   VaListTagDecl->startDefinition();
   VaListTagDecl->startDefinition();
@@ -5912,14 +5864,7 @@ CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) {
   Context->VaListTagTy = VaListTagType;
   Context->VaListTagTy = VaListTagType;
 
 
   // } __builtin_va_list;
   // } __builtin_va_list;
-  TypedefDecl *VaListTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          Context->getTrivialTypeSourceInfo(VaListTagType));
-
-  return VaListTypedefDecl;
+  return Context->buildImplicitTypedef(VaListTagType, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
 static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
@@ -5973,12 +5918,9 @@ static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
   Context->VaListTagTy = VaListTagType;
   Context->VaListTagTy = VaListTagType;
 
 
   // } __va_list_tag;
   // } __va_list_tag;
-  TypedefDecl *VaListTagTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__va_list_tag"),
-                          Context->getTrivialTypeSourceInfo(VaListTagType));
+  TypedefDecl *VaListTagTypedefDecl =
+      Context->buildImplicitTypedef(VaListTagType, "__va_list_tag");
+
   QualType VaListTagTypedefType =
   QualType VaListTagTypedefType =
     Context->getTypedefType(VaListTagTypedefDecl);
     Context->getTypedefType(VaListTagTypedefDecl);
 
 
@@ -5987,16 +5929,7 @@ static TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) {
   QualType VaListTagArrayType
   QualType VaListTagArrayType
     = Context->getConstantArrayType(VaListTagTypedefType,
     = Context->getConstantArrayType(VaListTagTypedefType,
                                     Size, ArrayType::Normal, 0);
                                     Size, ArrayType::Normal, 0);
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(VaListTagArrayType);
-  TypedefDecl *VaListTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
-
-  return VaListTypedefDecl;
+  return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *
 static TypedefDecl *
@@ -6047,12 +5980,9 @@ CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) {
   Context->VaListTagTy = VaListTagType;
   Context->VaListTagTy = VaListTagType;
 
 
   // } __va_list_tag;
   // } __va_list_tag;
-  TypedefDecl *VaListTagTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__va_list_tag"),
-                          Context->getTrivialTypeSourceInfo(VaListTagType));
+  TypedefDecl *VaListTagTypedefDecl =
+      Context->buildImplicitTypedef(VaListTagType, "__va_list_tag");
+
   QualType VaListTagTypedefType =
   QualType VaListTagTypedefType =
     Context->getTypedefType(VaListTagTypedefDecl);
     Context->getTypedefType(VaListTagTypedefDecl);
 
 
@@ -6061,16 +5991,7 @@ CreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) {
   QualType VaListTagArrayType
   QualType VaListTagArrayType
     = Context->getConstantArrayType(VaListTagTypedefType,
     = Context->getConstantArrayType(VaListTagTypedefType,
                                       Size, ArrayType::Normal,0);
                                       Size, ArrayType::Normal,0);
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(VaListTagArrayType);
-  TypedefDecl *VaListTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
-
-  return VaListTypedefDecl;
+  return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) {
 static TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) {
@@ -6079,19 +6000,15 @@ static TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) {
   QualType IntArrayType
   QualType IntArrayType
     = Context->getConstantArrayType(Context->IntTy,
     = Context->getConstantArrayType(Context->IntTy,
 				    Size, ArrayType::Normal, 0);
 				    Size, ArrayType::Normal, 0);
-  TypedefDecl *VaListTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          Context->getTrivialTypeSourceInfo(IntArrayType));
-
-  return VaListTypedefDecl;
+  return Context->buildImplicitTypedef(IntArrayType, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *
 static TypedefDecl *
 CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) {
 CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) {
-  RecordDecl *VaListDecl;
+  // struct __va_list
+  RecordDecl *VaListDecl =
+      CreateRecordDecl(*Context, TTK_Struct, Context->getTranslationUnitDecl(),
+                       &Context->Idents.get("__va_list"));
   if (Context->getLangOpts().CPlusPlus) {
   if (Context->getLangOpts().CPlusPlus) {
     // namespace std { struct __va_list {
     // namespace std { struct __va_list {
     NamespaceDecl *NS;
     NamespaceDecl *NS;
@@ -6100,19 +6017,8 @@ CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) {
                                /*Inline*/false, SourceLocation(),
                                /*Inline*/false, SourceLocation(),
                                SourceLocation(), &Context->Idents.get("std"),
                                SourceLocation(), &Context->Idents.get("std"),
                                /*PrevDecl*/0);
                                /*PrevDecl*/0);
-
-    VaListDecl = CXXRecordDecl::Create(*Context, TTK_Struct,
-                                       Context->getTranslationUnitDecl(),
-                                       SourceLocation(), SourceLocation(),
-                                       &Context->Idents.get("__va_list"));
-
+    NS->setImplicit();
     VaListDecl->setDeclContext(NS);
     VaListDecl->setDeclContext(NS);
-
-  } else {
-    // struct __va_list {
-    VaListDecl = CreateRecordDecl(*Context, TTK_Struct,
-                                  Context->getTranslationUnitDecl(),
-                                  &Context->Idents.get("__va_list"));
   }
   }
 
 
   VaListDecl->startDefinition();
   VaListDecl->startDefinition();
@@ -6135,17 +6041,8 @@ CreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) {
   VaListDecl->completeDefinition();
   VaListDecl->completeDefinition();
 
 
   // typedef struct __va_list __builtin_va_list;
   // typedef struct __va_list __builtin_va_list;
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(Context->getRecordType(VaListDecl));
-
-  TypedefDecl *VaListTypeDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
-
-  return VaListTypeDecl;
+  QualType T = Context->getRecordType(VaListDecl);
+  return Context->buildImplicitTypedef(T, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *
 static TypedefDecl *
@@ -6196,12 +6093,8 @@ CreateSystemZBuiltinVaListDecl(const ASTContext *Context) {
   Context->VaListTagTy = VaListTagType;
   Context->VaListTagTy = VaListTagType;
 
 
   // } __va_list_tag;
   // } __va_list_tag;
-  TypedefDecl *VaListTagTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__va_list_tag"),
-                          Context->getTrivialTypeSourceInfo(VaListTagType));
+  TypedefDecl *VaListTagTypedefDecl =
+      Context->buildImplicitTypedef(VaListTagType, "__va_list_tag");
   QualType VaListTagTypedefType =
   QualType VaListTagTypedefType =
     Context->getTypedefType(VaListTagTypedefDecl);
     Context->getTypedefType(VaListTagTypedefDecl);
 
 
@@ -6210,16 +6103,8 @@ CreateSystemZBuiltinVaListDecl(const ASTContext *Context) {
   QualType VaListTagArrayType
   QualType VaListTagArrayType
     = Context->getConstantArrayType(VaListTagTypedefType,
     = Context->getConstantArrayType(VaListTagTypedefType,
                                       Size, ArrayType::Normal,0);
                                       Size, ArrayType::Normal,0);
-  TypeSourceInfo *TInfo
-    = Context->getTrivialTypeSourceInfo(VaListTagArrayType);
-  TypedefDecl *VaListTypedefDecl
-    = TypedefDecl::Create(const_cast<ASTContext &>(*Context),
-                          Context->getTranslationUnitDecl(),
-                          SourceLocation(), SourceLocation(),
-                          &Context->Idents.get("__builtin_va_list"),
-                          TInfo);
 
 
-  return VaListTypedefDecl;
+  return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list");
 }
 }
 
 
 static TypedefDecl *CreateVaListDecl(const ASTContext *Context,
 static TypedefDecl *CreateVaListDecl(const ASTContext *Context,
@@ -6247,8 +6132,10 @@ static TypedefDecl *CreateVaListDecl(const ASTContext *Context,
 }
 }
 
 
 TypedefDecl *ASTContext::getBuiltinVaListDecl() const {
 TypedefDecl *ASTContext::getBuiltinVaListDecl() const {
-  if (!BuiltinVaListDecl)
+  if (!BuiltinVaListDecl) {
     BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind());
     BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind());
+    assert(BuiltinVaListDecl->isImplicit());
+  }
 
 
   return BuiltinVaListDecl;
   return BuiltinVaListDecl;
 }
 }

+ 0 - 11
lib/AST/DeclPrinter.cpp

@@ -238,17 +238,6 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
     if (D->isImplicit())
     if (D->isImplicit())
       continue;
       continue;
 
 
-    // FIXME: Ugly hack so we don't pretty-print the builtin declaration
-    // of __builtin_va_list or __[u]int128_t.  There should be some other way
-    // to check that.
-    if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) {
-      if (IdentifierInfo *II = ND->getIdentifier()) {
-        if (II->isStr("__builtin_va_list") ||
-            II->isStr("__int128_t") || II->isStr("__uint128_t"))
-          continue;
-      }
-    }
-
     // The next bits of code handles stuff like "struct {int x;} a,b"; we're
     // The next bits of code handles stuff like "struct {int x;} a,b"; we're
     // forced to merge the declarations because there's no other way to
     // forced to merge the declarations because there's no other way to
     // refer to the struct in question.  This limited merging is safe without
     // refer to the struct in question.  This limited merging is safe without

+ 6 - 8
unittests/Frontend/FrontendActionTest.cpp

@@ -76,10 +76,9 @@ TEST(ASTFrontendAction, Sanity) {
 
 
   TestASTFrontendAction test_action;
   TestASTFrontendAction test_action;
   ASSERT_TRUE(compiler.ExecuteAction(test_action));
   ASSERT_TRUE(compiler.ExecuteAction(test_action));
-  ASSERT_EQ(3U, test_action.decl_names.size());
-  EXPECT_EQ("__builtin_va_list", test_action.decl_names[0]);
-  EXPECT_EQ("main", test_action.decl_names[1]);
-  EXPECT_EQ("x", test_action.decl_names[2]);
+  ASSERT_EQ(2U, test_action.decl_names.size());
+  EXPECT_EQ("main", test_action.decl_names[0]);
+  EXPECT_EQ("x", test_action.decl_names[1]);
 }
 }
 
 
 TEST(ASTFrontendAction, IncrementalParsing) {
 TEST(ASTFrontendAction, IncrementalParsing) {
@@ -96,10 +95,9 @@ TEST(ASTFrontendAction, IncrementalParsing) {
 
 
   TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true);
   TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true);
   ASSERT_TRUE(compiler.ExecuteAction(test_action));
   ASSERT_TRUE(compiler.ExecuteAction(test_action));
-  ASSERT_EQ(3U, test_action.decl_names.size());
-  EXPECT_EQ("__builtin_va_list", test_action.decl_names[0]);
-  EXPECT_EQ("main", test_action.decl_names[1]);
-  EXPECT_EQ("x", test_action.decl_names[2]);
+  ASSERT_EQ(2U, test_action.decl_names.size());
+  EXPECT_EQ("main", test_action.decl_names[0]);
+  EXPECT_EQ("x", test_action.decl_names[1]);
 }
 }
 
 
 } // anonymous namespace
 } // anonymous namespace