This is an archive of the discontinued LLVM Phabricator instance.

Don't codegen an unreachable return block
ClosedPublic

Authored by rjmccall on Jan 22 2019, 4:33 PM.

Details

Summary

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.

Diff Detail

Event Timeline

bmoody created this revision.Jan 22 2019, 4:33 PM
rjmccall accepted this revision.Jan 23 2019, 10:02 PM

Sure, I have no objection to doing this at this point.

This revision is now accepted and ready to land.Jan 23 2019, 10:02 PM

Great, I don't have commit access so you're welcome to commit on my behalf. Thanks!

Ping! Any chance you could commit this on my behalf? Otherwise I can try the mailing list.

Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2019, 6:24 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
rjmccall commandeered this revision.Apr 10 2019, 10:01 AM
rjmccall edited reviewers, added: bmoody; removed: rjmccall.

Committed as r358104, thanks for your patience.

This revision now requires review to proceed.Apr 10 2019, 10:01 AM
craig.topper resigned from this revision.May 6 2019, 11:18 PM
bmoody accepted this revision.Mar 29 2020, 1:51 AM
This revision is now accepted and ready to land.Mar 29 2020, 1:51 AM
nikic edited the summary of this revision. (Show Details)Mar 29 2020, 2:39 AM
bmoody closed this revision.Mar 29 2020, 5:57 PM