[LLVMdev] Clarification between <type> and <ty> for alloca instruction

Daniel Liew daniel.liew at imperial.ac.uk
Thu Aug 15 08:30:00 PDT 2013


On 15/08/13 16:12, Tim Northover wrote:
>> I've obviously being playing with C++ too long because my 
>> instinct immediately told me that dynamically sized arrays on
>> the stack are't allowed but apparently that's fine for C99 (g++
>> also seems fine with this is you don't specify -pedantic)
> 
> It's all fun and games until someone decides to evaluate
> sizeof(arr). ;-)
> 
> I think a more limited form is coming to C++11, by the way.
> 
>> Interesting thanks for clarifying. Now you've raised another
>> question. I'm interested to know how you know that this is how
>> overflow behaves for this particular instruction. I can imagine
>> several different behaviours (I'm assuming NumElements is
>> unsigned but that doesn't seem to be specified)
>> 
>> - wrap around overflow. In which case 257 = 255 + 2 so result
>> would be 2
> 
> This is what happens (wraparound/truncation/whatever). But I think
> 256 -> 0, 257 -> 1.

Oops yes you're completely right. I didn't think about that through
very well ( I was doing % 255 in my head instead of % 256).

Do you think it would be wise to document the meaning of <ty> for the
alloca instruction or do you think that it is clear enough and that it
is my unfamiliarity with LLVM IR that caused my confusion?

Thanks,
Dan.




More information about the llvm-dev mailing list