public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant
@ 2021-12-15  4:16 f.heckenbach@fh-soft.de
  2021-12-18  8:49 ` [Bug tree-optimization/103725] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: f.heckenbach@fh-soft.de @ 2021-12-15  4:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

            Bug ID: 103725
           Summary: warning: assuming signed overflow does not occur when
                    simplifying conditional to constant
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.c  
int d = 0, b = 8, a[8][8];

struct S
{
  int c;
};

void foo (int *c)
{
  if (b >= 0)
    {
      if (*c) d = *c;
      if (*c < 0) d = *c;
    }
}

int main ()
{
  struct S i = { 0 };
  for (int e = 0; e < 11; e++, i.c++)
    {
      d = a[i.c >= b ? i.c - b : i.c][i.c + 1 >= b ? i.c + 1 - b : i.c + 1];
      foo (&i.c);
    }
}
% gcc -O2 -Wstrict-overflow test.c 
test.c: In function 'main':
test.c:22:66: warning: assuming signed overflow does not occur when simplifying
conditional to constant [-Wstrict-overflow]
   22 |       d = a[i.c >= b ? i.c - b : i.c][i.c + 1 >= b ? i.c + 1 - b : i.c
+ 1];
      |                                      
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~

This is not the same as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103724 (in
fact, that was a collateral damage while bisecting this one), though they may
be internally related since this warning also depends only many circumstances,
plus a few more (like, there must be a struct, a plain integer won't cause the
warning; and e and i.c must be distinct although they count in lockstep).

To a user, the warning is worrying since none of the visible conditionals
should be able to be simplified to a constant.

What seems to be happening, as far as I can tell from looking at the generated
code, is that GCC internally splits cases and then simplifies conditions in one
of them (since i.c >= b implies i.c + 1 >= b, unless signed overflow which
seems to explain the cause of the warning).

But the user normally doesn't see this and gets the impression one of their
conditions is wrongly simplified. This, and the fact that the warning doesn't
seem very robust in the first place (i.e. depends on many circumstances), seems
to make the whole "-Wstrict-overflow" option a bit less than useful, IMHO.

I get another spurious warning like this in a more complex piece of my code,
and it also seems to depend on many circumstances, so I can't easily provide a
reproducible example, but it may be a similar situation like this one in the
end. (And these were the only ones I got, i.e. it didn't actually help me find
a real bug in my code.)

Since it also doesn't seem possible to suppress the warning locally with a
pragma (since it's generated at a late stage, I suppose), I think I'll have to
disable it again. (I had re-enabled it after I heard
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70455 was fixed. It may work
better now, but still too mysterious to actually help me.)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
@ 2021-12-18  8:49 ` pinskia at gcc dot gnu.org
  2021-12-18  8:57 ` [Bug tree-optimization/103725] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-18  8:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
#1  0x00000000018fa008 in simplify_using_ranges::vrp_evaluate_conditional
(this=0x7fffffffd510, code=LE_EXPR, op0=<ssa_name 0x7ffff73ac048 2>,
op1=<ssa_name 0x7ffff73ac168 3>, stmt=<gimple_cond 0x7ffff7391d20>) at
/home/apinski/src/upstream-gcc/gcc/gcc/vr-values.c:2383
#2  0x00000000015e5791 in dom_jt_simplifier::simplify (this=0x7fffffffd920,
stmt=<gimple_cond 0x7ffff73c6460>, within_stmt=<gimple_cond 0x7ffff7391d20>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-dom.c:689
#3  0x0000000001756fb4 in jump_threader::simplify_control_stmt_condition_1
(this=0x7fffffffd940, e=<edge 0x7ffff73af090 (4 -> 5)>, stmt=<gimple_cond
0x7ffff7391d20>, op0=<ssa_name 0x7ffff73ac048 2>, cond_code=LE_EXPR,
op1=<ssa_name 0x7ffff73ac168 3>, limit=4)
    at /home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-threadedge.c:637
#4  0x0000000001756574 in jump_threader::simplify_control_stmt_condition
(this=0x7fffffffd940, e=<edge 0x7ffff73af090 (4 -> 5)>, stmt=<gimple_cond
0x7ffff7391d20>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-threadedge.c:385
#5  0x0000000001757b2a in jump_threader::thread_through_normal_block
(this=0x7fffffffd940, Python Exception <class 'gdb.error'> There is no member
or method named m_vecpfx.:
path=0x4282240, e=<edge 0x7ffff73af090 (4 -> 5)>, visited=0x7fffffffd760) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-threadedge.c:951
#6  0x00000000017580c5 in jump_threader::thread_across_edge
(this=0x7fffffffd940, e=<edge 0x7ffff73af090 (4 -> 5)>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-threadedge.c:1080
#7  0x00000000017585b8 in jump_threader::thread_outgoing_edges
(this=0x7fffffffd940, bb=<basic_block 0x7ffff724e680 (4)>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-threadedge.c:1206
#8  0x00000000015e7a3d in dom_opt_dom_walker::after_dom_children
(this=0x7fffffffd9b0, bb=<basic_block 0x7ffff724e680 (4)>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree-ssa-dom.c:1579
#9  0x0000000002841322 in dom_walker::walk (this=0x7fffffffd9b0,
bb=<basic_block 0x7ffff724e680 (4)>) at
/home/apinski/src/upstream-gcc/gcc/gcc/domwalk.c:352

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [9/10/11/12 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
  2021-12-18  8:49 ` [Bug tree-optimization/103725] " pinskia at gcc dot gnu.org
