Skip to content

Commit fc1fc50

Browse files
author
Christopher Bazley
committed
Pass unqualified aggregate values through an ellipsis
When an argument has no corresponding parameter type, TCC can carry the qualifiers of a structure or union lvalue into its outgoing copy. On x86-64, passing a const structure on the stack then produces a spurious assignment of read-only location warning. Remove the top-level qualifiers from the aggregate argument value in the path shared by variadic and unprototyped calls. Exercise the copy by passing a const volatile structure and reading it with va_arg.
1 parent 56b7510 commit fc1fc50

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎tests/tests2/153_large_struct_args.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdarg.h>
12
#include <stdio.h>
23

34
/* Struct arguments larger than 16 bytes are copied to the outgoing argument
@@ -11,13 +12,22 @@ int take(struct small s, struct big b)
1112
return (int)s.e + b.tag + b.data[10];
1213
}
1314

15+
static long take_va(int n, ...)
16+
{
17+
va_list ap;
18+
va_start(ap, n);
19+
struct small s = va_arg(ap, struct small);
20+
va_end(ap);
21+
return s.e;
22+
}
23+
1424
int main(void)
1525
{
1626
struct big b = {0};
17-
struct small s = {0};
27+
const volatile struct small s = { .e = 100 };
1828
b.tag = 40;
1929
b.data[10] = 2;
20-
s.e = 100;
2130
printf("%d\n", take(s, b));
31+
printf("%ld\n", take_va(1, s));
2232
return 0;
2333
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
142
2+
100

0 commit comments

Comments
 (0)