[PATCH] D125944: Template instantiation error recovery

Purva Chaudhari via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 30 00:12:35 PDT 2022


Purva-Chaudhari updated this revision to Diff 464159.
Purva-Chaudhari added a comment.

rebase, test passing locally


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125944/new/

https://reviews.llvm.org/D125944

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/test/Interpreter/template-recovery.cpp


Index: clang/test/Interpreter/template-recovery.cpp
===================================================================
--- /dev/null
+++ clang/test/Interpreter/template-recovery.cpp
@@ -0,0 +1,18 @@
+// clang-format off
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:            'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+template<class T> T f() { return T(); }
+auto ptu2 = f<float>(); err;
+auto ptu2 = f<float>();
+
+extern "C" int printf(const char *, ...);
+int i = 10;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 10
+
+%quit
Index: clang/lib/Interpreter/IncrementalParser.cpp
===================================================================
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -150,6 +150,7 @@
   llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(&S);
   Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, /*Enabled=*/true);
   Sema::LocalEagerInstantiationScope LocalInstantiations(S);
+  Sema::PerformPendingInstantiationsRAII PerformPendingInstantiations(S);
 
   PTUs.emplace_back(PartialTranslationUnit());
   PartialTranslationUnit &LastPTU = PTUs.back();
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -9719,6 +9719,19 @@
         SavedPendingLocalImplicitInstantiations;
   };
 
+  class PerformPendingInstantiationsRAII {
+  public:
+    PerformPendingInstantiationsRAII(Sema &S): S(S) {} ;
+
+    ~PerformPendingInstantiationsRAII() {
+      S.PerformPendingInstantiations();
+      assert(S.PendingInstantiations.empty() &&
+             "there shouldn't be any pending instantiations");
+    }
+  private:
+    Sema &S;
+  };  
+
   /// A helper class for building up ExtParameterInfos.
   class ExtParameterInfoBuilder {
     SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125944.464159.patch
Type: text/x-patch
Size: 2159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220930/ca4ceb29/attachment-0001.bin>


More information about the cfe-commits mailing list