This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Fix support for casts in ctors.
ClosedPublic

Authored by mtrofin on Apr 2 2018, 9:59 PM.

Details

Summary

Fixing an issue where initializations of globals where constructors use
casts were silently translated to 0-initialization.

Diff Detail

Repository
rL LLVM

Event Timeline

mtrofin created this revision.Apr 2 2018, 9:59 PM
evgeny777 added inline comments.Apr 4 2018, 12:53 AM
lib/Transforms/Utils/Evaluator.cpp
208 ↗(On Diff #140737)

It looks like we can get into the same trouble when evaluating GEP as well. So probably move this to getInitializer() ?

test/Transforms/GlobalOpt/static-const-bitcast.ll
1 ↗(On Diff #140737)

Can you make it a bit shorter? For instance clang generated metadata is not need for test case.

mtrofin updated this revision to Diff 141275.Apr 5 2018, 9:01 PM
  • Reduced testcase
mtrofin marked an inline comment as done.Apr 5 2018, 9:28 PM
mtrofin added inline comments.
lib/Transforms/Utils/Evaluator.cpp
208 ↗(On Diff #140737)

That's what I thought, too, but I'm having trouble producing a testcase. Replacing the bitcast here with a GEP (and performing the necessary adjustments) "just works".

evgeny777 accepted this revision.Apr 6 2018, 4:17 AM

LGTM with nit.

lib/Transforms/Utils/Evaluator.cpp
211 ↗(On Diff #141275)

Please change if .. else to ternary operator:

auto *I = (MM != MutatedMemory.end) ? MM->second : getInitializer(CE->getOperand(0));
if (I)
  ConstantFoldLoadThroughBitcast(I, ...);
208 ↗(On Diff #140737)

Well it looks like the GEP case is handled in the very beginning of ComputeLoadResult, so nothing really should be done with it

This revision is now accepted and ready to land.Apr 6 2018, 4:17 AM
mtrofin updated this revision to Diff 141362.Apr 6 2018, 8:54 AM
  • Reduced testcase
  • Using ternary operator.
mtrofin marked an inline comment as done.Apr 6 2018, 8:55 AM
This revision was automatically updated to reflect the committed changes.