* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow)
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
@ 2022-09-05 9:11 ` jakub at gcc dot gnu.org
2022-09-05 9:11 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-09-05 9:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dmalcolm at gcc dot gnu.org,
| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I certainly see a valgrind diagnostics on it:
valgrind ./cc1 -quiet pr106830.c
==2461995== Memcheck, a memory error detector
==2461995== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==2461995== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==2461995== Command: ./cc1 -quiet pr106830.c
==2461995==
pr106830.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
1 | foo0_u16_0() {
| ^~~~~~~~~~
pr106830.c: In function ‘foo0_u16_0’:
pr106830.c:2:14: warning: integer constant is so large that it is unsigned
2 | (__int128)(18302628885633695743 << 4) ^ 0;
| ^~~~~~~~~~~~~~~~~~~~
==2461995== Conditional jump or move depends on uninitialised value(s)
==2461995== at 0xAFCE3D: parser_build_binary_op(unsigned int, tree_code,
c_expr, c_expr) (c-typeck.cc:3992)
==2461995== by 0xB4ABA2: c_parser_binary_expression(c_parser*, c_expr*,
tree_node*) (c-parser.cc:8083)
==2461995== by 0xB486A3: c_parser_conditional_expression(c_parser*, c_expr*,
tree_node*) (c-parser.cc:7651)
==2461995== by 0xB48308: c_parser_expr_no_commas(c_parser*, c_expr*,
tree_node*) (c-parser.cc:7565)
so pressumably arg1.m_decimal is uninitialized.
I see there various spots at which m_decimal can remain uninitialized, in this
case e.g.
c_parser_cast_expression
ret.value = c_cast_expr (cast_loc, type_name, expr.value);
if (ret.value && expr.value)
set_c_expr_source_range (&ret, cast_loc, expr.get_finish ());
ret.original_code = ERROR_MARK;
ret.original_type = NULL;
return ret;
doesn't set it. I'd search for all assignments to original_code in c/*.cc and
added m_decimal = 0 next to it if it doesn't have it yet.
Another case is check_for_xor_used_as_pow implementation, if it only works on
UHWIs, then
/* Only complain if both args are non-negative integer constants. */
if (!(TREE_CODE (lhs_val) == INTEGER_CST
&& tree_int_cst_sgn (lhs_val) >= 0))
return;
if (!(TREE_CODE (rhs_val) == INTEGER_CST
&& tree_int_cst_sgn (rhs_val) >= 0))
return;
should actually be
if (!tree_fits_uhwi_p (lhs_val) || !tree_fits_uhwi_p (rhs_val))
return;
so that for larger values we return immediately.
As for lhs we only care about 2 and 10, it doesn't hurt at least for lhs_val.
For rhs, you'd need to use wide_ints otherwise but then the question is how to
print that...
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow)
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
2022-09-05 9:11 ` [Bug c/106830] " jakub at gcc dot gnu.org
@ 2022-09-05 9:11 ` jakub at gcc dot gnu.org
2022-09-05 10:12 ` [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a marxin at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-09-05 9:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
Ever confirmed|0 |1
Priority|P3 |P1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-09-05
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
2022-09-05 9:11 ` [Bug c/106830] " jakub at gcc dot gnu.org
2022-09-05 9:11 ` jakub at gcc dot gnu.org
@ 2022-09-05 10:12 ` marxin at gcc dot gnu.org
2022-09-06 5:06 ` zsojka at seznam dot cz
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-09-05 10:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
Summary|[13 Regression] ICE: in |[13 Regression] ICE: in
|tree_to_uhwi, at |tree_to_uhwi, at
|tree.cc:6392 (from |tree.cc:6392 (from
|check_for_xor_used_as_pow) |check_for_xor_used_as_pow)
| |since
| |r13-2386-gbedfca647a9e9c1a
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r13-2386-gbedfca647a9e9c1a.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
` (2 preceding siblings ...)
2022-09-05 10:12 ` [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a marxin at gcc dot gnu.org
@ 2022-09-06 5:06 ` zsojka at seznam dot cz
2022-09-06 15:58 ` dmalcolm at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2022-09-06 5:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
--- Comment #3 from Zdenek Sojka <zsojka at seznam dot cz> ---
(In reply to Jakub Jelinek from comment #1)
> I certainly see a valgrind diagnostics on it:
> valgrind ./cc1 -quiet pr106830.c
> ==2461995== Memcheck, a memory error detector
> ==2461995== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
> ==2461995== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright
> info
> ==2461995== Command: ./cc1 -quiet pr106830.c
> ==2461995==
> pr106830.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
> 1 | foo0_u16_0() {
> | ^~~~~~~~~~
> pr106830.c: In function ‘foo0_u16_0’:
> pr106830.c:2:14: warning: integer constant is so large that it is unsigned
> 2 | (__int128)(18302628885633695743 << 4) ^ 0;
> | ^~~~~~~~~~~~~~~~~~~~
> ==2461995== Conditional jump or move depends on uninitialised value(s)
> ==2461995== at 0xAFCE3D: parser_build_binary_op(unsigned int, tree_code,
> c_expr, c_expr) (c-typeck.cc:3992)
> ==2461995== by 0xB4ABA2: c_parser_binary_expression(c_parser*, c_expr*,
> tree_node*) (c-parser.cc:8083)
> ==2461995== by 0xB486A3: c_parser_conditional_expression(c_parser*,
> c_expr*, tree_node*) (c-parser.cc:7651)
> ==2461995== by 0xB48308: c_parser_expr_no_commas(c_parser*, c_expr*,
> tree_node*) (c-parser.cc:7565)
>
> so pressumably arg1.m_decimal is uninitialized.
>
Ah right, my fault, I forgot to add --trace-children=yes, and run valgrind on
the gcc binary instead... thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
` (3 preceding siblings ...)
2022-09-06 5:06 ` zsojka at seznam dot cz
@ 2022-09-06 15:58 ` dmalcolm at gcc dot gnu.org
2022-09-07 1:24 ` dmalcolm at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-09-06 15:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |dmalcolm at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this; sorry about the breakage.
I'm working on a fix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
` (4 preceding siblings ...)
2022-09-06 15:58 ` dmalcolm at gcc dot gnu.org
@ 2022-09-07 1:24 ` dmalcolm at gcc dot gnu.org
2022-09-22 12:36 ` cvs-commit at gcc dot gnu.org
2022-09-22 12:41 ` dmalcolm at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-09-07 1:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |WAITING
Keywords| |patch
--- Comment #5 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Patch posted for review here:
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601179.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
` (5 preceding siblings ...)
2022-09-07 1:24 ` dmalcolm at gcc dot gnu.org
@ 2022-09-22 12:36 ` cvs-commit at gcc dot gnu.org
2022-09-22 12:41 ` dmalcolm at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-22 12:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:
https://gcc.gnu.org/g:86254629b636db579616befde49022f098af8148
commit r13-2773-g86254629b636db579616befde49022f098af8148
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu Sep 22 08:35:26 2022 -0400
c: fix uninitialized c_expr::m_decimal [PR106830]
I added c_expr::m_decimal in r13-2386-gbedfca647a9e9c1a as part of the
implementation of -Wxor-used-as-pow, but I missed various places where
the field needed to be initialized.
Fixed thusly.
gcc/c-family/ChangeLog:
PR c/106830
* c-warn.cc (check_for_xor_used_as_pow): Don't try checking
values that don't fit in uhwi.
gcc/c/ChangeLog:
PR c/106830
* c-parser.cc (c_parser_initelt): Initialize m_decimal.
(c_parser_cast_expression): Likewise.
(c_parser_alignof_expression): Likewise.
(c_parser_postfix_expression_after_paren_type): Likewise.
(c_parser_postfix_expression_after_primary): Likewise.
(c_parser_expression): Likewise.
(c_parser_omp_variable_list): Likewise.
(c_parser_transaction_expression): Likewise.
* c-tree.h (c_expr::set_error): Likewise.
* c-typeck.cc (c_expr_sizeof_expr): Likewise.
(parser_build_unary_op): Likewise.
(parser_build_binary_op): Likewise.
(digest_init): Likewise.
(pop_init_level): Likewise.
* gimple-parser.cc (c_parser_gimple_call_internal): Likewise.
gcc/testsuite/ChangeLog:
PR c/106830
* gcc.dg/Wxor-used-as-pow-pr106830.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/106830] [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) since r13-2386-gbedfca647a9e9c1a
2022-09-05 5:28 [Bug c/106830] New: [13 Regression] ICE: in tree_to_uhwi, at tree.cc:6392 (from check_for_xor_used_as_pow) zsojka at seznam dot cz
` (6 preceding siblings ...)
2022-09-22 12:36 ` cvs-commit at gcc dot gnu.org
@ 2022-09-22 12:41 ` dmalcolm at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-09-22 12:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106830
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to CVS Commits from comment #6)
> The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:
>
> https://gcc.gnu.org/g:86254629b636db579616befde49022f098af8148
>
> commit r13-2773-g86254629b636db579616befde49022f098af8148
Should be fixed by this commit; I've verified the original reproducer using
valgrind. Sorry again about the breakage.
^ permalink raw reply [flat|nested] 9+ messages in thread