[cfe-commits] implicit sign/bitwidth conversions during array indexing?

Ted Kremenek kremenek at apple.com
Mon Nov 17 09:49:25 PST 2008


On Nov 15, 2008, at 10:28 AM, Chris Lattner wrote:

> On Nov 13, 2008, at 7:41 PM, Ted Kremenek wrote:
>>> Is this the rule:
>>> - if the bitwidth of E2 is the same as the pointer, do the  
>>> arithmetic.
>>> - if the bitwidth of E2 is different from the pointer, trunc or  
>>> ext it to the same width of the pointer. Signed-ness affects the  
>>> ext operation. Then do the arithmetic.
>>
>> I'm not certain.  Note that the 'long long' value 'k' was not  
>> truncated.  Is this a Sema bug, or is this the correct behavior?   
>> For this target LongLongWidth is 64, the bit width for 'int' is 32,  
>> and the bit width for a pointer is (I believe) 32 bits as well.
>
> This is correct for Sema, and as others pointed out, codegen does  
> the truncation.  Overflow is undefined for pointers, so truncating  
> the index to the size of the pointer is safe to do,  Zhongxing's  
> rules above should work great!

My question is whether or not Sema should insert an implicit cast here  
from long long to int?  It seems strange that there is an implicit  
cast from short to int but not from long long to int.



More information about the cfe-commits mailing list