aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2003-09-22 23:04:14 -0700
committerRichard Henderson <rth@gcc.gnu.org>2003-09-22 23:04:14 -0700
commit3504b199c283afd4d48cbd0f786fa6fd33a11a13 (patch)
tree25aa3fd7b1ba9fdbd7f88065a488abc158ffdf71 /gcc/c-common.c
parent92f6e625321d576fdcafebd2ad540f8709508a35 (diff)
downloadgcc-3504b199c283afd4d48cbd0f786fa6fd33a11a13.zip
gcc-3504b199c283afd4d48cbd0f786fa6fd33a11a13.tar.gz
gcc-3504b199c283afd4d48cbd0f786fa6fd33a11a13.tar.bz2
c-common.c (c_common_signed_or_unsigned_type): Examine mode, not precision.
* c-common.c (c_common_signed_or_unsigned_type): Examine mode, not precision. * g++.dg/opt/enum1.C: New. From-SVN: r71677
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 39c6a57..905ad93 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -1982,32 +1982,37 @@ c_common_signed_or_unsigned_type (int unsignedp, tree type)
|| TREE_UNSIGNED (type) == unsignedp)
return type;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
+ /* Must check the mode of the types, not the precision. Enumeral types
+ in C++ have precision set to match their range, but may use a wider
+ mode to match an ABI. If we change modes, we may wind up with bad
+ conversions. */
+
+ if (TYPE_MODE (type) == TYPE_MODE (signed_char_type_node))
return unsignedp ? unsigned_char_type_node : signed_char_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (integer_type_node))
return unsignedp ? unsigned_type_node : integer_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (short_integer_type_node))
return unsignedp ? short_unsigned_type_node : short_integer_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (long_integer_type_node))
return unsignedp ? long_unsigned_type_node : long_integer_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (long_long_integer_type_node))
return (unsignedp ? long_long_unsigned_type_node
: long_long_integer_type_node);
- if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (widest_integer_literal_type_node))
return (unsignedp ? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
#if HOST_BITS_PER_WIDE_INT >= 64
- if (TYPE_PRECISION (type) == TYPE_PRECISION (intTI_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (intTI_type_node))
return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
#endif
- if (TYPE_PRECISION (type) == TYPE_PRECISION (intDI_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (intDI_type_node))
return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (intSI_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (intSI_type_node))
return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (intHI_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (intHI_type_node))
return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
- if (TYPE_PRECISION (type) == TYPE_PRECISION (intQI_type_node))
+ if (TYPE_MODE (type) == TYPE_MODE (intQI_type_node))
return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
return type;