<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 - [coroutines] Clang emits duplicate debug information for 'this' variable"
   href="https://bugs.llvm.org/show_bug.cgi?id=33492">33492</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[coroutines] Clang emits duplicate debug information for 'this' variable
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eric@efcs.ca
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18654" name="attach_18654" title="reproducer.cpp">attachment 18654</a> <a href="attachment.cgi?id=18654&action=edit" title="reproducer.cpp">[details]</a></span>
reproducer.cpp

Currently, under certain conditions, Clang/LLVM will hit the following
assertion when processing coroutine code.

clang-5.0: /home/eric/full-llvm/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h:131:
void llvm::DbgVariable::addMMIEntry(const llvm::DbgVariable &): Assertion
`V.Var == Var && "conflicting variable"' failed.

I've only been able to hit this assertion when passing `-g -O2` (See attached
reproducer, compile as "clang++ -std=c++11 -fcoroutines-ts -g -O2 test.cpp").

A little investigation suggests that it's the 'this' variable which is being
duplicated. I have no clue why this is happening.

The relevant bit of the LLVM IR that clang emits appears to be this:

!175 = !DISubprogram(name: "unhandled_exception", linkageName:
"_ZN4func12promise_type19unhandled_exceptionEv", scope: !119, file: !1, line:
106, type: !173, isLocal: false, isDefinition: false, scopeLine: 106, flags:
DIFlagPrototyped, isOptimized: true)
[...]
!178 = !DILocalVariable(name: "this", arg: 1, scope: !179, type: !183, flags:
DIFlagArtificial | DIFlagObjectPointer)
!179 = distinct !DISubprogram(name: "return_void", linkageName:
"_ZN4func12promise_type11return_voidEv", scope: !35, file: !1, line: 105, type:
!93, isLocal: false, isDefinition: true, scopeLine: 105, flags:
DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !92, variables:
!180)
!180 = !{!181}
!181 = !DILocalVariable(name: "this", arg: 1, scope: !179, type: !182, flags:
DIFlagArtificial | DIFlagObjectPointer)
[...]</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>