[clang] [C2y] Add documentation to conform to WG14 N3262; NFC (PR #98146)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 06:28:29 PDT 2024


AaronBallman wrote:

> The pointer values in a specific `va_list` can and often do change when you call `va_arg`, but I am not aware of any targets where they do not always point to the same regions. In every ABI I've ever seen, `va_list` contains a pointer to the stack argument area, and those pointers _must_ point there because the stack argument area cannot be either copied or relocated. `va_list` may also contain one or more pointers to separate "spill areas" where the callee is required to spill certain argument registers, which it generally does in its prologue. In theory, a compiler could produce multiple copies of that spill area, or an ABI could require it to be copied by `va_copy` or even allocated on the heap. However, there's no good reason to do either of those things: the `va_list` can never validly escape the variadic function because of the limitation on the stack argument area, and so the spill area might as well also go in a unique location on the stack.

Ah! Thank you for the explanation, that makes a lot of sense.

> I have no objection to requiring va_copy and documenting primitive copies as undefined behavior. It is the easiest thing to do, and we can clearly revisit it later if we want.

Thank you for the clarification. So you're happy with the current state of the PR, or are there some changes you'd like to see made?

https://github.com/llvm/llvm-project/pull/98146


More information about the cfe-commits mailing list