@ 2021-12-18  8:57 ` pinskia at gcc dot gnu.org
  2022-01-04 11:26 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-18  8:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |7.1.0, 7.5.0
      Known to fail|                            |10.1.0, 8.1.0
   Last reconfirmed|                            |2021-12-18
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
            Summary|warning: assuming signed    |[9/10/11/12 Regression]
                   |overflow does not occur     |warning: assuming signed
                   |when simplifying            |overflow does not occur
                   |conditional to constant     |when simplifying
                   |                            |conditional to constant

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---


int t = i.c >= b ? i.c - b : i.c;
int t1 = i.c + 1 >= b ? i.c + 1 - b : i.c + 1;

I think the warning is happening when jump threading the above in DOM.
I don't think the warning makes sense really because we are inside a loop after
all.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [9/10/11/12 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
  2021-12-18  8:49 ` [Bug tree-optimization/103725] " pinskia at gcc dot gnu.org
  2021-12-18  8:57 ` [Bug tree-optimization/103725] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
@ 2022-01-04 11:26 ` rguenth at gcc dot gnu.org
  2022-01-18 14:01 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-04 11:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.5

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
We've mostly pruned all the singed overflow diagnostics when touching stuff but
some are still there ...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [9/10/11/12 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2022-01-04 11:26 ` rguenth at gcc dot gnu.org
@ 2022-01-18 14:01 ` rguenth at gcc dot gnu.org
  2022-05-27  9:46 ` [Bug tree-optimization/103725] [10/11/12/13 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-18 14:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [10/11/12/13 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (3 preceding siblings ...)
  2022-01-18 14:01 ` rguenth at gcc dot gnu.org
@ 2022-05-27  9:46 ` rguenth at gcc dot gnu.org
  2022-06-28 10:47 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [10/11/12/13 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (4 preceding siblings ...)
  2022-05-27  9:46 ` [Bug tree-optimization/103725] [10/11/12/13 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:47 ` jakub at gcc dot gnu.org
  2023-03-10 19:58 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [10/11/12/13 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (5 preceding siblings ...)
  2022-06-28 10:47 ` jakub at gcc dot gnu.org
@ 2023-03-10 19:58 ` pinskia at gcc dot gnu.org
  2023-07-07 10:41 ` [Bug tree-optimization/103725] [11/12/13/14 " rguenth at gcc dot gnu.org
  2024-03-11  4:26 ` [Bug tree-optimization/103725] [11/12 " law at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-10 19:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Seems to be fixed on the trunk ....

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [11/12/13/14 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (6 preceding siblings ...)
  2023-03-10 19:58 ` pinskia at gcc dot gnu.org
@ 2023-07-07 10:41 ` rguenth at gcc dot gnu.org
  2024-03-11  4:26 ` [Bug tree-optimization/103725] [11/12 " law at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/103725] [11/12 Regression] warning: assuming signed overflow does not occur when simplifying conditional to constant
  2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
                   ` (7 preceding siblings ...)
  2023-07-07 10:41 ` [Bug tree-optimization/103725] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-03-11  4:26 ` law at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-11  4:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103725

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
            Summary|[11/12/13/14 Regression]    |[11/12 Regression] warning:
                   |warning: assuming signed    |assuming signed overflow
                   |overflow does not occur     |does not occur when
                   |when simplifying            |simplifying conditional to
                   |conditional to constant     |constant

--- Comment #8 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Per c#6.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-03-11  4:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15  4:16 [Bug c/103725] New: warning: assuming signed overflow does not occur when simplifying conditional to constant f.heckenbach@fh-soft.de
2021-12-18  8:49 ` [Bug tree-optimization/103725] " pinskia at gcc dot gnu.org
2021-12-18  8:57 ` [Bug tree-optimization/103725] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-04 11:26 ` rguenth at gcc dot gnu.org
2022-01-18 14:01 ` rguenth at gcc dot gnu.org
2022-05-27  9:46 ` [Bug tree-optimization/103725] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:47 ` jakub at gcc dot gnu.org
2023-03-10 19:58 ` pinskia at gcc dot gnu.org
2023-07-07 10:41 ` [Bug tree-optimization/103725] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-11  4:26 ` [Bug tree-optimization/103725] [11/12 " law 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).