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

Daniel Liew daniel.liew at imperial.ac.uk
Thu Aug 15 04:44:17 PDT 2013


Hi,

This is quite a simple question so hopefully it's easy to answer.

I was looking at the documentation for the alloca instruction (
http://llvm.org/docs/LangRef.html#alloca-instruction ) and something is
unclear to me. The given syntax is...

<result> = alloca <type>[, <ty> <NumElements>][, align <alignment>]
; yields {type*}:result

And the documentation states "The ‘alloca‘ instruction allocates
sizeof(<type>)*NumElements bytes of memory on the runtime stack".

It is not stated how the "<ty>" type is used as we are told the type of
result is type* and sizeof(<type>)*NumElements is the amount of memory
so from my perspective it looks like <ty> is never used which would seem
to make stating i32 twice in the following example redundant

%ptr = alloca i32, i32 4

My guess is that if <NumElements> is specified then the amount of memory
actually allocated would be sizeof(<ty>)*NumElements (instead of
sizeof(<type>)*NumElements) but the pointer type of result is <type>. Is
that correct?

If not could someone please clarify this?


Thanks,
Dan Liew.






More information about the llvm-dev mailing list