Author: Sam McCall Date: 2020-06-12T16:09:38+02:00 New Revision: 05ed3efc2ac7b34bd62b1cbac88ff9a47b649cc5
URL: https://github.com/llvm/llvm-project/commit/05ed3efc2ac7b34bd62b1cbac88ff9a47b649cc5 DIFF: https://github.com/llvm/llvm-project/commit/05ed3efc2ac7b34bd62b1cbac88ff9a47b649cc5.diff LOG: Handle delayed-template-parsing functions imported into a non-dtp TU Summary: 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 Reviewers: rsmith Subscribers: ilya-biryukov, usaxena95, cfe-commits, kadircet Tags: #clang Differential Revision: https://reviews.llvm.org/D81474 Added: clang/test/PCH/delayed-template-parsing.cpp Modified: clang/lib/Parse/Parser.cpp Removed: ################################################################################ diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 2cea7307b3ac..764d4e8e9d52 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -652,9 +652,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, bool IsFirstDecl) { } // 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. diff --git a/clang/test/PCH/delayed-template-parsing.cpp b/clang/test/PCH/delayed-template-parsing.cpp new file mode 100644 index 000000000000..b4404c757634 --- /dev/null +++ b/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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits