Skip to content

Commit 4789226

Browse files
committed
Apply access notes before checkDeclAttributes()
There appear to be ways to enter this function without passing through DeclChecker::visit() first.
1 parent 69fb104 commit 4789226

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,9 @@ void AttributeChecker::visitOptionalAttr(OptionalAttr *attr) {
11301130
}
11311131

11321132
void TypeChecker::checkDeclAttributes(Decl *D) {
1133+
if (auto VD = dyn_cast<ValueDecl>(D))
1134+
TypeChecker::applyAccessNote(VD);
1135+
11331136
AttributeChecker Checker(D);
11341137
// We need to check all OriginallyDefinedInAttr relative to each other, so
11351138
// collect them and check in batch later.

lib/Sema/TypeCheckDeclObjC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
14831483
DiagnosticStateRAII diagState(VD->getASTContext().Diags);
14841484

14851485
// Access notes may add attributes that affect this calculus.
1486-
(void)evaluateOrDefault(evaluator, ApplyAccessNoteRequest{VD}, {});
1486+
TypeChecker::applyAccessNote(VD);
14871487

14881488
auto dc = VD->getDeclContext();
14891489
Optional<ObjCReason> isObjC;

lib/Sema/TypeCheckDeclPrimary.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,11 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote &note,
15141514
}
15151515
}
15161516

1517+
void TypeChecker::applyAccessNote(ValueDecl *VD) {
1518+
(void)evaluateOrDefault(VD->getASTContext().evaluator,
1519+
ApplyAccessNoteRequest{VD}, {});
1520+
}
1521+
15171522
evaluator::SideEffect
15181523
ApplyAccessNoteRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
15191524
AccessNotesFile &notes = VD->getModuleContext()->getAccessNotes();
@@ -1545,8 +1550,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
15451550
PrettyStackTraceDecl StackTrace("type-checking", decl);
15461551

15471552
if (auto VD = dyn_cast<ValueDecl>(decl))
1548-
(void)evaluateOrDefault(VD->getASTContext().evaluator,
1549-
ApplyAccessNoteRequest{VD}, {});
1553+
TypeChecker::applyAccessNote(VD);
15501554

15511555
DeclVisitor<DeclChecker>::visit(decl);
15521556

lib/Sema/TypeChecker.h

+6
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,12 @@ UnresolvedMemberExpr *getUnresolvedMemberChainBase(Expr *expr);
11841184
bool typeSupportsBuilderOp(Type builderType, DeclContext *dc, Identifier fnName,
11851185
ArrayRef<Identifier> argLabels = {},
11861186
SmallVectorImpl<ValueDecl *> *allResults = nullptr);
1187+
1188+
/// Forces all changes specified by the module's access notes file to be
1189+
/// applied to this declaration. It is safe to call this function more than
1190+
/// once.
1191+
void applyAccessNote(ValueDecl *VD);
1192+
11871193
}; // namespace TypeChecker
11881194

11891195
/// Temporary on-stack storage and unescaping for encoded diagnostic

0 commit comments

Comments
 (0)