Bug 48022 - [4.6 Regression] -Wstrict-overflow warning on code that doesn't have overflows
Summary: [4.6 Regression] -Wstrict-overflow warning on code that doesn't have overflows
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-07 16:01 UTC by Jakub Jelinek
Modified: 2011-03-08 10:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2011-03-07 16:01:33 UTC
int
foo (const char *x)
{
  unsigned long l = 1;
  const unsigned char *s = (const unsigned char *) (const char *) (x);
  int r = s[0] - ((const unsigned char *) (const char *) ("/"))[0];
  if (l > 0 && r == 0)
    r = (s[1] - ((const unsigned char *) (const char *) ("/"))[1]);
  return r;
}

gets at -O2 on x86_64-linux
warning: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Wstrict-overflow]

This is simplified return strcmp (path, "/"); when using glibc <string.h> strcmp macro.

The warning started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161655
Comment 1 Richard W.M. Jones 2011-03-07 16:51:14 UTC
Report on Fedora devel mailing list:
http://lists.fedoraproject.org/pipermail/devel/2011-March/thread.html#149342
Comment 2 Jakub Jelinek 2011-03-08 10:43:14 UTC
Author: jakub
Date: Tue Mar  8 10:43:10 2011
New Revision: 170772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170772
Log:
	PR tree-optimization/48022
	* fold-const.c (fold_comparison): Don't call fold_overflow_warning
	for EQ/NE_EXPR.

	* gcc.dg/pr48022-1.c: New test.
	* gcc.dg/pr48022-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr48022-1.c
    trunk/gcc/testsuite/gcc.dg/pr48022-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jakub Jelinek 2011-03-08 10:44:30 UTC
Fixed.