[LLVMdev] Exact meaning of byval

Matthijs Kooijman matthijs at stdin.nl
Fri Jul 4 02:21:29 PDT 2008


Hi,

after working with llvm for a while, I'm still a little confused with the
meaning of the 'byval' attribute. From the langref:

"This 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. This attribute is only valid on llvm pointer arguments. It is
generally used to pass structs and arrays by value, but is also valid on
scalars (even though this is silly)."

I'm particularly confused by the "between the caller and the callee" part. The
way I see this, the responsibility for the copying should be with either the
caller or the callee, not somewhere in between. In particular, I think byval
could either mean:
	a) The callee is not allowed to modify the argument. If the original code
	modifies the argument, the callee should make a copy and modify that
	instead.
	b) The caller will always pass in a copy of the object, which the callee is
	free to modify and will be thrown away afterwards.

In both cases, it seems that byval argument must always be a valid pointer.

From the code, I suspect that option b is the case. I would think that option
a is the better option, since it can prevent copies when the callee doesn't
even modify the value (but this stems from C ABI or something?)


Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080704/196ab827/attachment.sig>


More information about the llvm-dev mailing list