diff options
author | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2009-04-12 21:39:39 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2009-04-12 21:39:39 +0000 |
commit | 849d624b4a81f4dc9546e29571c970994dc935ed (patch) | |
tree | 3526746cc33223821d95bafdc40b7cb9e1597f03 /gcc/fold-const.c | |
parent | 3906a4a1bc19a4618625cfa6064d647cd7d78686 (diff) | |
download | gcc-849d624b4a81f4dc9546e29571c970994dc935ed.zip gcc-849d624b4a81f4dc9546e29571c970994dc935ed.tar.gz gcc-849d624b4a81f4dc9546e29571c970994dc935ed.tar.bz2 |
fold-const.c (build_range_check): Properly deal with enumeral and boolean base types.
* fold-const.c (build_range_check): Properly deal with enumeral and
boolean base types.
From-SVN: r145988
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index dd2f62d..bd5e97d 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4671,8 +4671,8 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh, static tree build_range_check (tree type, tree exp, int in_p, tree low, tree high) { - tree etype = TREE_TYPE (exp); - tree value; + tree etype = TREE_TYPE (exp), value; + enum tree_code code; #ifdef HAVE_canonicalize_funcptr_for_compare /* Disable this optimization for function pointer expressions @@ -4756,20 +4756,25 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) /* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low). This requires wrap-around arithmetics for the type of the expression. */ - switch (TREE_CODE (etype)) + code = TREE_CODE (etype); + switch (code) { case INTEGER_TYPE: + case ENUMERAL_TYPE: + case BOOLEAN_TYPE: /* There is no requirement that LOW be within the range of ETYPE if the latter is a subtype. It must, however, be within the base type of ETYPE. So be sure we do the subtraction in that type. */ - if (TREE_TYPE (etype)) - etype = TREE_TYPE (etype); - break; + if (code == INTEGER_TYPE && TREE_TYPE (etype)) + { + etype = TREE_TYPE (etype); + /* But not in an enumeral or boolean type though. */ + code = TREE_CODE (etype); + } - case ENUMERAL_TYPE: - case BOOLEAN_TYPE: - etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype), - TYPE_UNSIGNED (etype)); + if (code != INTEGER_TYPE) + etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype), + TYPE_UNSIGNED (etype)); break; default: |