[PATCH] D81474: Handle delayed-template-parsing functions imported into a non-dtp TU

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 9 08:46:11 PDT 2020


sammccall created this revision.
sammccall added a reviewer: rsmith.
Herald added subscribers: cfe-commits, usaxena95, ilya-biryukov.
Herald added a project: clang.

DelayedTemplateParsing is marked as BENIGN_LANGOPT, so we are allowed to
use a delayed template in a non-delayed TU.
(This is clangd's default configuration on windows: delayed-template-parsing
is on for the preamble and forced off for the current file)

However today clang fails to parse implicit instantiations in a non-dtp
TU of templates defined in a dtp PCH file (and presumably module?).
In this case the delayed parser is not registered, so the function is
simply marked "delayed" again. We then hit an assert:
end of TU template instantiation should not create more late-parsed templates


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81474

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/PCH/delayed-template-parsing.cpp


Index: clang/test/PCH/delayed-template-parsing.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/delayed-template-parsing.cpp
@@ -0,0 +1,14 @@
+// Check any combination of delayed-template-parsing between PCH and TU works.
+// RUN: %clang_cc1 %s -emit-pch -o %t.pch
+// RUN: %clang_cc1 -fdelayed-template-parsing %s -emit-pch -o %t.delayed.pch
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.delayed.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.delayed.pch %s
+
+#ifndef MAIN_FILE
+template <typename T>
+T successor(T Value) { return Value + 1; }
+#else
+int x = successor(42);
+#endif
Index: clang/lib/Parse/Parser.cpp
===================================================================
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -652,9 +652,7 @@
     }
 
     // Late template parsing can begin.
-    if (getLangOpts().DelayedTemplateParsing)
-      Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr,
-                                    this);
+    Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
     if (!PP.isIncrementalProcessingEnabled())
       Actions.ActOnEndOfTranslationUnit();
     //else don't tell Sema that we ended parsing: more input might come.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81474.269554.patch
Type: text/x-patch
Size: 1459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200609/87c90fe6/attachment-0001.bin>


More information about the cfe-commits mailing list