[llvm-dev] LLVM IR source line error
Muhui Jiang via llvm-dev
llvm-dev at lists.llvm.org
Tue May 29 05:25:21 PDT 2018
Hi
I am using LLVM to help me do some code analysis. I wrote a LLVM Function
Pass to help me to generate some information. I use the code below to get
the source line information for every instruction.
for (BasicBlock &BB : F){
for(Instruction &I: BB){
DILocation* Loc = I.getDebugLoc().get();
unsigned Line = Loc->getLine()
}
}
I think the function's first block's first instruction's source line should
be the beginning of the function. Most of the functions inside the binary
follow the rules. However, I found the file system.h in the coreutils-8.28
has a function like below:
611 static inline void
612 emit_backup_suffix_note (void)
613 {
614 fputs (_("\
615 \n\
616 The backup suffix is '~', unless set with --suffix or
SIMPLE_BACKUP_SUFFIX.\n\
617 The version control method may be selected via the --backup option or
through\n\
618 the VERSION_CONTROL environment variable. Here are the values:\n\
619 \n\
620 "), stdout);
621 fputs (_("\
622 none, off never make backups (even if --backup is given)\n\
623 numbered, t make numbered backups\n\
624 existing, nil numbered if numbered backups exist, simple
otherwise\n\
625 simple, never always make simple backups\n\
626 "), stdout);
627 }
When analysis this function. The first block's first instruction's source
line is 614 rather than 612 or 613. Is it a bug or any other meaning
resulting in such case. Below is the IR. The first IR's source line if 614.
%call = call i8* @gettext(i8* getelementptr inbounds ([221 x i8], [221 x
i8]* @.str.42, i32 0 , i32 0)) #12, !dbg !1295
%0 = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 4, !dbg
!1295
%call1 = call i32 @fputs_unlocked(i8* %call, %struct._IO_FILE* %0), !dbg
!1295
%call2 = call i8* @gettext(i8* getelementptr inbounds ([222 x i8], [222 x
i8]* @.str.43, i32 0, i32 0)) #12, !dbg !1296
%1 = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 4, !dbg
!1296
%call3 = call i32 @fputs_unlocked(i8* %call2, %struct._IO_FILE* %1), !dbg
!1296
ret void, !dbg !1297
Can anyone help me or give me some suggestions? Many Thanks
Regards
Muhui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180529/5a5a2dbe/attachment.html>
More information about the llvm-dev
mailing list