Skip to content

Commit b34218b

Browse files
author
ematejska
authored
Merge pull request #10389 from DougGregor/ast-verifier-parsed-4.0
[4.0] [AST Verifier] Don't verify parsed function bodies in a type-checked AST.
2 parents 2d93b21 + 77c53ac commit b34218b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,28 @@ class Verifier : public ASTWalker {
451451
bool shouldVerifyChecked(Pattern *S) { return S->hasType(); }
452452
bool shouldVerifyChecked(Decl *S) { return true; }
453453

454+
// Only verify functions if they have bodies we can safely walk.
455+
// FIXME: This is a bit of a hack; we should be able to check the
456+
// invariants of a parsed body as well.
457+
bool shouldVerify(AbstractFunctionDecl *afd) {
458+
switch (afd->getBodyKind()) {
459+
case AbstractFunctionDecl::BodyKind::None:
460+
case AbstractFunctionDecl::BodyKind::TypeChecked:
461+
case AbstractFunctionDecl::BodyKind::Skipped:
462+
case AbstractFunctionDecl::BodyKind::MemberwiseInitializer:
463+
return true;
464+
465+
case AbstractFunctionDecl::BodyKind::Unparsed:
466+
case AbstractFunctionDecl::BodyKind::Parsed:
467+
case AbstractFunctionDecl::BodyKind::Synthesize:
468+
if (auto SF = dyn_cast<SourceFile>(afd->getModuleScopeContext())) {
469+
return SF->ASTStage < SourceFile::TypeChecked;
470+
}
471+
472+
return false;
473+
}
474+
}
475+
454476
// Default cases for cleaning up as we exit a node.
455477
void cleanup(Expr *E) { }
456478
void cleanup(Stmt *S) { }

0 commit comments

Comments
 (0)