This is an archive of the discontinued LLVM Phabricator instance.

Don't emit CFI instructions at the end of a function
ClosedPublic

Authored by aprantl on Apr 19 2017, 2:35 PM.

Details

Summary

When functions are terminated by unreachable instructions, the last
instruction might trigger a CFI instruction to be generated. However,
emitting it would be be illegal since the function (and thus the FDE the CFI is in)
has already ended with the previous instruction.

Darwin's dwarfdump --verify --eh-frame complains about this and the
specification supports this.
Relevant bits from the DWARF 5 standard (6.4 Call Frame Information):

"[The] address_range [field in an FDE]: The number of bytes of
 program instructions described by this entry."
    
"Row creation instructions: [...]
 The new location value is always greater than the current one."

The first quotation implies that a CFI cannot describe a target
address outside of the enclosing FDE's range.

rdar://problem/26244988

Diff Detail

Repository
rL LLVM

Event Timeline

aprantl created this revision.Apr 19 2017, 2:35 PM
MatzeB added inline comments.Apr 19 2017, 3:23 PM
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
941–947 ↗(On Diff #95821)

Should this look ignore MachineInstr::isTransient() instructions in general as they all shouldn't generate any actual machine code.

aprantl updated this revision to Diff 95837.Apr 19 2017, 3:36 PM

Address review feedback. Thanks!

MatzeB accepted this revision.Apr 19 2017, 3:47 PM

LGTM. Though maybe wait a little longer in case there is feedback from someone who actually knows the AsmPrinter.

This revision is now accepted and ready to land.Apr 19 2017, 3:47 PM
This revision was automatically updated to reflect the committed changes.
echristo edited edge metadata.Apr 25 2017, 4:21 PM

(I do know the asm printer and this looks ok to me :)