[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 02:55:14 PST 2024


================
@@ -4099,7 +4099,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
   // calls to Decl::getASTContext() by Decl's methods will find the
   // TranslationUnitDecl without crashing.
   D->setDeclContext(Context.getTranslationUnitDecl());
-  Reader.Visit(D);
+
+  // Reading some declarations can result in deep recursion.
+  SemaObj->runWithSufficientStackSpace(DeclLoc, [&] { Reader.Visit(D); });
----------------
ilya-biryukov wrote:

Could you elaborate in which sense it is non-meaningful for the purpose of calling this method?
I believe SemaObj is never null here (because it's used during deserialization of declarations). The only logic we have in `runWithSufficientStackSpace`, is to warn about stack exhaustion only once and actually show this warning.

I would still be using `Wstack-exhausted` here, not sure there is much useful context to add here (maybe a note about deserializing declarations, but this case is so rare I think we can live without it).

https://github.com/llvm/llvm-project/pull/79875


More information about the cfe-commits mailing list