Skip to content

Commit ca0aeb2

Browse files
committed
Verify that a Decl's DeclContext and a DeclContext's parent are in sync
When a Decl is also a DeclContext, these two concepts are identical, and we rely on that throughout the compiler. No functionality change; we appear to already be doing this correctly.
1 parent 38e5c8a commit ca0aeb2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,19 @@ class Verifier : public ASTWalker {
540540
void verifyParsed(Stmt *S) {}
541541
void verifyParsed(Pattern *P) {}
542542
void verifyParsed(Decl *D) {
543+
PrettyStackTraceDecl debugStack("verifying ", D);
543544
if (!D->getDeclContext()) {
544-
Out << "every Decl should have a DeclContext";
545-
PrettyStackTraceDecl debugStack("verifying DeclContext", D);
545+
Out << "every Decl should have a DeclContext\n";
546546
abort();
547547
}
548+
if (auto *DC = dyn_cast<DeclContext>(D)) {
549+
if (D->getDeclContext() != DC->getParent()) {
550+
Out << "Decl's DeclContext not in sync with DeclContext's parent\n";
551+
D->getDeclContext()->dumpContext();
552+
DC->getParent()->dumpContext();
553+
abort();
554+
}
555+
}
548556
}
549557
template<typename T>
550558
void verifyParsedBase(T ASTNode) {

0 commit comments

Comments
 (0)