go-llvm icon indicating copy to clipboard operation
go-llvm copied to clipboard

Add support for opaque pointers and structs

Open rj45 opened this issue 2 years ago • 4 comments
trafficstars

If you call ElementType() on an opaque pointer, it causes a segfault. Unfortunately there was no way to know you had an opaque pointer on your hands before this change, so there was no way to know that calling ElementType() on the type that was a PointerTypeKind would crash.

This change introduces a IsPointerOpaque() method to check for opaque pointers. While I was at it, I noticed there was no way to check for opaque structs as well, so I added that. I also tried calling Subtypes() and noticed it causes an index out of range panic when there is no subtypes, so I fixed that too.

When I uploaded the fix, I noticed that LLVM 14 doesn't have the method to check for opaque pointers, which is odd because opaque pointers have been a thing since 2015.... at any rate, it was simple enough to add a back port for it, though it took a couple tries to get the CI to pass.

rj45 avatar Aug 27 '23 13:08 rj45

I'm not sure what's up with the CI. I hope it's a temporary failure.

aykevl avatar Aug 29 '23 21:08 aykevl

To use the bundled libc++ please add the following LDFLAGS: LDFLAGS="-L$HOMEBREW_PREFIX/opt/llvm/lib/c++ -Wl,-rpath,$HOMEBREW_PREFIX/opt/llvm/lib/c++"

Looks like this needs to be done to pass CI on macOS...

deadprogram avatar Aug 30 '23 05:08 deadprogram

Seemed like python was failing to install in the CI.... I tried a fix to force python to install, but now it's saying that python is already installed. So it must have been updated in the base image. So I reverted my "fix" since it shouldn't be necessary.

rj45 avatar Sep 02 '23 12:09 rj45

The fix for opaque structs seems necessary indeed (and is unrelated to opaque pointers: opaque structs are simply structs without a body and are part of LLVM for years).

I'm not so sure about specific support for opaque pointers. They were last used by default in LLVM 14, and have been removed entirely in LLVM 17. So I'd say that new code should assume all pointers are opaque. Or do you still need to compile against LLVM 14 for some reason?

This is what LLVMPointerTypeIsOpaque looks like in LLVM 17:

LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty) {
  return true;
}

aykevl avatar Oct 01 '23 13:10 aykevl