[llvm-commits] [PATCH] Handle negative values in StringRef::getAsInteger(unsigned Radix, APInt &).

Michael Spencer bigcheesegs at gmail.com
Fri Mar 9 17:01:50 PST 2012


On Tue, Feb 21, 2012 at 8:15 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Feb 16, 2012, at 2:45 PM, Michael Spencer wrote:
>
>> On Thu, Feb 16, 2012 at 8:20 AM, Chris Lattner <clattner at apple.com> wrote:
>>>
>>> On Feb 15, 2012, at 4:25 PM, Michael Spencer wrote:
>>>
>>>> I have a use case for this in lld.
>>>
>>>
>>> This is sorta strange to me, how about adding an APSInt overload that allows negative (also weird) or a new getAsSignedInteger method (probably better)?
>>>
>>> -Chris
>>
>> There is already precedent in the other StringRef::getAsInteger
>> functions to accept negative values. I believe the interface should be
>> uniform.
>>
>> All I actually need is uint64_t and int64_t, however, these are
>> unsigned long and long on my platform (x86-64 Linux), and thus don't
>> match any of the overloads.
>>
>> Would it be better for me to just cleanup the overload set?
>
> I'd prefer you to clean up the overload set, but do what you think is best.  Thanks!
>
> -Chris

Attached is a patch that does this. I chose to go with templates
because it reduced the amount of repeated code. There is also a test
that checks all the boundaries for each size both positive and
negative (for signed values).

- Michael Spencer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getAsInteger.patch
Type: application/octet-stream
Size: 8858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120309/bbd1c958/attachment.obj>


More information about the llvm-commits mailing list