public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
       [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
@ 2006-11-26 19:27 ` manu at gcc dot gnu dot org
  2006-12-09  1:10 ` patchapp at dberlin dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2006-11-26 19:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2006-11-26 19:27 -------
(In reply to comment #3)
> (In reply to comment #2)
> > The problem is that we reset TREE_OVERFLOW:
> 
> It would seem it overflows incremented, and underflow's decremented,
> only a terminal non-zero count would represent an over/underflow for
> addition/subtraction, (as an intermediate over/underflow is not observable)?
> 

No. 1 - INT_MAX is not underflow or overflow. 
For example:
int
f2 (void)
{
  return INT_MAX + 1 - 1;
}

gives also two "integer overflow in expression" warnings.

Actually, I think the problem is that somewhere TREE_OVERFLOW() is set whenever
TREE_CONSTANT_OVERFLOW() is 1. After the first warning is emitted,
TREE_OVERFLOW() is set to 0 but TREE_CONSTANT_OVERFLOW() remains 1. When the
next part of the expression is handled TREE_OVERFLOW() is set again because
TREE_CONSTANT_OVERFLOW is still 1, so the warning is emitted a second time.

For example:

  return INT_MAX + 1 - 1 + 1 - 1 + 1 - 1;

generates 6 warnings. Is this the desired behaviour?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
       [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
  2006-11-26 19:27 ` [Bug c/19978] overflow in expression of constants should not cause multiple warnings manu at gcc dot gnu dot org
@ 2006-12-09  1:10 ` patchapp at dberlin dot org
  2007-01-05 21:57 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: patchapp at dberlin dot org @ 2006-12-09  1:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from patchapp at dberlin dot org  2006-12-09 01:10 -------
Subject: Bug number PR c/19978

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00588.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
       [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
  2006-11-26 19:27 ` [Bug c/19978] overflow in expression of constants should not cause multiple warnings manu at gcc dot gnu dot org
  2006-12-09  1:10 ` patchapp at dberlin dot org
@ 2007-01-05 21:57 ` manu at gcc dot gnu dot org
  2007-01-06  9:34 ` manu at gcc dot gnu dot org
  2007-01-06 15:04 ` schlie at comcast dot net
  4 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-05 21:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2007-01-05 21:57 -------
Subject: Bug 19978

Author: manu
Date: Fri Jan  5 21:57:01 2007
New Revision: 120505

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120505
Log:
2007-01-05  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

        PR c/19978
        * tree.h (TREE_OVERFLOW_P): New.
        * c-typeck.c (parser_build_unary_op): Warn only if result
        overflowed and operands did not.
        (parser_build_binary_op): Likewise.
        (convert_for_assignment): Remove redundant overflow_warning.
        * c-common.c (overflow_warning): Don't check or set TREE_OVERFLOW.

cp/
        * semantics.c (finish_unary_op_expr): Warn only if result
        overflowed and operands did not.

testsuite/
        * gcc.dg/multiple-overflow-warn-1.c: New.
        * gcc.dg/multiple-overflow-warn-2.c: New.
        * gcc.dg/overflow-warn-6.c: New.
        * g++.dg/warn/multiple-overflow-warn-1.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-1.C
    trunk/gcc/testsuite/gcc.dg/multiple-overflow-warn-1.c
    trunk/gcc/testsuite/gcc.dg/multiple-overflow-warn-2.c
    trunk/gcc/testsuite/gcc.dg/overflow-warn-6.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.h


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
       [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2007-01-05 21:57 ` manu at gcc dot gnu dot org
@ 2007-01-06  9:34 ` manu at gcc dot gnu dot org
  2007-01-06 15:04 ` schlie at comcast dot net
  4 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-06  9:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from manu at gcc dot gnu dot org  2007-01-06 09:34 -------
Fixed in mainline.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
       [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2007-01-06  9:34 ` manu at gcc dot gnu dot org
@ 2007-01-06 15:04 ` schlie at comcast dot net
  4 siblings, 0 replies; 8+ messages in thread
From: schlie at comcast dot net @ 2007-01-06 15:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from schlie at comcast dot net  2007-01-06 15:04 -------
It seems that an overflow warning should be generated if an overflowed value
is utilized or results from an expression evaluation between sequence ponts?
Thereby:

x = INT_MAX + 2 - 2 ; // warning x may overflow.

z = (y = x +1, y - 2)  ; // warning y may overflow, warning z may overflow.

if (z < INT_MAX) {<something>} // warning if may overflow.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
  2005-02-15 22:54 [Bug c/19978] New: " jsm28 at gcc dot gnu dot org
  2005-02-16  3:29 ` [Bug c/19978] " pinskia at gcc dot gnu dot org
  2005-02-17 14:34 ` pinskia at gcc dot gnu dot org
@ 2005-02-18 11:04 ` schlie at comcast dot net
  2 siblings, 0 replies; 8+ messages in thread
From: schlie at comcast dot net @ 2005-02-18 11:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-02-17 23:37 -------
(In reply to comment #2)
> The problem is that we reset TREE_OVERFLOW:

It would seem it overflows incremented, and underflow's decremented,
only a terminal non-zero count would represent an over/underflow for
addition/subtraction, (as an intermediate over/underflow is not observable)?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
  2005-02-15 22:54 [Bug c/19978] New: " jsm28 at gcc dot gnu dot org
  2005-02-16  3:29 ` [Bug c/19978] " pinskia at gcc dot gnu dot org
@ 2005-02-17 14:34 ` pinskia at gcc dot gnu dot org
  2005-02-18 11:04 ` schlie at comcast dot net
  2 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-17 14:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 05:09 -------
The problem is that we reset TREE_OVERFLOW:
  if ((TREE_CODE (value) == INTEGER_CST
       || (TREE_CODE (value) == COMPLEX_CST
           && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
      && TREE_OVERFLOW (value))
    {
      TREE_OVERFLOW (value) = 0;
      if (skip_evaluation == 0)
        warning ("integer overflow in expression");
    }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

* [Bug c/19978] overflow in expression of constants should not cause multiple warnings
  2005-02-15 22:54 [Bug c/19978] New: " jsm28 at gcc dot gnu dot org
@ 2005-02-16  3:29 ` pinskia at gcc dot gnu dot org
  2005-02-17 14:34 ` pinskia at gcc dot gnu dot org
  2005-02-18 11:04 ` schlie at comcast dot net
  2 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-16  3:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-15 21:20 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
      Known to fail|                            |3.3.3 3.2.3 3.4.0 4.0.0
                   |                            |3.0.4 2.95.3
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-15 21:20:52
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19978


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

end of thread, other threads:[~2007-01-06 15:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-19978-230@http.gcc.gnu.org/bugzilla/>
2006-11-26 19:27 ` [Bug c/19978] overflow in expression of constants should not cause multiple warnings manu at gcc dot gnu dot org
2006-12-09  1:10 ` patchapp at dberlin dot org
2007-01-05 21:57 ` manu at gcc dot gnu dot org
2007-01-06  9:34 ` manu at gcc dot gnu dot org
2007-01-06 15:04 ` schlie at comcast dot net
2005-02-15 22:54 [Bug c/19978] New: " jsm28 at gcc dot gnu dot org
2005-02-16  3:29 ` [Bug c/19978] " pinskia at gcc dot gnu dot org
2005-02-17 14:34 ` pinskia at gcc dot gnu dot org
2005-02-18 11:04 ` schlie at comcast dot net

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).