]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix ICEs from invalid atomic compound assignment [PR98195, PR117755]
authorJoseph Myers <josmyers@redhat.com>
Tue, 26 Nov 2024 03:25:44 +0000 (03:25 +0000)
committerJoseph Myers <josmyers@redhat.com>
Tue, 26 Nov 2024 03:25:44 +0000 (03:25 +0000)
commit980929bdb80f1a1490caab5acc6d9740e0f9b539
tree3088efff6ca14b33fa4af06dd9172a0f42aecbfa
parentf89c7916b971d4535d1ae206222ae0e9ff5175f0
c: Fix ICEs from invalid atomic compound assignment [PR98195, PR117755]

As reported in bug 98195, there are ICEs from an _Atomic compound
assignment with an incomplete type on the RHS, arising from an invalid
temporary being created with such a type.  As reported in bug 117755,
there are also (different) ICEs in cases with complete types where the
binary operation itself is invalid, when inside a nested function,
arising from a temporary being created for the RHS, but then not used
because the binary operation returns error_mark_node, resulting in the
temporary not appearing in a TARGET_EXPR, never getting its
DECL_CONTEXT set by the gimplifier and eventually resulting in an ICE
in nested function processing (trying to find a function context for
the temporary) as a result.

Fix the first ICE with an earlier check for a complete type for the
RHS of an assignment so the problematic temporary is never created for
an incomplete type (which changes the error message three existing
tests get for that case; the new message seems as good as the old
one).  Fix the second ICE by ensuring that once a temporary has been
created, it always gets a corresponding TARGET_EXPR even on error.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/98195
PR c/117755

gcc/c/
* c-typeck.cc (build_atomic_assign): Always create a TARGET_EXPR
for newval even in case of error from binary operation.
(build_modify_expr): Check early for incomplete type of rhs.

gcc/testsuite/
* gcc.dg/pr98195-1.c, gcc.dg/pr117755-1.c: New tests.
* gcc.dg/noncompile/20020207-1.c, gcc.dg/pr14765-1.c,
objc.dg/method-11.m: Update expected error messages.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/noncompile/20020207-1.c
gcc/testsuite/gcc.dg/pr117755-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr14765-1.c
gcc/testsuite/gcc.dg/pr98195-1.c [new file with mode: 0644]
gcc/testsuite/objc.dg/method-11.m