llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.84k stars 11.47k forks source link

Incorrect debug info for C++20 coroutine resume and destroy functions #57321

Open vogelsgesang opened 2 years ago

vogelsgesang commented 2 years ago

It seems that the

In https://godbolt.org/z/qM1Eqjhrh, we see

define dso_local void @_Z17my_generator_funcv(ptr nocapture writeonly sret(%struct.int_generator) align 8 %0) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 !dbg !115 {
[...]
define internal fastcc void @_Z17my_generator_funcv.resume(ptr noalias nonnull align 8 dereferenceable(24) %0) #5 personality ptr @__gxx_personality_v0 !dbg !167 {
[...]
define internal fastcc void @_Z17my_generator_funcv.destroy(ptr noalias nonnull align 8 dereferenceable(24) %0) #5 personality ptr @__gxx_personality_v0 !dbg !198 {

and the corresponding debug info

!115 = distinct !DISubprogram(name: "my_generator_func", linkageName: "_Z17my_generator_funcv", scope: !6, file: !6, line: 28, type: !116, scopeLine: 28, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !118)
!167 = distinct !DISubprogram(name: "my_generator_func", linkageName: "_Z17my_generator_funcv", scope: !6, file: !6, line: 28, type: !116, scopeLine: 28, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !168)
!198 = distinct !DISubprogram(name: "my_generator_func", linkageName: "_Z17my_generator_funcv", scope: !6, file: !6, line: 28, type: !116, scopeLine: 28, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !199)

Note how all 3 functions are assigned the same name and linkage name. Afaik, assigning the same linkageName is invalid. Assigning the same name is valid, but surprising. We should probably distinguish the functions by assigning different names.

Furthermore, all 3 routines are defined to have type !116, which is defined as

!116 = !DISubroutineType(types: !117)
!117 = !{!7}
!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "int_generator", file: !6, line: 5, size: 64, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !8, identifier: "_ZTS13int_generator")

which indicates that all 3 functions (also the resume and destroy functions) take no parameters and return an int_generator. However, this is only correct for the ramp function.

llvmbot commented 2 years ago

@llvm/issue-subscribers-c-20

llvmbot commented 2 years ago

@llvm/issue-subscribers-coroutines

vogelsgesang commented 2 years ago

just stumbled across the related https://reviews.llvm.org/D97345

llvmbot commented 2 years ago

@llvm/issue-subscribers-debuginfo