This is an archive of the discontinued LLVM Phabricator instance.

IR: Teach GlobalIndirectSymbol::getBaseObject() to handle more kinds of expressions.
ClosedPublic

Authored by pcc on Jul 22 2019, 2:17 PM.

Details

Summary

For aliases, any expression that lowers at the MC level to global_object or
global_object+constant is valid at the object file level. getBaseObject()
should return a result if the aliasee ends up being of that form even if
the IR used to produce it is somewhat unconventional.

Note that this is different from what stripInBoundsOffsets() and that family
of functions is doing. Those functions are concerned about semantic properties
of IR, whereas here we only care about the lowering result.

Therefore reimplement getBaseObject() in a way that matches the lowering
result. This fixes a crash when producing a summary for aliases such as
that in the included test case.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Jul 22 2019, 2:17 PM
tejohnson added inline comments.Jul 23 2019, 9:23 AM
llvm/lib/IR/Globals.cpp
436 ↗(On Diff #211189)

Why is this needed? Is it possible to have cycles in the indirection?

441 ↗(On Diff #211189)

Is it possible for the other operand of the add (or subtract below) to be something that disqualifies this from analysis, i.e. that needs checking?

llvm/test/Linker/comdat8.ll
6 ↗(On Diff #211189)

Why does this test change?

pcc marked 3 inline comments as done.Jul 23 2019, 10:01 AM
pcc added inline comments.
llvm/lib/IR/Globals.cpp
436 ↗(On Diff #211189)

Yes, in invalid IR. Without this we hang when reading this IR instead of erroring in the verifier. See llvm/test/Verifier/alias.ll for one example.

441 ↗(On Diff #211189)

Yes, A+B where both A and B refer to GlobalObjects would mean we need to return nullptr here. I'll add a case for that. For subtract we're already checking both operands.

llvm/test/Linker/comdat8.ll
6 ↗(On Diff #211189)

Because now we can analyze the aliasee, so it needed to be replaced with something that doesn't refer to a base object. See http://llvm-cs.pcc.me.uk/lib/Linker/LinkModules.cpp#134 for the call that now succeeds.

pcc updated this revision to Diff 211540.Jul 24 2019, 9:59 AM
  • Check both operands of an add; follow GlobalAliases only
This revision is now accepted and ready to land.Jul 24 2019, 12:07 PM
This revision was automatically updated to reflect the committed changes.