Reinterpret_cast

suppose I have a function such as function foo(::A);, I’d like to check how it is compiled with @code_llvm foo(a), but I don’t know or care how to create an instance of the class A. Is there a way to achieve that without having to create an instance of A, for instance with a bogus expression as in C++ by reinterpret_cast<A*>(nullptr);

Use the non-macro version:

julia> struct A end; foo(x) = x
foo (generic function with 1 method)

julia> code_llvm(foo, (A,))
;  @ REPL[3]:1 within `foo'
define void @julia_foo_184() {
top:
  ret void
}
3 Likes

The macro @code_llvm is actually just a user-friendly interface to the function code_llvm. This function takes the function and the types as input:

julia> struct A end;

julia> foo(::A) = 1 + 1;

julia> code_llvm(foo, (A,))
;  @ REPL[5]:1 within `foo'
define i64 @julia_foo_179() {
top:
  ret i64 2
}
3 Likes