From a8cbd5f62fbf1b7f5400fee8af48697e4bdf3774 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sat, 4 May 2024 19:32:26 +0000 Subject: [PATCH] Restore the TUScope only when we are not in incremental processing mode. The TUScope is set to nullptr in Sema::ActOnEndOfTranslationUnit onlu when incremental processing mode in off. This makes the state of Sema more consistent when Clad is on/off. --- tools/ClangPlugin.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/ClangPlugin.cpp b/tools/ClangPlugin.cpp index bc0ee14b5..ef38173aa 100644 --- a/tools/ClangPlugin.cpp +++ b/tools/ClangPlugin.cpp @@ -397,7 +397,8 @@ namespace clad { void CladPlugin::HandleTranslationUnit(ASTContext& C) { Sema& S = m_CI.getSema(); // Restore the TUScope that became a 0 in Sema::ActOnEndOfTranslationUnit. - S.TUScope = m_StoredTUScope; + if (!m_CI.getPreprocessor().isIncrementalProcessingEnabled()) + S.TUScope = m_StoredTUScope; constexpr bool Enabled = true; Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, Enabled); Sema::LocalEagerInstantiationScope LocalInstantiations(S); @@ -409,8 +410,11 @@ namespace clad { m_DiffRequestGraph.markCurrentNodeProcessed(); request = m_DiffRequestGraph.getNextToProcessNode(); } + // Put the TUScope in a consistent state after clad is done. - S.TUScope = nullptr; + if (!m_CI.getPreprocessor().isIncrementalProcessingEnabled()) + S.TUScope = nullptr; + // Force emission of the produced pending template instantiations. LocalInstantiations.perform(); GlobalInstantiations.perform();