Bug 31023 - Fold is agnostic of integer sub-types
Summary: Fold is agnostic of integer sub-types
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: 30911
  Show dependency treegraph
 
Reported: 2007-03-02 09:52 UTC by Richard Biener
Modified: 2009-11-10 08:34 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-09-12 16:05:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2007-03-02 09:52:53 UTC
Transformations in fold do not properly handle integer types with value ranges
(defined by TYPE_MIN_VALUE and TYPE_MAX_VALUE) that do not correspond to the
types precision.

Citing from PR30911 comment #40

"The problem is in this transformation:

      /* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries.  */

X^Y may not be in the range of the type.  In this case C=7 and op=NE_EXPR.
The type of X and Y has range 4..5.  Thus X^Y is either 0 or 2 (neither of
which is in the range 4..5).  Since the type of X^Y has range 4..5, the
new fold code deduces that X^Y NE 0 is always true.  I think the thing to
do, as Richard Kenner suggested, is to convert each type to its base type
right at the start of fold_comparison, at least if it has a base type
(the same goes for other routines in fold).  This unfortunately neutralizes
your patch, since as it is right now you will only ever see base types.
Thus this kind of check needs to happen at the start of fold_comparison,
before the conversion to the base type."

another source of problems is fold_convert and its siblings that happily
create out-of-bounds constants or strip conversions to the base type.
Comment 1 Richard Biener 2008-03-30 14:57:12 UTC
Subject: Bug 31023

Author: rguenth
Date: Sun Mar 30 14:56:28 2008
New Revision: 133731

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133731
Log:
2008-03-30  Richard Guenther  <rguenther@suse.de>

	PR middle-end/31023
	* fold-const.c (fold_sign_changed_comparison): Do leave
	conversions to base-types alone.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c

Comment 2 Eric Botcazou 2009-11-10 08:34:57 UTC
These sub-types are gone in 4.5.