clang crashes when it compiles a member function or a lambda is marked as "naked":
struct S {
__attribute__((naked)) S() {}
}
To fix this bug, this patch defines a function that cleans up the naked function removing all allocas and their users and all basic blocks except the entry block. Also, it makes changes so that, if a non-void function is marked as naked, llvm.trap isn't inserted into the function even if it doesn't have a return statement.
This isn't the right approach. Look at Function::dropAllReferences and try modelling this code on that. This does a lot of unnecessary RAUW when we can just null out all operands and delete all instructions except for the inline asm CallInst.