[PATCH] D57072: Don't codegen an unreachable return block

Brad Moody via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 22 16:34:01 PST 2019


bmoody created this revision.
bmoody added reviewers: craig.topper, dberris, rjmccall.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D57072

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/unreachable-ret.c
  test/OpenMP/parallel_reduction_codegen.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57072.182994.patch
Type: text/x-patch
Size: 3214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190123/44ea68b4/attachment.bin>


More information about the cfe-commits mailing list