[PATCH] D141381: [codegen] Store address of indirect arguments on the stack

Felipe de Azevedo Piovezan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 06:29:35 PST 2023


fdeazeve created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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:

1. "Big enough" trivial structures passed by value under the ARM ABI.
2. Structures that are non-trivial for the purposes of call (as per the Itanium ABI) when passed by value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141381

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141381.487780.patch
Type: text/x-patch
Size: 5266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230110/753c6457/attachment.bin>


More information about the cfe-commits mailing list