Skip to content

Commit 2c2148d

Browse files
authored
[C2y] Add documentation to conform to WG14 N3262; NFC (#98146)
This paper is about whether a copy of a va_list object which was not produced by calling va_copy is valid to use or not. While this may work on some targets, we explicitly document it as undefined behavior for all targets so there's not confusion as to when it's valid or not. It's not a burden for a user to use va_copy explicitly.
1 parent 9d10172 commit 2c2148d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3977,7 +3977,10 @@ standard library ``<stdarg.h>`` header:
39773977
39783978
* ``__builtin_va_list``
39793979
3980-
A predefined typedef for the target-specific ``va_list`` type.
3980+
A predefined typedef for the target-specific ``va_list`` type. It is undefined
3981+
behavior to use a byte-wise copy of this type produced by calling ``memcpy``,
3982+
``memmove``, or similar. Valid explicit copies are only produced by calling
3983+
``va_copy`` or ``__builtin_va_copy``.
39813984
39823985
* ``void __builtin_va_start(__builtin_va_list list, <parameter-name>)``
39833986

clang/test/C/C2y/n3262.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
2+
// expected-no-diagnostics
3+
4+
/* WG14 N3262: Yes
5+
* Usability of a byte-wise copy of va_list
6+
*
7+
* NB: Clang explicitly documents this as being undefined behavior. A
8+
* diagnostic is produced for some targets but not for others for assignment or
9+
* initialization, but no diagnostic is possible to produce for use with memcpy
10+
* in the general case, nor with a manual bytewise copy via a for loop.
11+
*
12+
* Therefore, nothing is tested in this file; it serves as a reminder that we
13+
* validated our documentation against the paper. See
14+
* clang/docs/LanguageExtensions.rst for more details.
15+
*
16+
* FIXME: it would be nice to add ubsan support for recognizing when an invalid
17+
* copy is made and diagnosing on copy (or on use of the copied va_list).
18+
*/
19+
20+
int main() {}

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ <h2 id="c2y">C2y implementation status</h2>
12901290
<tr>
12911291
<td>Usability of a byte-wise copy of va_list</td>
12921292
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3262.pdf">N3262</a></td>
1293-
<td class="unknown" align="center">Unknown</td>
1293+
<td class="full" align="center">Yes</td>
12941294
</tr>
12951295
<tr>
12961296
<td>alignof of an incomplete array type</td>

0 commit comments

Comments
 (0)