[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


            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) {
  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) {
      std::make_pair(Function, PointOfInstantiation));

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();
    } else {
      Inst = PendingLocalImplicitInstantiations.front();

    // Instantiate function definitions
    if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) {
      bool DefinitionRequired = Function->getTemplateSpecializationKind() ==
      InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true,
                                    DefinitionRequired, true);
      if (Function->isDefined())

Possibly the same underlying issue as:

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