I am working with LLVM 3.4 and want to obtain the line number information of source file from IR. The IR is generated from simple c code with Clang. I want to obtain the line number in source c file from the line in IR body.
I tried this -
But, the result stored/printed is always 0. I don't know how to obtain line number in the source from LLVM IR.
My Source C file is -
#include <stdio.h>
int main()
{
int i;
int inbuf[100];
int outbuf[100];
for(i = 0; i < 100; ++i)
inbuf[i] ^= outbuf[i];
inbuf[1] += 402;
inbuf[6] += 107;
inbuf[97] += 231;
for(i = 0; i < 100; ++i)
{
inbuf[i] += outbuf[i];
}
inbuf[47] += 312;
//print-statements
for (i=0;i<100;i++) {
printf("inbuf[%d] = %d\n",i,inbuf[i]);
}
return 0;
Command Used- ~/llvm/build/Release+Asserts/bin/clang -O3 -fno-unroll-loops -fno-vectorize -fno-slp-vectorize -S -emit-llvm sample.c -o sample.ll
Thanks!
To get line number information into .ll file your must specify both -O0
and -g
flags for clang.
http://llvm.org/docs/SourceLevelDebugging.html#debugging-optimized-code
Line numbers are stored in specialized metadata nodes.
http://llvm.org/docs/LangRef.html#specialized-metadata-nodes
So the full command line must look like this:
~/llvm/build/Release+Asserts/bin/clang -O0 -g -S -emit-llvm sample.c -o sample.ll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With