From: Richard Stallman Date: Tue, 7 Sep 1993 12:26:20 +0000 (+0000) Subject: (build_enumerator): Choose type properly for wide constants. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=75b46437886a5e33b8cd51201cfa852c82c2f0ec;p=gcc.git (build_enumerator): Choose type properly for wide constants. (finish_enum): Always set type of the enumerators to the enum type. From-SVN: r5271 --- diff --git a/gcc/c-decl.c b/gcc/c-decl.c index df0a515b9c6..539828e1c67 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5551,17 +5551,18 @@ finish_enum (enumtype, values) /* An enum can have some negative values; then it is signed. */ TREE_UNSIGNED (enumtype) = ! tree_int_cst_lt (minnode, integer_zero_node); - /* If the enumerators might not fit in an int, change their type now. */ - /* It seems more useful in the debugger to leave these as int - unless the enumerator is wider than int. */ - if (TYPE_PRECISION (enumtype) <= TYPE_PRECISION (integer_type_node)) - for (pair = values; pair; pair = TREE_CHAIN (pair)) - { - TREE_TYPE (TREE_PURPOSE (pair)) = enumtype; - DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype); - if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL) - DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype); - } + /* Change the type of the enumerators to be the enum type. + Formerly this was done only for enums that fit in an int, + but the comment said it was done only for enums wider than int. + It seems necessary to do this for wide enums, + and best not to change what's done for ordinary narrower ones. */ + for (pair = values; pair; pair = TREE_CHAIN (pair)) + { + TREE_TYPE (TREE_PURPOSE (pair)) = enumtype; + DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype); + if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL) + DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype); + } /* Replace the decl nodes in VALUES with their names. */ for (pair = values; pair; pair = TREE_CHAIN (pair)) @@ -5600,7 +5601,7 @@ tree build_enumerator (name, value) tree name, value; { - register tree decl; + register tree decl, type; /* Validate and default VALUE. */ @@ -5645,9 +5646,16 @@ build_enumerator (name, value) /* Now create a declaration for the enum value name. */ - decl = build_decl (CONST_DECL, name, integer_type_node); + type = TREE_TYPE (value); + type = type_for_size (MAX (TYPE_PRECISION (type), + TYPE_PRECISION (integer_type_node)), + ((flag_traditional + || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)) + && TREE_UNSIGNED (type))); + + decl = build_decl (CONST_DECL, name, type); DECL_INITIAL (decl) = value; - TREE_TYPE (value) = integer_type_node; + TREE_TYPE (value) = type; pushdecl (decl); return saveable_tree_cons (decl, value, NULL_TREE);