[llvm] [coroutines] Use DILocation from new storage for hoisted dbg.declare (PR #75104)

Matheus Izvekov via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 00:49:37 PST 2023


mizvekov wrote:

Reproducer:
```sh
clang -cc1 -triple x86_64-pc-windows-msvc -emit-llvm -flto=full -gcodeview -debug-info-kind=constructor -O1 -std=c++20 -Wno-coroutine-missing-unhandled-exception -x c++ test.cpp
```
```C++
namespace std {
template <class = void> struct coroutine_handle {
  static coroutine_handle from_address(void *);
  operator coroutine_handle<>();
  operator bool();
  void *address();
};
template <class _Ret, class...> struct coroutine_traits : _Ret {};
}

struct A {
  bool await_ready() noexcept;
  template <class PromiseType>
  auto await_suspend(std::coroutine_handle<PromiseType>) -> std::coroutine_handle<>;
  void await_resume() noexcept;
};
std::coroutine_handle a;
struct B {
  struct promise_type {
    B get_return_object();
    void return_void();
    A initial_suspend();
    A final_suspend() noexcept;
  };
  ~B() {
    if (auto b = a)
      ;
  }
};
B f() {
  for (;;) {
    A d;
    []() -> B { co_return; }();
    co_await d;
  }
}
```

Produces:
```
mismatched subprogram between llvm.dbg.declare variable and !dbg attachment
  call void @llvm.dbg.declare(metadata ptr %3, metadata !88, metadata !DIExpression(DW_OP_plus_uconst, 18)), !dbg !86
label %coro.init
ptr @"?f@@YA?AUB@@XZ"
!88 = !DILocalVariable(name: "b", scope: !89, file: !5, line: 26, type: !6)
!91 = distinct !DISubprogram(name: "~B", linkageName: "??1B@@QEAA at XZ", scope: !36, file: !5, line: 25, type: !61, scopeLine: 25, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, declaration: !60, retainedNodes: !92)
!86 = !DILocation(line: 30, column: 7, scope: !33)
!33 = distinct !DISubprogram(name: "f", linkageName: "?f@@YA?AUB@@XZ", scope: !5, file: !5, line: 30, type: !34, scopeLine: 30, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !64)
fatal error: error in backend: Broken function
```

https://github.com/llvm/llvm-project/pull/75104


More information about the llvm-commits mailing list