[clang] [clang-format] Fix crashes on directives in discarded macro call args (PR #221501)

Andre Sun via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 15 14:04:52 PDT 2026


================
@@ -1101,6 +1110,28 @@ void UnwrappedLineParser::conditionalCompilationEnd() {
     PPStack.pop_back();
 }
 
+UnwrappedLineParser::PPState UnwrappedLineParser::savePPState() const {
+  return {PPStack,
+          PPBranchLevel,
+          PPLevelBranchIndex,
+          PPLevelBranchCount,
+          PPChainBranchIndex,
+          IncludeGuard,
+          IncludeGuardToken,
+          AtEndOfPPLine};
+}
+
+void UnwrappedLineParser::restorePPState(const PPState &State) {
+  PPStack = State.PPStack;
+  PPBranchLevel = State.PPBranchLevel;
+  PPLevelBranchIndex = State.PPLevelBranchIndex;
+  PPLevelBranchCount = State.PPLevelBranchCount;
+  PPChainBranchIndex = State.PPChainBranchIndex;
+  IncludeGuard = State.IncludeGuard;
+  IncludeGuardToken = State.IncludeGuardToken;
+  AtEndOfPPLine = State.AtEndOfPPLine;
+}
+
----------------
and2049 wrote:

I think so as well, I'll revise the patch to use a single PPState member in the parser instead of saving and restoring each member individually. 

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


More information about the cfe-commits mailing list