diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3813,6 +3813,7 @@ RedeclarationKind Redecl = NotForRedeclaration); bool LookupBuiltin(LookupResult &R); + void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false); bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2035,24 +2035,6 @@ return S; } -/// Looks up the declaration of "struct objc_super" and -/// saves it for later use in building builtin declaration of -/// objc_msgSendSuper and objc_msgSendSuper_stret. If no such -/// pre-existing declaration exists no action takes place. -static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S, - IdentifierInfo *II) { - if (!II->isStr("objc_msgSendSuper")) - return; - ASTContext &Context = ThisSema.Context; - - LookupResult Result(ThisSema, &Context.Idents.get("objc_super"), - SourceLocation(), Sema::LookupTagName); - ThisSema.LookupName(Result, S); - if (Result.getResultKind() == LookupResult::Found) - if (const TagDecl *TD = Result.getAsSingle()) - Context.setObjCSuperType(Context.getTagDeclType(TD)); -} - static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID, ASTContext::GetBuiltinTypeError Error) { switch (Error) { @@ -2113,7 +2095,7 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc) { - LookupPredefedObjCSuperType(*this, S, II); + LookupNecessaryTypesForBuiltin(S, ID); ASTContext::GetBuiltinTypeError Error; QualType R = Context.GetBuiltinType(ID, Error); @@ -9671,7 +9653,7 @@ NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID)); } else { ASTContext::GetBuiltinTypeError Error; - LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier()); + LookupNecessaryTypesForBuiltin(S, BuiltinID); QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error); if (!Error && !BuiltinType.isNull() && @@ -10880,7 +10862,7 @@ // declaration against the expected type for the builtin. if (unsigned BuiltinID = NewFD->getBuiltinID()) { ASTContext::GetBuiltinTypeError Error; - LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier()); + LookupNecessaryTypesForBuiltin(S, BuiltinID); QualType T = Context.GetBuiltinType(BuiltinID, Error); // If the type of the builtin differs only in its exception // specification, that's OK. diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -907,6 +907,24 @@ return false; } +/// Looks up the declaration of "struct objc_super" and +/// saves it for later use in building builtin declaration of +/// objc_msgSendSuper and objc_msgSendSuper_stret. +static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S) { + ASTContext &Context = Sema.Context; + LookupResult Result(Sema, &Context.Idents.get("objc_super"), SourceLocation(), + Sema::LookupTagName); + Sema.LookupName(Result, S); + if (Result.getResultKind() == LookupResult::Found) + if (const TagDecl *TD = Result.getAsSingle()) + Context.setObjCSuperType(Context.getTagDeclType(TD)); +} + +void Sema::LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID) { + if (ID == Builtin::BIobjc_msgSendSuper) + LookupPredefedObjCSuperType(*this, S); +} + /// Determine whether we can declare a special member function within /// the class at this point. static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class) {