This is an archive of the discontinued LLVM Phabricator instance.

[libunwind] Add casts to avoid warnings about implicit conversions losing precision
ClosedPublic

Authored by mstorsjo on Jan 20 2019, 1:35 PM.

Details

Summary

This fixes warnings like these:

DwarfInstructions.hpp:85:25: warning: implicit conversion

loses integer precision: 'uint64_t' (aka 'unsigned long long') to
'libunwind::DwarfInstructions<libunwind::LocalAddressSpace,
libunwind::Registers_arm>::pint_t' (aka 'unsigned int')
[-Wshorten-64-to-32]

DwarfInstructions.hpp:88:25: warning: implicit conversion

loses integer precision: 'uint64_t' (aka 'unsigned long long') to
'libunwind::DwarfInstructions<libunwind::LocalAddressSpace,
libunwind::Registers_arm>::pint_t' (aka 'unsigned int')
[-Wshorten-64-to-32]

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jan 20 2019, 1:35 PM

I'm not really familiar with this code -- can you quickly explain why it's OK to lose precision here? Mostly for my education.

I'm not really familiar with this code -- can you quickly explain why it's OK to lose precision here? Mostly for my education.

The LocalAddressSpace class has got a getRegister method that returns uint64_t, while this method returns a variable sized to the actual size of registers on the current architecture. I.e. this fixes warnings on 32 bit architectures.

ldionne accepted this revision.Jan 22 2019, 8:30 AM

I'm not really familiar with this code -- can you quickly explain why it's OK to lose precision here? Mostly for my education.

The LocalAddressSpace class has got a getRegister method that returns uint64_t, while this method returns a variable sized to the actual size of registers on the current architecture. I.e. this fixes warnings on 32 bit architectures.

I guess my question could have been rephrased as: why doesn't LocalAddressSpace::getRegister return a uint32_t on 32 bit architectures, but that's not useful because you might just as well always return a 64 bit value, which is larger than needed in the worst case. I see why that's the right place to put this cast now.

LGTM.

This revision is now accepted and ready to land.Jan 22 2019, 8:30 AM

I guess my question could have been rephrased as: why doesn't LocalAddressSpace::getRegister return a uint32_t on 32 bit architectures, but that's not useful because you might just as well always return a 64 bit value, which is larger than needed in the worst case. I see why that's the right place to put this cast now.

Well, that might also be a valid way to fix it - but it's a much larger and potentially riskier endeavour. This patch just confirms to the compiler that the code currently does behave as intended in this regard, as it has worked so far.

This revision was automatically updated to reflect the committed changes.