Suppose I have the following set up in my IR file:
Some main function that uses some api FUNCTION_CALLER to fork and call some FUNCTION
define dso_local noundef i32 @main() #0 !dbg !265 {
entry:
(...)
%a = alloca i32, align 4
(...)
call void @llvm.dbg.declare(metadata ptr %a, metadata !267, metadata !DIExpression()), !dbg !268
(...)
call void (ptr, i32, ...) @__FUNCTION_CALLER(..., ptr @.FUNCTION., ptr %a, ...), !dbg !275
(...)
with relevant variable metadata:
!267 = !DILocalVariable(name: "a", scope: !265, file: !2, line: 23, type: !17)
!268 = !DILocation(line: 23, column: 7, scope: !265)
And FUNCTION looks like:
define internal void @.FUNCTION.(..., ptr noundefalign 4 dereferenceable(4) %a, ...) #2 !dbg !302 {
entry:
(...)
%a.addr = alloca ptr, align 8
(...)
store ptr %a, ptr %a.addr, align 8
call void @llvm.dbg.declare(metadata ptr %a.addr, metadata !308, metadata !DIExpression()), ...
... !dbg !306
(...)
also with relevant variable metadata:
!308 = !DILocalVariable(name: "a", arg: 3, scope: !302, type: !284, flags: DIFlagArtificial)
Now, assume using C++ LLVM API, inside of FUNCTION
I am investigating the Instruction* @llvm.dbg.declare
. If I want to take a look at the metadata of %a.addr
, the second argument, this brings me to !308
. However, this doesn’t contain the information I want which is line number and column number in source declaration — this only shows up in the main
function @llvm.dbg.declare
because it’s not a pointer.
Is there a way, given the argument %a.addr
with metadata at !308
, I can trace it back to the for %a
with metadata at !267/!268
at the original @llvm.dbg.declare
?
To reiterate, how can I sort of dereference %a.addr
to arrive at metadata for %a
in my LLVM Pass, so I can get its line and column information?
I have tried something like going from %a.addr
-> store ptr %a, ptr %a.addr, align 8
-> %a
and then trace it back through FUNCTION
‘s arguments, but this I’m not sure if this even works.
Sa’di Thamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.