llvm.trap() from -O1 optimization


This is likely to be some small issue, but I am unable to figure out
the solution. The following code, when run through `opt' with the -O1
flag, replaces the call to foo() with a call to llvm.trap() followed
by an `unreachable' instruction.

You’re not using the right calling convention here: you need call arm_aapcs_vfpcc void @foo().

Instcombine detects the mismatch, knows it is incorrect, and thus optimize away the call with “undefined behavior”-like code.

You probably also want the triple "armv7-unknown-linux-gnueabihf".
Straight away that would make your arm_aapcs_vfpcc annotations
redundant because that's the default.

Also, plain "gnu" is a really weird old ABI that LLVM doesn't actually
support so you could easily get strange behaviour from the backend not
dealing with it properly. And even if the backend gets it right
somehow, your surrounding libraries are almost certainly not "gnu".