[clang] [llvm] [WIP][Clang-Repl] Introduce Error Recovery for Clang-Repl. (PR #223305)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 13 22:05:59 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/include/clang/Interpreter/ErrorRecovery.h clang/lib/Interpreter/ASTContextStateStash.cpp clang/lib/Interpreter/SemaStateStash.cpp clang/test/Interpreter/ptu-adl-namespace-collisions.cpp clang/test/Interpreter/ptu-class-edge-cases.cpp clang/test/Interpreter/ptu-class-sema-recovery.cpp clang/test/Interpreter/ptu-lookup-recovery.cpp clang/test/Interpreter/ptu-rewind-stress.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/AST/ASTMutationListener.h clang/include/clang/AST/Decl.h clang/include/clang/AST/DeclBase.h clang/include/clang/AST/DeclCXX.h clang/include/clang/AST/DeclContextInternals.h clang/include/clang/AST/DeclTemplate.h clang/include/clang/AST/DeclarationName.h clang/include/clang/AST/RecordLayout.h clang/include/clang/AST/Redeclarable.h clang/include/clang/Interpreter/PartialTranslationUnit.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/Frontend/MultiplexConsumer.cpp clang/lib/Interpreter/IncrementalAction.h clang/lib/Interpreter/IncrementalParser.cpp clang/lib/Interpreter/IncrementalParser.h clang/lib/Interpreter/Interpreter.cpp llvm/include/llvm/ADT/FoldingSet.h llvm/include/llvm/Support/Allocator.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Interpreter/ErrorRecovery.h b/clang/include/clang/Interpreter/ErrorRecovery.h
index 0c47e9bc2..bd3e24d94 100644
--- a/clang/include/clang/Interpreter/ErrorRecovery.h
+++ b/clang/include/clang/Interpreter/ErrorRecovery.h
@@ -1468,7 +1468,8 @@ public:
   /// EvaluatedValueCached likewise) is never returned as verified --
   /// there is nothing to compare it against, so it cannot be confirmed,
   /// full stop, not assumed either way.
-  // static uint32_t verifyMutationFor(const Decl *D, DeclShape S, uint32_t FlaggedKinds,
+  // static uint32_t verifyMutationFor(const Decl *D, DeclShape S, uint32_t
+  // FlaggedKinds,
   //                            PTUID ID);
 
   void commitLevel1(PTUID ID, const Decl *D, MutationRecord &Rec,
diff --git a/clang/lib/Frontend/MultiplexConsumer.cpp b/clang/lib/Frontend/MultiplexConsumer.cpp
index bd9f4af9b..97798b741 100644
--- a/clang/lib/Frontend/MultiplexConsumer.cpp
+++ b/clang/lib/Frontend/MultiplexConsumer.cpp
@@ -279,7 +279,8 @@ void MultiplexASTMutationListener::AddedAnonymousNamespace(
   for (auto *L : Listeners)
     L->AddedAnonymousNamespace(TU, AnonNamespace);
 }
-void MultiplexASTMutationListener::AddedTagDeclType(const TagDecl *TD, const Type *T) {
+void MultiplexASTMutationListener::AddedTagDeclType(const TagDecl *TD,
+                                                    const Type *T) {
   for (auto *L : Listeners)
     L->AddedTagDeclType(TD, T);
 }
diff --git a/clang/lib/Interpreter/ASTContextStateStash.cpp b/clang/lib/Interpreter/ASTContextStateStash.cpp
index d9da3f744..b9ac44cd8 100644
--- a/clang/lib/Interpreter/ASTContextStateStash.cpp
+++ b/clang/lib/Interpreter/ASTContextStateStash.cpp
@@ -898,13 +898,12 @@ void ASTContextStateRecovery::restore(StashCheckPoint &CP,
   if (Ctx.AutoTypes.size() != CP.AutoTypesSize) {
     llvm::dbgs() << "Ctx.AutoTypes.size() != CP.AutoTypesSize\n";
     // mutable llvm::DenseMap<llvm::FoldingSetNodeID, AutoType *> AutoTypes;
-    eraseDenseMapIf(
-        Ctx.AutoTypes,
-        [&](llvm::detail::DenseMapPair<llvm::FoldingSetNodeIDRef, AutoType *>
-                &KV) -> bool {
-          return Ctx.getAllocator().isAfterCheckpoint(
-              static_cast<void *>(KV.getSecond()), SlabCP);
-        });
+    eraseDenseMapIf(Ctx.AutoTypes,
+                    [&](llvm::detail::DenseMapPair<llvm::FoldingSetNodeIDRef,
+                                                   AutoType *> &KV) -> bool {
+                      return Ctx.getAllocator().isAfterCheckpoint(
+                          static_cast<void *>(KV.getSecond()), SlabCP);
+                    });
     assert(Ctx.AutoTypes.size() == CP.AutoTypesSize);
   }
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 413726c74..5e8ba229b 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -559,9 +559,9 @@ Interpreter::Parse(llvm::StringRef Code) {
     explicit PTUSlabRollback(Sema &S)
         : Ctx(S.getASTContext()), ASTCtxState(Ctx), SemaState(S),
           CheckPoint(Ctx.getAllocator().checkPoint()) {
-            SemaState.stash(SemaCheckPoint);
-            ASTCtxState.stash(CtxCheckPoint);
-          }
+      SemaState.stash(SemaCheckPoint);
+      ASTCtxState.stash(CtxCheckPoint);
+    }
 
     ~PTUSlabRollback() {
       if (!Committed) {
diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index cc9bd67d6..347b7f256 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -267,7 +267,7 @@ public:
 #else
     // In non-ASAN builds, overwrite with a known poison pattern
     // so use-after-rewind crashes deterministically in debug builds
-// #ifndef NDEBUG
+    // #ifndef NDEBUG
     memset(Ptr, 0xCD, Size); // 0xCD = classic "dead memory" pattern
 // #endif
 #endif
@@ -298,7 +298,7 @@ public:
     assert(CP.ActiveSlabIdx >= 0 && CP.ActiveSlabIdx < Slabs.size());
     assert(CP.CurPtr >= (const char *)Slabs[CP.ActiveSlabIdx] &&
            CP.EndSentinel == uintptr_t(Slabs[CP.ActiveSlabIdx]) +
-                      computeSlabSize(CP.ActiveSlabIdx) + 1);
+                                 computeSlabSize(CP.ActiveSlabIdx) + 1);
     ActiveSlabIdx = CP.ActiveSlabIdx;
     CurPtr = CP.CurPtr;
     EndSentinel = CP.EndSentinel;
@@ -306,8 +306,11 @@ public:
     uintptr_t EndRange =
         uintptr_t(Slabs[CP.ActiveSlabIdx]) + computeSlabSize(CP.ActiveSlabIdx);
 
-    llvm::outs() << "Poisoned range = [" << (void *)CurPtr << ", " << (void *)(EndSentinel - 1) << "]\n";
-    llvm::outs() << "Poisoned End Size = [" << (void *)CurPtr << ", " << (void *)(CurPtr + ((EndSentinel - 1) - (uintptr_t)CurPtr)) << "]\n";
+    llvm::outs() << "Poisoned range = [" << (void *)CurPtr << ", "
+                 << (void *)(EndSentinel - 1) << "]\n";
+    llvm::outs() << "Poisoned End Size = [" << (void *)CurPtr << ", "
+                 << (void *)(CurPtr + ((EndSentinel - 1) - (uintptr_t)CurPtr))
+                 << "]\n";
     llvm::outs().flush();
     poisonMemory((void *)CurPtr, (size_t)(EndRange - uintptr_t(CurPtr)));
     for (unsigned I = ActiveSlabIdx + 1; I < Slabs.size(); ++I)

``````````

</details>


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


More information about the cfe-commits mailing list