This patch adds a check at the end of CodeGenFunction::FinishFunction to delete the return block if it isn't reachable.
Without this patch applied the code generated for the test cases is:
define void @f1() { entry: call void @abort() unreachable return: ; No predecessors! ret void } define i8* @f2() { entry: %retval = alloca i8*, align 8 call void @abort() unreachable return: ; No predecessors! %0 = load i8*, i8** %retval, align 8 ret i8* %0 }
This sort-of addresses the FIXME in CodeGenFunction::EmitReturnBlock:
// FIXME: We are at an unreachable point, there is no reason to emit the block // unless it has uses. However, we still need a place to put the debug // region.end for now.
I'm not sure if this FIXME still applies with this patch - it's not clear if the intent is to avoid generating the unreachable code in the first place, rather than generating it and then deleting it. Seems like it would complicate the rest of the codegen to avoid generating it in the first place.