public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects
@ 2023-11-20 14:31 jakub at gcc dot gnu.org
2023-11-20 14:31 ` [Bug middle-end/112639] " jakub at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-11-20 14:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
Bug ID: 112639
Summary: Incorrect handling of __builtin_c[lt]zg argument
side-effects
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
unsigned long long b = 0;
int
foo (void)
{
return __builtin_clzg (b++, __SIZEOF_LONG__ * __CHAR_BIT__);
}
int
bar (void)
{
return __builtin_ctzg (b++, __SIZEOF_LONG__ * __CHAR_BIT__);
}
int
main ()
{
if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ || b != 1)
__builtin_abort ();
if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ - 1 || b != 2)
__builtin_abort ();
if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ - 2 || b != 3)
__builtin_abort ();
b = 0;
if (bar () != __SIZEOF_LONG__ * __CHAR_BIT__ || b != 1)
__builtin_abort ();
if (bar () != 0 || b != 2)
__builtin_abort ();
if (bar () != 1 || b != 3)
__builtin_abort ();
}
is miscompiled.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/112639] Incorrect handling of __builtin_c[lt]zg argument side-effects
2023-11-20 14:31 [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects jakub at gcc dot gnu.org
@ 2023-11-20 14:31 ` jakub at gcc dot gnu.org
2023-11-20 14:37 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-11-20 14:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2023-11-20
Ever confirmed|0 |1
Target Milestone|--- |14.0
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/112639] Incorrect handling of __builtin_c[lt]zg argument side-effects
2023-11-20 14:31 [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects jakub at gcc dot gnu.org
2023-11-20 14:31 ` [Bug middle-end/112639] " jakub at gcc dot gnu.org
@ 2023-11-20 14:37 ` jakub at gcc dot gnu.org
2023-11-21 8:42 ` cvs-commit at gcc dot gnu.org
2024-02-15 9:28 ` jakub at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-11-20 14:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 56650
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56650&action=edit
gcc14-pr112639.patch
Untested fix.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/112639] Incorrect handling of __builtin_c[lt]zg argument side-effects
2023-11-20 14:31 [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects jakub at gcc dot gnu.org
2023-11-20 14:31 ` [Bug middle-end/112639] " jakub at gcc dot gnu.org
2023-11-20 14:37 ` jakub at gcc dot gnu.org
@ 2023-11-21 8:42 ` cvs-commit at gcc dot gnu.org
2024-02-15 9:28 ` jakub at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-21 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:8a8a6d60c670c5153c5109df5fe68deb6fcf466d
commit r14-5638-g8a8a6d60c670c5153c5109df5fe68deb6fcf466d
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Nov 21 09:32:37 2023 +0100
builtins: Fix fold_builtin_query clzg/ctzg side-effects handling [PR112639]
As the testcase shows, I've missed one spot where initially the code thinks
it could use 2 argument IFN_CLZ/IFN_CTZ form, but then verifies it can't
because it doesn't have the right target value and turns it into the
arg0 ? arg1 : .C[LT]Z (arg0)
form. That form evaluates the argument twice though and so needs
save_expr,
which I've missed to call in that case. In other cases where it is known
from the beginning that it will be needed (e.g. the __builtin_clzg case
on types smaller than unsigned int where we'll need to add an addend
to the clz value) or the unsigned __int128 expansion called save_expr
before.
2023-11-21 Jakub Jelinek <jakub@redhat.com>
PR middle-end/112639
* builtins.cc (fold_builtin_bit_query): If arg0 has side-effects,
arg1
is specified but cleared, call save_expr on arg0.
* gcc.dg/torture/pr112639.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/112639] Incorrect handling of __builtin_c[lt]zg argument side-effects
2023-11-20 14:31 [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects jakub at gcc dot gnu.org
` (2 preceding siblings ...)
2023-11-21 8:42 ` cvs-commit at gcc dot gnu.org
@ 2024-02-15 9:28 ` jakub at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-15 9:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-15 9:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-20 14:31 [Bug middle-end/112639] New: Incorrect handling of __builtin_c[lt]zg argument side-effects jakub at gcc dot gnu.org
2023-11-20 14:31 ` [Bug middle-end/112639] " jakub at gcc dot gnu.org
2023-11-20 14:37 ` jakub at gcc dot gnu.org
2023-11-21 8:42 ` cvs-commit at gcc dot gnu.org
2024-02-15 9:28 ` jakub at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).