From 9f6c0b34311bbba58a44b7e502f5c5d37bc21565 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 1 Aug 2024 10:39:22 +0200 Subject: [PATCH] [cling] Forcefully clean up TemplateIdAnnotations Upstream Clang keeps TemplateIdAnnotations around "if they might still be in the token stream." See upstream commit for more details: https://github.com/llvm/llvm-project/commit/6163aa96799cbad7f2f58e02c5bebee9647056a5 (included in Clang 11, in ROOT since the upgrade to LLVM 13) This reasoning doesn't apply when we fully reset the Parser state in ParserStateRAII's destructor, and we expect the swapped out vector of TemplateIdAnnotations to be empty in order to not leak. Fixes #16121 --- interpreter/cling/lib/Utils/ParserStateRAII.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interpreter/cling/lib/Utils/ParserStateRAII.cpp b/interpreter/cling/lib/Utils/ParserStateRAII.cpp index d53c3b8c00311..d0eae481986d8 100644 --- a/interpreter/cling/lib/Utils/ParserStateRAII.cpp +++ b/interpreter/cling/lib/Utils/ParserStateRAII.cpp @@ -50,10 +50,13 @@ cling::ParserStateRAII::~ParserStateRAII() { // Note: Consuming the EOF token will pop the include stack. // { - // Cleanup the TemplateIds before swapping the previous set back. - Parser::DestroyTemplateIdAnnotationsRAIIObj CleanupTemplateIds(*P); + // Forcefully clean up the TemplateIds, ignoring additional checks in + // MaybeDestroyTemplateIds called from DestroyTemplateIdAnnotationsRAIIObj, + // before swapping the previous set back. + P->DestroyTemplateIds(); } P->TemplateIds.swap(OldTemplateIds); + assert(OldTemplateIds.empty()); if (SkipToEOF) P->SkipUntil(tok::eof); else