[llvm-commits] [PATCH 1/2] Fix Casting

David Blaikie dblaikie at gmail.com
Wed Jan 9 15:11:17 PST 2013


On Wed, Jan 9, 2013 at 3:05 PM,  <dag at cray.com> wrote:
> David Greene <dag at cray.com> writes:
>
>> Do proper casting to eliminate a const-away-cast compiler warning.
>> ---
>>  llvm/lib/ExecutionEngine/ExecutionEngine.cpp |    3 ++-
>>  1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
>> index ef5f589..6f71ffb 100644
>> --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
>> +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
>> @@ -893,7 +893,8 @@ void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
>>  /// from Src into IntVal, which is assumed to be wide enough and to hold zero.
>>  static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
>>    assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
>> -  uint8_t *Dst = (uint8_t *)IntVal.getRawData();
>> +  uint8_t *Dst = reinterpret_cast<uint8_t *>(
>> +                   const_cast<uint64_t *>(IntVal.getRawData()));
>>
>>    if (sys::isLittleEndianHost())
>>      // Little-endian host - the destination must be ordered from LSB to MSB.
>
> Ping?  I have a whole bunch of these (~40) for llvm and clang.  I didn't
> want to flood the commits list with each one, they all basically do the
> same kind of thing.

Especially with const cast changes I'd like to use this as an
opportunity to consider whether the warning is actually telling us
something useful, rarther than just something to work around/silence.

Should APInt have a getRawData() non-const function that returns a
non-const uint64_t*?
Or should APInt friend this function?

Any alternatives people have in mind?



More information about the llvm-commits mailing list