This is an archive of the discontinued LLVM Phabricator instance.

[XRay] Fix assertion failure on empty machine basic blocks (PR 31424)
ClosedPublic

Authored by dberris on Dec 18 2016, 11:48 PM.

Details

Summary

The original version of the code in XRayInstrumentation.cpp assumed that
functions may not have empty machine basic blocks (or that the first one
couldn't be). This change addresses that by special-casing that specific
situation.

We provide a .mir test-case to make sure we're handling this
appropriately.

Fixes llvm.org/PR31424.

Diff Detail

Repository
rL LLVM

Event Timeline

dberris updated this revision to Diff 81919.Dec 18 2016, 11:48 PM
dberris retitled this revision from to [XRay] Fix assertion failure on empty machine basic blocks (PR 31424).
dberris updated this object.
dberris added a reviewer: chandlerc.
dberris added subscribers: llvm-commits, varno.
chandlerc edited edge metadata.Dec 18 2016, 11:52 PM

Also good to add an IR test case with 'unreachable' just for more coverage of these kinds of edge cases?

lib/CodeGen/XRayInstrumentation.cpp
61–62 ↗(On Diff #81919)

Unrelated formatting change, please land in a separate commit.

93–94 ↗(On Diff #81919)

Ditto.

114–115 ↗(On Diff #81919)

Add a test case for this as well?

136–140 ↗(On Diff #81919)

Why do you care about instrumenting functions which have no instructions in them?

dberris updated this revision to Diff 81922.Dec 19 2016, 12:24 AM
dberris marked 4 inline comments as done.
dberris edited edge metadata.
  • Do not instrument empty functions
  • Add test for an empty function
lib/CodeGen/XRayInstrumentation.cpp
114–115 ↗(On Diff #81919)

I'm not sure how to do that from a .mir properly, but I tried anyway. :)

136–140 ↗(On Diff #81919)

Good point -- mostly because I'm not sure whether the assumption that the first MBB being empty implies that there are no instructions in the rest of the function. I'm happy to ignore this case (maybe because it's when an inlined function is there just for the debug info case).

chandlerc accepted this revision.Dec 19 2016, 12:52 AM
chandlerc edited edge metadata.

LGTM

lib/CodeGen/XRayInstrumentation.cpp
135 ↗(On Diff #81922)

You can use just find_if(MF, ...) -- we have a range based version in the llvm namespace.

This revision is now accepted and ready to land.Dec 19 2016, 12:52 AM
dberris marked an inline comment as done.Dec 19 2016, 1:08 AM

Thanks @chandlerc!

lib/CodeGen/XRayInstrumentation.cpp
135 ↗(On Diff #81922)

Awesome! I keep forgetting that. :)

dberris updated this revision to Diff 81924.Dec 19 2016, 1:09 AM
dberris marked an inline comment as done.
dberris edited edge metadata.
  • Use llvm::find_if instead
This revision was automatically updated to reflect the committed changes.