<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - OCaml binding Llvm.value_name always returns empty string"
   href="https://bugs.llvm.org/show_bug.cgi?id=39762">39762</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OCaml binding Llvm.value_name always returns empty string
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>taquangtrungvn@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I followed the tutorial <a href="https://www.wzdftpd.net/blog/ocaml-llvm-02.html">https://www.wzdftpd.net/blog/ocaml-llvm-02.html</a> 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!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>