llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
308 stars 84 forks source link

[CIR][CodeGen][Bugfix] store fptr of a function with no args #622

Closed gitoleg closed 1 month ago

gitoleg commented 1 month ago

This PR fixes the next bug showed in the example below:

typedef int (*fn_t)();
int get42() { return 42; }

void foo() {
  fn_t f = get42;
}

The function type fn_t is generated as the variadic one due to no arg types listed, this is the codegen feature. And once we store the function pointer to a real function - a pointer to get42 here has the expected i32 ()* type - we get a verification error, so bitcast is needed. The original codegen doesn't have it because of opaque pointers used, and had the bitcast earlier, long time ago:

%f = alloca i32 (...)*
store i32 (...)* bitcast (i32 ()* @get42 to i32 (...)*), i32 (...)** %f