With codegen prior to this patch, truly indirect arguments -- i.e.
those that are not byval -- can have their debug information lost even
at O0. Because indirect arguments are passed by pointer, and this
pointer is likely placed in a register as per the function call ABI,
debug information is lost as soon as the register gets clobbered.
This patch solves the issue by storing the address of the parameter on
the stack, using a similar strategy employed when C++ references are
passed. In other words, this patch changes codegen from:
define @foo(ptr %arg) { call void @llvm.dbg.declare(%arg, [...], metadata !DIExpression())
To:
define @foo(ptr %arg) { %ptr_storage = alloca ptr store ptr %arg, ptr %ptr_storage call void @llvm.dbg.declare(%ptr_storage, [...], metadata !DIExpression(DW_OP_deref))
Some common cases where this may happen with C or C++ function calls:
- "Big enough" trivial structures passed by value under the ARM ABI.
- Structures that are non-trivial for the purposes of call (as per the Itanium ABI) when passed by value.
FWIW I used a const bool here to match the style already present in this class