]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix ICE when using va_arg with arrays [PR97986]
authorMartin Uecker <uecker@tugraz.at>
Fri, 31 Oct 2025 15:10:40 +0000 (16:10 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Sat, 1 Nov 2025 06:59:27 +0000 (07:59 +0100)
commit5175ef7f7577a1ef4151f306161a1dab904f23bb
treee5539a5c69613164457e83d2670f589e8e6053b5
parent806b229561f5380c00057c16bc1644dbf58cfa9b
c: Fix ICE when using va_arg with arrays [PR97986]

When array type is passed to va_arg, this is undefined behavior.
Emit a warning, and insert a run-time trap after evaluating side effects,
but return the correct type for sizeof / typeof.  For C90 a VLA is an
error.

PR c/97986

gcc/c/ChangeLog:
* c-parser.cc (c_parser_postfix_expression): Adapt.
* c-tree.h (c_build_va_arg): Adapt prototype.
* c-typeck.cc (c_build_va_arg): Handle UB.

gcc/testsuite/ChangeLog:
* gcc.dg/pr97986-1.c: New test.
* gcc.dg/pr97986-2.c: New test.
gcc/c/c-parser.cc
gcc/c/c-tree.h
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr97986-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr97986-2.c [new file with mode: 0644]