This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Fix DwarfExpression::addConstantFP for float on big-endian
ClosedPublic

Authored by bjope on Aug 20 2020, 2:43 AM.

Details

Summary

The byte swapping, when dealing with 4 byte (float) FP constants
in DwarfExpression::addConstantFP, added in commit ef8992b9f0189005
was not correct. It always performed byte swapping using an
uint64_t value. When dealing with 4 byte values the 4 interesting
bytes ended up in the big end of the uint64_t, but later we emitted
the 4 bytes at the little end. So we ended up with zeroes being
emitted and faulty debug information.

This patch simplifies things a bit, IMHO. Using the APInt
representation throughout the function, instead of looking at
the internal representation using getRawBytes and without using
reinterpret_cast etc. And using API.byteSwap() should result in
correct byte swapping independent of APInt being 4 or 8 bytes.

Diff Detail

Event Timeline

bjope created this revision.Aug 20 2020, 2:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2020, 2:43 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
bjope requested review of this revision.Aug 20 2020, 2:43 AM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 20 2020, 2:49 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
bjope added a comment.Aug 20 2020, 2:53 AM

I do not have any upstream test case for this, but got failures in our downstream testing.

Looks like no test was added for 4-byte float + big-endian as part of the original patch. Wouldn't hurt if someone would add such a test case. I just focused on fixing the bug here.

Thanks @bjope for catching this bug! I do not have big-endian machine so it must've got un-noticed(test case for 4 bytes float was written and tested/verified on x86 machine).
But I got your point, I'll see if I can add a hand written test case to address this situation.