Skip to content

Commit f91f28c

Browse files
committed
[Sema] Split special builtin type lookups into a separate function
In case further such cases appear in the future we've got a generic function to add them to. Additionally changed the ObjC special case to check the language and the identifier builtin ID instead of the name. Addresses the cleanup suggestion from D87917. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D87983
1 parent 474d527 commit f91f28c

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,6 +3813,7 @@ class Sema final {
38133813
RedeclarationKind Redecl
38143814
= NotForRedeclaration);
38153815
bool LookupBuiltin(LookupResult &R);
3816+
void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID);
38163817
bool LookupName(LookupResult &R, Scope *S,
38173818
bool AllowBuiltinCreation = false);
38183819
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,24 +2035,6 @@ Scope *Sema::getNonFieldDeclScope(Scope *S) {
20352035
return S;
20362036
}
20372037

2038-
/// Looks up the declaration of "struct objc_super" and
2039-
/// saves it for later use in building builtin declaration of
2040-
/// objc_msgSendSuper and objc_msgSendSuper_stret. If no such
2041-
/// pre-existing declaration exists no action takes place.
2042-
static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S,
2043-
IdentifierInfo *II) {
2044-
if (!II->isStr("objc_msgSendSuper"))
2045-
return;
2046-
ASTContext &Context = ThisSema.Context;
2047-
2048-
LookupResult Result(ThisSema, &Context.Idents.get("objc_super"),
2049-
SourceLocation(), Sema::LookupTagName);
2050-
ThisSema.LookupName(Result, S);
2051-
if (Result.getResultKind() == LookupResult::Found)
2052-
if (const TagDecl *TD = Result.getAsSingle<TagDecl>())
2053-
Context.setObjCSuperType(Context.getTagDeclType(TD));
2054-
}
2055-
20562038
static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID,
20572039
ASTContext::GetBuiltinTypeError Error) {
20582040
switch (Error) {
@@ -2113,7 +2095,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, QualType Type,
21132095
NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
21142096
Scope *S, bool ForRedeclaration,
21152097
SourceLocation Loc) {
2116-
LookupPredefedObjCSuperType(*this, S, II);
2098+
LookupNecessaryTypesForBuiltin(S, ID);
21172099

21182100
ASTContext::GetBuiltinTypeError Error;
21192101
QualType R = Context.GetBuiltinType(ID, Error);
@@ -9671,7 +9653,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
96719653
NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
96729654
} else {
96739655
ASTContext::GetBuiltinTypeError Error;
9674-
LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
9656+
LookupNecessaryTypesForBuiltin(S, BuiltinID);
96759657
QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error);
96769658

96779659
if (!Error && !BuiltinType.isNull() &&
@@ -10880,7 +10862,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
1088010862
// declaration against the expected type for the builtin.
1088110863
if (unsigned BuiltinID = NewFD->getBuiltinID()) {
1088210864
ASTContext::GetBuiltinTypeError Error;
10883-
LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
10865+
LookupNecessaryTypesForBuiltin(S, BuiltinID);
1088410866
QualType T = Context.GetBuiltinType(BuiltinID, Error);
1088510867
// If the type of the builtin differs only in its exception
1088610868
// specification, that's OK.

clang/lib/Sema/SemaLookup.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,24 @@ bool Sema::LookupBuiltin(LookupResult &R) {
907907
return false;
908908
}
909909

910+
/// Looks up the declaration of "struct objc_super" and
911+
/// saves it for later use in building builtin declaration of
912+
/// objc_msgSendSuper and objc_msgSendSuper_stret.
913+
static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S) {
914+
ASTContext &Context = Sema.Context;
915+
LookupResult Result(Sema, &Context.Idents.get("objc_super"), SourceLocation(),
916+
Sema::LookupTagName);
917+
Sema.LookupName(Result, S);
918+
if (Result.getResultKind() == LookupResult::Found)
919+
if (const TagDecl *TD = Result.getAsSingle<TagDecl>())
920+
Context.setObjCSuperType(Context.getTagDeclType(TD));
921+
}
922+
923+
void Sema::LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID) {
924+
if (ID == Builtin::BIobjc_msgSendSuper)
925+
LookupPredefedObjCSuperType(*this, S);
926+
}
927+
910928
/// Determine whether we can declare a special member function within
911929
/// the class at this point.
912930
static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class) {

0 commit comments

Comments
 (0)