<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Infinite loop during function instantiation under -fdelayed-template-parsing with 'auto' return type"
href="https://bugs.llvm.org/show_bug.cgi?id=34185">34185</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Infinite loop during function instantiation under -fdelayed-template-parsing with 'auto' return type
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gornishanov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// -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:
<a class="bz_bug_link
bz_status_NEW "
title="NEW - Infinite loop when using -fdelayed-template-parsing, constexpr, and generalized lambdas"
href="show_bug.cgi?id=33561">https://bugs.llvm.org/show_bug.cgi?id=33561</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>