re PR c/30260 (Enumeration types and enumeration constants erroneously given unsigned types)

2008-10-19  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/30260
	* c-decl.c (finish_enum): Convert non-integer enumerators to enum
	type.
	(build_enumerator): Convert enumerators that fit in integer to
	integer type.
testsuite/
	* gcc.dg/pr30260.c: New.

From-SVN: r141224
parent 1344d390
2008-10-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/30260
* c-decl.c (finish_enum): Convert non-integer enumerators to enum
type.
(build_enumerator): Convert enumerators that fit in integer to
integer type.
2008-10-18 Uros Bizjak <ubizjak@gmail.com> 2008-10-18 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (unnamed peephole2): Do not force memory * config/i386/i386.md (unnamed peephole2): Do not force memory
...@@ -8765,7 +8773,7 @@ ...@@ -8765,7 +8773,7 @@
PR ada/36554 PR ada/36554
* dwarf2out.c (is_subrange_type): Deal with BOOLEAN_TYPE. * dwarf2out.c (is_subrange_type): Deal with BOOLEAN_TYPE.
2008-07-30 Rafael vila de Espíndola <espindola@google.com> 2008-07-30 Rafael Ávila de Espíndola <espindola@google.com>
PR 36974 PR 36974
* final.c (call_from_call_insn): Handle COND_EXEC. * final.c (call_from_call_insn): Handle COND_EXEC.
...@@ -8977,7 +8985,7 @@ ...@@ -8977,7 +8985,7 @@
* config/rs6000/rs6000.h (SLOW_UNALIGNED_ACCESS): Add clause for * config/rs6000/rs6000.h (SLOW_UNALIGNED_ACCESS): Add clause for
vector modes. vector modes.
2008-07-30 Rafael vila de Espíndola <espindola@google.com> 2008-07-30 Rafael Ávila de Espíndola <espindola@google.com>
* final.c (call_from_call_insn): New. * final.c (call_from_call_insn): New.
(final_scan_insn): Call assemble_external on FUNCTION_DECLs. (final_scan_insn): Call assemble_external on FUNCTION_DECLs.
...@@ -10095,7 +10103,7 @@ ...@@ -10095,7 +10103,7 @@
(TARGET_OPTION_PRINT): Ditto. (TARGET_OPTION_PRINT): Ditto.
(TARGET_CAN_INLINE_P): Ditto. (TARGET_CAN_INLINE_P): Ditto.
2008-07-22 Rafael vila de Espíndola <espindola@google.com> 2008-07-22 Rafael Ávila de Espíndola <espindola@google.com>
* c-typeck.c (build_external_ref): Don't call assemble_external. * c-typeck.c (build_external_ref): Don't call assemble_external.
* final.c (output_operand): Call assemble_external. * final.c (output_operand): Call assemble_external.
...@@ -10116,7 +10124,7 @@ ...@@ -10116,7 +10124,7 @@
highest magnitude if this is still less or equal to the true highest magnitude if this is still less or equal to the true
quotient in magnitude. quotient in magnitude.
2008-07-21 Rafael vila de Espíndola <espindola@google.com> 2008-07-21 Rafael Ávila de Espíndola <espindola@google.com>
* Makefile.in: Replace toplev.h with TOPLEV_H. * Makefile.in: Replace toplev.h with TOPLEV_H.
* c-decl.c (merge_decls): Don't set DECL_IN_SYSTEM_HEADER. * c-decl.c (merge_decls): Don't set DECL_IN_SYSTEM_HEADER.
...@@ -10419,7 +10427,7 @@ ...@@ -10419,7 +10427,7 @@
(m32c_legitimate_address_p): Handle "++rii" addresses created by (m32c_legitimate_address_p): Handle "++rii" addresses created by
m32c_legitimize_reload_address. m32c_legitimize_reload_address.
2007-07-16 Rafael vila de Espíndola <espindola@google.com> 2007-07-16 Rafael Ávila de Espíndola <espindola@google.com>
* c-decl.c (merge_decls): Keep DECL_SOURCE_LOCATION and * c-decl.c (merge_decls): Keep DECL_SOURCE_LOCATION and
DECL_IN_SYSTEM_HEADER in sync. DECL_IN_SYSTEM_HEADER in sync.
...@@ -10509,7 +10517,7 @@ ...@@ -10509,7 +10517,7 @@
* emit-rtl.c (set_mem_attributes_minus_bitpos): Improve comment. * emit-rtl.c (set_mem_attributes_minus_bitpos): Improve comment.
2007-07-14 Rafael vila de Espíndola <espindola@google.com> 2007-07-14 Rafael Ávila de Espíndola <espindola@google.com>
* c-decl.c (diagnose_mismatched_decls): Don't warn if TREE_NO_WARNING * c-decl.c (diagnose_mismatched_decls): Don't warn if TREE_NO_WARNING
is set. is set.
......
...@@ -5926,17 +5926,15 @@ finish_enum (tree enumtype, tree values, tree attributes) ...@@ -5926,17 +5926,15 @@ finish_enum (tree enumtype, tree values, tree attributes)
/* The ISO C Standard mandates enumerators to have type int, /* The ISO C Standard mandates enumerators to have type int,
even though the underlying type of an enum type is even though the underlying type of an enum type is
unspecified. However, GCC allows enumerators of any unspecified. However, GCC allows enumerators of any
integer type as an extensions. Here we convert any integer type as an extensions. build_enumerator()
enumerators that fit in an int to type int, to avoid converts any enumerators that fit in an int to type int,
promotions to unsigned types when comparing integers with to avoid promotions to unsigned types when comparing
enumerators that fit in the int range. When -pedantic is integers with enumerators that fit in the int range.
given, build_enumerator() would have already warned about When -pedantic is given, build_enumerator() would have
those that don't fit. */ already warned about those that don't fit. Here we
if (int_fits_type_p (ini, integer_type_node)) convert the rest to the enumerator type. */
tem = integer_type_node; if (TREE_TYPE (ini) != integer_type_node)
else ini = convert (enumtype, ini);
tem = enumtype;
ini = convert (tem, ini);
DECL_INITIAL (enu) = ini; DECL_INITIAL (enu) = ini;
TREE_PURPOSE (pair) = DECL_NAME (enu); TREE_PURPOSE (pair) = DECL_NAME (enu);
...@@ -6026,6 +6024,18 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, ...@@ -6026,6 +6024,18 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value,
pedwarn (value_loc, OPT_pedantic, pedwarn (value_loc, OPT_pedantic,
"ISO C restricts enumerator values to range of %<int%>"); "ISO C restricts enumerator values to range of %<int%>");
/* The ISO C Standard mandates enumerators to have type int, even
though the underlying type of an enum type is unspecified.
However, GCC allows enumerators of any integer type as an
extensions. Here we convert any enumerators that fit in an int
to type int, to avoid promotions to unsigned types when comparing
integers with enumerators that fit in the int range. When
-pedantic is given, we would have already warned about those that
don't fit. We have to do this here rather than in finish_enum
because this value may be used to define more enumerators. */
if (int_fits_type_p (value, integer_type_node))
value = convert (integer_type_node, value);
/* Set basis for default for next value. */ /* Set basis for default for next value. */
the_enum->enum_next_value the_enum->enum_next_value
= build_binary_op = build_binary_op
......
2008-10-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/30260
* gcc.dg/pr30260.c: New.
2008-10-19 Paul Thomas <pault@gcc.gnu.org> 2008-10-19 Paul Thomas <pault@gcc.gnu.org>
PR fortran/37723 PR fortran/37723
......
/* PR 30260 */
/* { dg-do link } */
/* { dg-options "-pedantic -O" } */
#include <limits.h>
enum A {
A1 = 0,
A2 = A1 - 1
};
enum B {
B1 = 0u,
B2 = B1 - 1 /* { dg-bogus "ISO C restricts enumerator values to range of 'int'" } */
};
int main(void)
{
enum A a = -1;
enum B b = -1;
if (!(a < 0))
link_error ();
if (!(A2 < 0))
link_error ();
if (!(b < 0))
link_error ();
if (!(B2 < 0))
link_error ();
return 0;
}
enum E1 { e10 = INT_MAX, e11 }; /* { dg-error "overflow in enumeration values" } */
enum E2 { e20 = (unsigned) INT_MAX, e21 }; /* { dg-error "overflow in enumeration values" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment