[llvm-bugs] [Bug 34185] New: Infinite loop during function instantiation under -fdelayed-template-parsing with 'auto' return type
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 14 10:42:07 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34185
Bug ID: 34185
Summary: Infinite loop during function instantiation under
-fdelayed-template-parsing with 'auto' return type
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: gornishanov at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// -cc1 -std=c++14 -fdelayed-template-parsing repro.cpp
template <typename Promise> struct coroutine_handle {
Promise &promise() const { return *reinterpret_cast<Promise *>(nullptr); }
};
template <typename Promise> auto GetCurrenPromise() {
struct Awaiter {
void await_suspend(coroutine_handle<Promise> h) {
h.promise();
}
};
return Awaiter{};
}
void foo() { auto& p = GetCurrenPromise<int>(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ends up in an infinite loop. While instantiating local class Awaiter in
GetCurrentPromise, we recurse to instantiate a coroutine_handle::promise()
which is marked as "isLateTemplateParsed()" which causes
InstantiateFunctionDefinition to bail out due to this code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Postpone late parsed template instantiations.
if (PatternDecl->isLateTemplateParsed() &&
!LateTemplateParser) {
Function->setInstantiationIsPending(true);
PendingInstantiations.push_back(
std::make_pair(Function, PointOfInstantiation));
return;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PerformPendingInstantiations fetches it and asks InstantiateFunctionDefinition
to instantiate it, it pushes it back into pending instantiations and
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void Sema::PerformPendingInstantiations(bool LocalOnly) {
while (!PendingLocalImplicitInstantiations.empty() ||
(!LocalOnly && !PendingInstantiations.empty())) {
PendingImplicitInstantiation Inst;
if (PendingLocalImplicitInstantiations.empty()) {
Inst = PendingInstantiations.front();
PendingInstantiations.pop_front();
} else {
Inst = PendingLocalImplicitInstantiations.front();
PendingLocalImplicitInstantiations.pop_front();
}
// Instantiate function definitions
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) {
bool DefinitionRequired = Function->getTemplateSpecializationKind() ==
TSK_ExplicitInstantiationDefinition;
InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true,
DefinitionRequired, true);
if (Function->isDefined())
Function->setInstantiationIsPending(false);
continue;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Possibly the same underlying issue as:
https://bugs.llvm.org/show_bug.cgi?id=33561
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170814/3c32d4ba/attachment.html>
More information about the llvm-bugs
mailing list