[llvm-bugs] [Bug 39762] New: OCaml binding Llvm.value_name always returns empty string
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 22 19:53:49 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39762
Bug ID: 39762
Summary: OCaml binding Llvm.value_name always returns empty
string
Product: libraries
Version: 6.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: taquangtrungvn at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
I followed the tutorial https://www.wzdftpd.net/blog/ocaml-llvm-02.html to
build an analyzer for LLVM bitcode.
However, the OCaml binding function Llvm.value_name always returns an empty
string. This is unexpected since the function Llvm.string_of_llvalue returns
the correct string-representation of an Llvm value.
I'm using LLVM 6.0 and test with two versions of OCaml: 4.06.1 and 4.07.0.
Here are the steps to reproduce the bug:
1. Create a file hello.c
#include<stdio.h>
int main(int arg) {
int x = arg;
if (x>1)
return 1;
else
return 2;
assert(1>2);
}
2. Compile it to bitcode: clang -c hello.c -emit-llvm
3. Here is my OCaml code to print the value name of the bitcode file hello.bc
let print_bitcode file =
let llctx = Llvm.global_context () in
let llmem = Llvm.MemoryBuffer.of_file file in
let llm = Llvm_bitreader.parse_bitcode llctx llmem in
Llvm.iter_functions (fun func ->
Llvm.iter_blocks (fun blk ->
Llvm.iter_instrs(fun inst ->
print_endline ("Value Name: '" ^ (Llvm.value_name inst) ^ "'");
print_endline ("Value Str: '" ^ (Llvm.string_of_llvalue inst) ^
"'\n");
) blk
) func
) llm
4. Here is the output:
Value Name: ''
Value Str: ' %2 = alloca i32, align 4'
Value Name: ''
Value Str: ' %3 = alloca i32, align 4'
Value Name: ''
Value Str: ' %4 = alloca i32, align 4'
Value Name: ''
Value Str: ' store i32 0, i32* %2, align 4'
Value Name: ''
Value Str: ' store i32 %0, i32* %3, align 4'
Value Name: ''
Value Str: ' %5 = load i32, i32* %3, align 4'
Value Name: ''
Value Str: ' store i32 %5, i32* %4, align 4'
Value Name: ''
Value Str: ' %6 = load i32, i32* %4, align 4'
Value Name: ''
Value Str: ' %7 = icmp sgt i32 %6, 1'
Value Name: ''
Value Str: ' br i1 %7, label %8, label %9'
Value Name: ''
Value Str: ' store i32 1, i32* %2, align 4'
Value Name: ''
Value Str: ' br label %10'
Value Name: ''
Value Str: ' store i32 2, i32* %2, align 4'
Value Name: ''
Value Str: ' br label %10'
Value Name: ''
Value Str: ' %11 = load i32, i32* %2, align 4'
Value Name: ''
Value Str: ' ret i32 %11'
5. As can be seen above, all the Value Name is empty.
So, I wonder if this is a bug of the binding function Llvm.value_name,
or did I make some mistakes in my code?
Thank you!
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181123/11f54a3a/attachment-0001.html>
More information about the llvm-bugs
mailing list