From: Douglas Gregor Date: Fri, 12 Aug 2011 06:49:56 +0000 (+0000) Subject: Switch the __int128_t and __uint128_t types over to predefined types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=772eeaefef2c883aabe35caf4543e7e32d290183;p=clang Switch the __int128_t and __uint128_t types over to predefined types in the AST format, which are built lazily by the ASTContext when requested. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137437 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 2625f81eb7..bb71503ee2 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -174,9 +174,12 @@ class ASTContext : public llvm::RefCountedBase { TemplateTemplateParmDecl * getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; - /// \brief Whether __[u]int128_t identifier is installed. - bool IsInt128Installed; + /// \brief The typedef for the __int128_t type. + mutable TypedefDecl *Int128Decl; + /// \brief The typedef for the __uint128_t type. + mutable TypedefDecl *UInt128Decl; + /// BuiltinVaListType - built-in va list type. /// This is initially null and set by Sema::LazilyCreateBuiltin when /// a builtin that takes a valist is encountered. @@ -499,6 +502,12 @@ public: void PrintStats() const; const std::vector& getTypes() const { return Types; } + /// \brief Retrieve the declaration for the 128-bit signed integer type. + TypedefDecl *getInt128Decl() const; + + /// \brief Retrieve the declaration for the 128-bit unsigned integer type. + TypedefDecl *getUInt128Decl() const; + //===--------------------------------------------------------------------===// // Type Constructors //===--------------------------------------------------------------------===// @@ -947,10 +956,6 @@ public: /// purpose in characters. CharUnits getObjCEncodingTypeSize(QualType t) const; - /// \brief Whether __[u]int128_t identifier is installed. - bool isInt128Installed() const { return IsInt128Installed; } - void setInt128Installed() { IsInt128Installed = true; } - /// \brief Retrieve the typedef corresponding to the predefined 'id' type /// in Objective-C. TypedefDecl *getObjCIdDecl() const; diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 56a0f52920..6699b13293 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -655,9 +655,7 @@ namespace clang { /// \brief Objective-C "Class" redefinition type SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 7, /// \brief Objective-C "SEL" redefinition type - SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 8, - /// \brief Whether __[u]int128_t identifier is installed. - SPECIAL_TYPE_INT128_INSTALLED = 9 + SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 8 }; /// \brief Predefined declaration IDs. @@ -680,14 +678,20 @@ namespace clang { PREDEF_DECL_OBJC_SEL_ID = 3, /// \brief The Objective-C 'Class' type. - PREDEF_DECL_OBJC_CLASS_ID = 4 + PREDEF_DECL_OBJC_CLASS_ID = 4, + + /// \brief The signed 128-bit integer type. + PREDEF_DECL_INT_128_ID = 5, + + /// \brief The unsigned 128-bit integer type. + PREDEF_DECL_UNSIGNED_INT_128_ID = 6 }; /// \brief The number of declaration IDs that are predefined. /// /// For more information about predefined declarations, see the /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants. - const unsigned int NUM_PREDEF_DECL_IDS = 5; + const unsigned int NUM_PREDEF_DECL_IDS = 7; /// \brief Record codes for each kind of declaration. /// diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 8a4c9d3338..cd7d5080e8 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -221,7 +221,8 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, TemplateSpecializationTypes(this_()), DependentTemplateSpecializationTypes(this_()), SubstTemplateTemplateParmPacks(this_()), - GlobalNestedNameSpecifier(0), IsInt128Installed(false), + GlobalNestedNameSpecifier(0), + Int128Decl(0), UInt128Decl(0), ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), CFConstantStringTypeDecl(0), FILEDecl(0), @@ -346,6 +347,33 @@ void ASTContext::PrintStats() const { BumpAlloc.PrintStats(); } +TypedefDecl *ASTContext::getInt128Decl() const { + if (!Int128Decl) { + TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(Int128Ty); + Int128Decl = TypedefDecl::Create(const_cast(*this), + getTranslationUnitDecl(), + SourceLocation(), + SourceLocation(), + &Idents.get("__int128_t"), + TInfo); + } + + return Int128Decl; +} + +TypedefDecl *ASTContext::getUInt128Decl() const { + if (!UInt128Decl) { + TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(UnsignedInt128Ty); + UInt128Decl = TypedefDecl::Create(const_cast(*this), + getTranslationUnitDecl(), + SourceLocation(), + SourceLocation(), + &Idents.get("__uint128_t"), + TInfo); + } + + return UInt128Decl; +} void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index a4abae42ac..657f2d92e3 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -60,39 +60,17 @@ void Sema::ActOnTranslationUnitScope(Scope *S) { VAListTagName = PP.getIdentifierInfo("__va_list_tag"); - if (!Context.isInt128Installed() && // May be set by ASTReader. - PP.getTargetInfo().getPointerWidth(0) >= 64) { - TypeSourceInfo *TInfo; - - // Install [u]int128_t for 64-bit targets. - TInfo = Context.getTrivialTypeSourceInfo(Context.Int128Ty); - PushOnScopeChains(TypedefDecl::Create(Context, CurContext, - SourceLocation(), - SourceLocation(), - &Context.Idents.get("__int128_t"), - TInfo), TUScope); - - TInfo = Context.getTrivialTypeSourceInfo(Context.UnsignedInt128Ty); - PushOnScopeChains(TypedefDecl::Create(Context, CurContext, - SourceLocation(), - SourceLocation(), - &Context.Idents.get("__uint128_t"), - TInfo), TUScope); - Context.setInt128Installed(); + if (PP.getLangOptions().ObjC1) { + // Synthesize "@class Protocol; + if (Context.getObjCProtoType().isNull()) { + ObjCInterfaceDecl *ProtocolDecl = + ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("Protocol"), + SourceLocation(), true); + Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); + PushOnScopeChains(ProtocolDecl, TUScope, false); + } } - - - if (!PP.getLangOptions().ObjC1) return; - - // Synthesize "@class Protocol; - if (Context.getObjCProtoType().isNull()) { - ObjCInterfaceDecl *ProtocolDecl = - ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), - &Context.Idents.get("Protocol"), - SourceLocation(), true); - Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); - PushOnScopeChains(ProtocolDecl, TUScope, false); - } } Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, @@ -142,6 +120,20 @@ void Sema::Initialize() { = dyn_cast_or_null(Context.getExternalSource())) ExternalSema->InitializeSema(*this); + // Initialize predefined 128-bit integer types, if needed. + if (PP.getTargetInfo().getPointerWidth(0) >= 64) { + // If either of the 128-bit integer types are unavailable to name lookup, + // define them now. + DeclarationName Int128 = &Context.Idents.get("__int128_t"); + if (IdentifierResolver::begin(Int128) == IdentifierResolver::end()) + PushOnScopeChains(Context.getInt128Decl(), TUScope); + + DeclarationName UInt128 = &Context.Idents.get("__uint128_t"); + if (IdentifierResolver::begin(UInt128) == IdentifierResolver::end()) + PushOnScopeChains(Context.getUInt128Decl(), TUScope); + } + + // Initialize predefined Objective-C types: if (PP.getLangOptions().ObjC1) { // If 'SEL' does not yet refer to any declarations, make it refer to the diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index c048f58fdb..53790fb8cc 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -3075,9 +3075,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); } - if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) - Context->setInt128Installed(); - ReadPragmaDiagnosticMappings(Context->getDiagnostics()); // If there were any CUDA special declarations, deserialize them. @@ -4222,6 +4219,14 @@ Decl *ASTReader::GetDecl(DeclID ID) { case PREDEF_DECL_OBJC_CLASS_ID: assert(Context && "No context available?"); return Context->getObjCClassDecl(); + + case PREDEF_DECL_INT_128_ID: + assert(Context && "No context available?"); + return Context->getInt128Decl(); + + case PREDEF_DECL_UNSIGNED_INT_128_ID: + assert(Context && "No context available?"); + return Context->getUInt128Decl(); } return 0; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 47bcd6fdee..3af8fd7b93 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2814,6 +2814,10 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; if (Context.ObjCClassDecl) DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; + if (Context.Int128Decl) + DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; + if (Context.UInt128Decl) + DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; if (!Chain) { // Make sure that we emit IdentifierInfos (and any attached @@ -3029,7 +3033,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); - SpecialTypes.push_back(Context.isInt128Installed()); // Keep writing types and declarations until all types and // declarations have been written.