<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87552>87552</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Ocaml] Bindings produce wrong IR for pointers
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kritonios01
      </td>
    </tr>
</table>

<pre>
    Hello all,
I have been working on a compiler in OCaml and I am using the LLVM bindings to compile to LLVM IR.
I believe I have found a bug in OCaml's LLVM bindings. Please find attached a .ml file which when compiled and run produces the file "llvm_ir.ll". Open the file and you will see that in the store instruction, a ptr* type is used which of course is invalid causing llc to fail with:
`error: ptr* is invalid - use ptr instead`
The issue exists both on version 15 and 16 of bindings. Please confirm if this is a bug and what can be done. More generally, I do not see how opaque pointers can be codegened. In C++ when using `PointerType::getUnqual` the pointer is automatically converted to opaque pointer in LLVM 15. This does not seem to be the behaviour in OCaml. Almost all of the bindings produce IR with typed pointers. Please find attached an semantically equivalent C++ file which when compiled and run produces correct LLVM 15 IR using only opaque pointers.
[Archive.zip](https://github.com/llvm/llvm-project/files/14858109/Archive.zip)
I provide here the IR produced by each one for convenience:


OCaml
`; ModuleID = 'program'
source_filename = "program"

%frame = type { ptr }

define void @main(ptr %0) {
main_entry:
  %frame_ptr = alloca %frame, align 8
 %frame_elem_ptr = getelementptr inbounds %frame, %frame* %frame_ptr, i32 0, i32 0
  store ptr %0, ptr* %frame_elem_ptr, align 8
  ret void
}
`


C++
`
; ModuleID = 'program'
source_filename = "program"

%frame = type { ptr }

define void @main(ptr %0) {
main_entry:
  %frame_ptr = alloca %frame, align 8
  %frame_elem_ptr = getelementptr inbounds %frame, ptr %frame_ptr, i32 0, i32 0
  store ptr %0, ptr %frame_elem_ptr, align 8
 ret void
}
`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o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