Bug 48432 - -Wstrict-overflow incorrectly warns for Emacs src/font.c
Summary: -Wstrict-overflow incorrectly warns for Emacs src/font.c
Status: RESOLVED DUPLICATE of bug 48228
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.6.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-04 06:49 UTC by Paul Eggert
Modified: 2011-04-04 09:19 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 Paul Eggert 2011-04-04 06:49:25 UTC
When compiling the GNU Emacs trunk with a GCC 4.6.0 that I built on
RHEL 5.6 (x86-64), I ran into a problem when compiling src/font.c that
I narrowed down to the following stripped-down test case.  When I
compile this test case with

  gcc -S -Wstrict-overflow -O2 f.c

the output is:

  f.c: In function 'font_list_entities':
  f.c:38:35: warning: assuming signed overflow does not occur when simplifying co
nditional to constant [-Wstrict-overflow]

The warning is incorrect, since signed overflow is impossible here.
There are two 'int' variables, one of which is assigned only 0 or 1,
and the other which is assigned only values ranging from 6 through 12.
Changing either 'int' variable to 'unsigned' makes the warning go away.

I'm not sure whether this bug is the same as earlier bug reports I
filed in this area (PR48228, PR48267), but it's not obviously the same
so I figured I should be safe and file it.  It did take some time to
track down.

-----

extern unsigned foo0 (void);
extern unsigned foo2 (unsigned, unsigned);

static unsigned
font_delete_unmatched (unsigned vec, unsigned spec, unsigned int size)
{
  unsigned val = 0;

  while (1)
    {
      if (spec)
	{
	  val = foo2 (vec, val);
	  continue;
	}
    }
  return val;
}

unsigned
font_list_entities (unsigned frame, unsigned spec)
{
  unsigned val = 0;
  int need_filtering = 0;
  int i;

  for (i = 6; i < 13; i++)
    {
      if (foo0 ())
	need_filtering = 1;
      if (i == 10)
	i++;
    }

  while (foo0 ())
    if (need_filtering)
      val = font_delete_unmatched (val, need_filtering ? spec : 0, 0);
  return 0;
}
Comment 1 Jakub Jelinek 2011-04-04 09:19:37 UTC
It looks like a dup of PR48228, certainly on the trunk the warning goes away with that commit.

*** This bug has been marked as a duplicate of bug 48228 ***