summaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 01:14:24 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 01:14:24 +0000
commitee1ab43129e5d263eba81fb1f2721be503e9d148 (patch)
treeaa422656fa001e4c76605059943c273de869706a /gcc/stor-layout.c
parente4a0b392b2d0188bb1cb8ff255f409f21754af81 (diff)
downloadgcc-ee1ab43129e5d263eba81fb1f2721be503e9d148.tar.gz
PR c++/11667
* c-common.c (shorten_compare): Take into account differences between C and C++ representation for enumeration types. * tree.h (set_min_and_max_values_for_integral_type): Declare. * stor-layout.c (set_min_and_max_values_for_integral_type): New function, broken out from ... (fixup_signed_type): ... here and ... (fixup_unsigned_type): ... here. PR c++/11667 * call.c (standard_conversion): Allow all integral->enumeral conversions, after marking them as bad. * decl.c (finish_enum): Make sure that all enumerators are properly converted to the underlying type. (build_enumerator): Set DECL_CONTEXT for namespace-scope enumeration types. * pt.c (tsubst_copy): Adjust handling of CONST_DECLs accordingly. (tsubst_enum): Tidy. * Make-lang.in (typeck.o): Depend on convert.h. (class.o): Likewise. (rtti.o): Likewise. * call.c: Include convert.h. (convert_arg_to_ellipsis): Use convert_to_real. * class.c: Include convert.h. (build_base_path): Use convert_to_integer. * rtti.c: Include convert.h. (build_headof): Use convert_to_integer. * typeck.c: Include convert.h. (decay_conversion): Use convert_to_integer. (build_unary_op): Use build_nop. (get_delta_difference): Use convert_to_integer. (build_ptrmemfunc): Avoid unncessary conversions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69909 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c84
1 files changed, 56 insertions, 28 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index e2395c451c5..54e6a56de99 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -1957,6 +1957,58 @@ set_sizetype (tree type)
sizetype_set = 1;
}
+/* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE,
+ BOOLEAN_TYPE, or CHAR_TYPE. Set TYPE_MIN_VALUE and TYPE_MAX_VALUE
+ for TYPE, based on the PRECISION and whether or not the TYPE
+ IS_UNSIGNED. PRECISION need not correspond to a width supported
+ natively by the hardware; for example, on a machine with 8-bit,
+ 16-bit, and 32-bit register modes, PRECISION might be 7, 23, or
+ 61. */
+
+void
+set_min_and_max_values_for_integral_type (tree type,
+ int precision,
+ bool is_unsigned)
+{
+ tree min_value;
+ tree max_value;
+
+ if (is_unsigned)
+ {
+ min_value = build_int_2 (0, 0);
+ max_value
+ = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
+ ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
+ precision - HOST_BITS_PER_WIDE_INT > 0
+ ? ((unsigned HOST_WIDE_INT) ~0
+ >> (HOST_BITS_PER_WIDE_INT
+ - (precision - HOST_BITS_PER_WIDE_INT)))
+ : 0);
+ }
+ else
+ {
+ min_value
+ = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
+ ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
+ (((HOST_WIDE_INT) (-1)
+ << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
+ ? precision - HOST_BITS_PER_WIDE_INT - 1
+ : 0))));
+ max_value
+ = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
+ ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
+ (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
+ ? (((HOST_WIDE_INT) 1
+ << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
+ : 0));
+ }
+
+ TREE_TYPE (min_value) = type;
+ TREE_TYPE (max_value) = type;
+ TYPE_MIN_VALUE (type) = min_value;
+ TYPE_MAX_VALUE (type) = max_value;
+}
+
/* Set the extreme values of TYPE based on its precision in bits,
then lay it out. Used when make_signed_type won't do
because the tree code is not INTEGER_TYPE.
@@ -1973,23 +2025,8 @@ fixup_signed_type (tree type)
if (precision > HOST_BITS_PER_WIDE_INT * 2)
precision = HOST_BITS_PER_WIDE_INT * 2;
- TYPE_MIN_VALUE (type)
- = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
- ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
- (((HOST_WIDE_INT) (-1)
- << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
- ? precision - HOST_BITS_PER_WIDE_INT - 1
- : 0))));
- TYPE_MAX_VALUE (type)
- = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
- ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
- (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
- ? (((HOST_WIDE_INT) 1
- << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
- : 0));
-
- TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
- TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
+ set_min_and_max_values_for_integral_type (type, precision,
+ /*is_unsigned=*/false);
/* Lay out the type: set its alignment, size, etc. */
layout_type (type);
@@ -2010,17 +2047,8 @@ fixup_unsigned_type (tree type)
if (precision > HOST_BITS_PER_WIDE_INT * 2)
precision = HOST_BITS_PER_WIDE_INT * 2;
- TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
- TYPE_MAX_VALUE (type)
- = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
- ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
- precision - HOST_BITS_PER_WIDE_INT > 0
- ? ((unsigned HOST_WIDE_INT) ~0
- >> (HOST_BITS_PER_WIDE_INT
- - (precision - HOST_BITS_PER_WIDE_INT)))
- : 0);
- TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
- TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
+ set_min_and_max_values_for_integral_type (type, precision,
+ /*is_unsigned=*/true);
/* Lay out the type: set its alignment, size, etc. */
layout_type (type);