This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/19978] overflow in expression of constants should not cause multiple warnings



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]