Meaning of byval?

Duncan wrote:

Hi Alon,

> The docs say "[byval] indicates that the pointer parameter should
> really be passed by value to the function. The attribute implies
> that a hidden copy of the pointee is made between the caller and
> the callee, so the callee is unable to modify the value in the
> callee."
>
> I am not sure what this means though - when I generate code
> from the LLVM assembly, do I need to do anything with byval?

yes, the pointee needs to be passed by-copy, which usually means on the
stack but could mean in a bunch of registers.

> Either in the calling location or in the called function?

The caller does the copy IIRC. If you look at the .s file you should see
it happening.

> I've
> been trying to figure this out from generated LLVM assembly
> and it puzzles me.

You can't really figure it out from LLVM IR. Look at final target assembler
(.s).

Ciao, Duncan.

Thanks Duncan, yes it is indeed much clearer from the x86
assembly. It's passed on the stack, so the copy is done in
the caller, in effect.

It's a little puzzling to me that the unoptimized LLVM
assembly also creates an explicit copy in the assembly
(allocating it & doing a memcpy), but I guess it gets
optimized out later so it doesn't matter.

Best,
  Alon Zakai