JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
826 stars 141 forks source link

Special-case the type of the C main() function #99

Closed hikari-no-yume closed 3 years ago

hikari-no-yume commented 3 years ago

A fix for part of https://github.com/JuliaComputing/llvm-cbe/issues/98, as discussed there.

I hope the code is self-explanatory.

hikari-no-yume commented 3 years ago

Trivial example of what this change does:

; Function Attrs: norecurse nounwind readnone ssp uwtable
define i32 @main(i32 %0, i8** nocapture readnone %1) local_unnamed_addr #0 {
  ret i32 0
}
int main(int argc, char ** argv) {
  uint32_t _1 = (uint32_t)argc;
  uint8_t** _2 = (uint8_t**)argv;
  return 0;
}

Without this change, it looks like:

uint32_t main(uint32_t _1, uint8_t** _2) {
  return 0;
}

Because the argument types are wrong, GCC and Clang refuse to compile it without special flags. They also warn about the wrong return type.