[llvm-dev] Force casting a Value*

Dipanjan Das via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 11 11:56:49 PDT 2017


On 11 June 2017 at 11:32, Nikodemus Siivola <nikodemus at random-state.net>
wrote:

> On Sun, Jun 11, 2017 at 7:49 PM, Dipanjan Das via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>>
>>
>> On 11 June 2017 at 07:53, David Blaikie <dblaikie at gmail.com> wrote:
>>
>>> Sounds like you're looking for reinterpret_cast: http://en.cp
>>> preference.com/w/cpp/language/reinterpret_cast
>>>
>>
>> I tried cast<ConstInt>(vo), but that failed at run-time.
>>
>
> That is not the same as reinterpret_cast<int64>(some_value_star).
>

None of the following work.

Value* var_value = reinterpret_cast<intptr_t>(vo);
Value* var_value= reinterpret_cast<uint64_t>(vo);

The following worked, still didn't solve the problem:

Value* var_value = reinterpret_cast<ConstantInt*>(vo);

I can't pass var_value to a function accepting uint64_t. LLVM complains
about broken function call.


> Or better yet, reinterpret_cast<intptr_t>(some_value_star)
>
> http://www.cplusplus.com/reference/cstdint/
>
> Cheers,
>
>   -- nikodemus
>
>
>>
>>
>>>
>>> On Sun, Jun 11, 2017 at 3:06 AM Dipanjan Das via llvm-dev <
>>> llvm-dev at lists.llvm.org> wrote:
>>>
>>>>
>>>> I am trying to cast a Value* irrespective of  its underlying subclass
>>>> to uint64 and pass it on to a method as an argument.
>>>>
>>>> if (StoreInst *store_inst = dyn_cast<StoreInst>(&I)) {
>>>>                     Value* vo = store_inst->getValueOperand();
>>>>                      uint64 value = /* cast vo to unsigned int 64 bit */
>>>>                      func(value);
>>>>                 }
>>>>
>>>> How can I force cast 'vo' to unsigned int?
>>>>
>>>> --
>>>>
>>>> Thanks & Regards,
>>>> Dipanjan
>>>> _______________________________________________
>>>> LLVM Developers mailing list
>>>> llvm-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>>
>>>
>>
>>
>> --
>>
>> Thanks & Regards,
>> Dipanjan
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>


-- 

Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170611/cb8cd62c/attachment.html>


More information about the llvm-dev mailing list