]> git.ipfire.org Git - thirdparty/gcc.git/commit
gimplify: Fix up __builtin_c[lt]zg gimplification [PR122188]
authorJakub Jelinek <jakub@redhat.com>
Wed, 8 Oct 2025 07:58:41 +0000 (09:58 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 8 Oct 2025 07:58:41 +0000 (09:58 +0200)
commitbb22f7d4d63446c9095db32ca013a9b2182df7d9
tree00e530ad5486ed7a6b926caaedb39e03273d5773
parent7fb8339ca3239cc74983b82e4ba89c95b7489209
gimplify: Fix up __builtin_c[lt]zg gimplification [PR122188]

The following testcase ICEs during gimplification.
The problem is that save_expr sometimes doesn't create a SAVE_EXPR but
returns the original complex tree (COND_EXPR) and the code then uses that
tree in 2 different spots without unsharing.  As this is done during
gimplification it wasn't unshared when whole body is unshared and because
gimplification is destructive, the first time we gimplify it we destruct it
and second time we try to gimplify it we ICE on it.
Now, we could replace one a use with unshare_expr (a), but because this
is a gimplification hook, I think easier than trying to create a save_expr
is just gimplify the argument, then we know it is is_gimple_val and so
something without side-effects and can safely use it twice.  That argument
would be the first thing to gimplify after return GS_OK anyway, so it
doesn't change argument sequencing etc.

2025-10-08  Jakub Jelinek  <jakub@redhat.com>

PR c/122188
* c-gimplify.cc (c_gimplify_expr): Gimplify CALL_EXPR_ARG (*expr_p, 0)
instead of calling save_expr on it.

* c-c++-common/pr122188.c: New test.
gcc/c-family/c-gimplify.cc
gcc/testsuite/c-c++-common/pr122188.c [new file with mode: 0644]