[cfe-dev] Fixed-size argument arrays in LLVM assembly

John McCall rjmccall at apple.com
Wed Feb 13 10:45:36 PST 2013


On Feb 13, 2013, at 9:55 AM, nkavv at physics.auth.gr wrote:
> I've noticed that fixed-size arrays are not always preserved in LLVM assembly.  This happens in the case of procedure argument arrays.

This is just how C works.  Arguments and parameters of array type decay to pointers;  they are not passed by copying the array.

> While an alloca declares the size of fixed-size local arrays (for instance), argument arrays are always accessed as pointers (with getelementptr, which is not intuitive for an LLVM n00b).

Sounds like you ought to learn about getelementptr, then.

> While C (and other languages that share this approach) does not impose any bounds checking, maintaining the sizes may be meaningful for certain targets, e.g. non-programmable hardware.

There is no C-level language requirement at all that the argument actually be an array of that size or greater.

It's vaguely possible that this information might be preserved in clang's DWARF output, but I don't think so.

> 2) If this is not the case, can the LLVM IR (in principle) cope with array arguments without converting them to pointers?

In principle, yes.  In practice, I don't know if the calling-convention lowering code is likely to behave well in the presence of a first-class array argument.

John.



More information about the cfe-dev mailing list