[clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.
authorRaphael Isemann <teemperor@gmail.com>
Mon, 7 Sep 2020 09:23:39 +0000 (11:23 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Mon, 7 Sep 2020 10:31:30 +0000 (12:31 +0200)
commit0478720157f6413fad7595b8eff9c70d2d99b637
tree9c54d6569bc28712c4c23db3aba4705b35e8f16b
parent56d1f3138b532f4e195a5aaba9ea65a8bcb8adb4
[clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.

Decl::dump is primarily used for debugging to visualise the current state of a
declaration. Usually Decl::dump just displays the current state of the Decl and
doesn't actually change any of its state, however since commit
457226e02a6e8533eaaa864a3fd7c8eeccd2bf58 the method actually started loading
additional declarations from the ExternalASTSource. This causes that calling
Decl::dump during a debugging session now actually does permanent changes to the
AST and will cause the debugged program run to deviate from the original run.

The change that caused this behaviour is the addition of
`hasConstexprDestructor` (which is called from the TextNodeDumper) which
performs a lookup into the current CXXRecordDecl to find the destructor. All
other similar methods just return their respective bit in the DefinitionData
(which obviously doesn't have such side effects).

This just changes the node printer to emit "unknown_constexpr" in case a
CXXRecordDecl is dumped that could potentially call into the ExternalASTSource
instead of the usually empty string/"constexpr". For CXXRecordDecls that can
safely be dumped the old behaviour is preserved

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D80878
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/ast-dump-lambda.cpp
clang/test/AST/ast-dump-records.cpp
clang/unittests/AST/ASTDumpTest.cpp [new file with mode: 0644]
clang/unittests/AST/CMakeLists.txt