This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch committed: Avoid IN_RANGE tests on enum values


i386.c has some IN_RANGE tests on enum values.  This is fine in C, but
in C++, where enums are not simply int, it triggers -Wtype-limits
warnings.  I don't think the IN_RANGE tests are the right approach
anyhow, since it means that if the type of the field changes we have to
change the test.  It's better to test that storing th value in the fild
does not change the value.  That is what I implemented in this patch.

Bootstrapped and tsted on x86_64-unknown-linux-gnu.  Committed.

Ian


2009-06-19  Ian Lance Taylor  <iant@google.com>

	* config/i386/i386.c (ix86_function_specific_save): Test that
	fields match values, rather than testing the values are in a
	certain range.


Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 148683)
+++ config/i386/i386.c	(working copy)
@@ -3424,12 +3424,6 @@ override_options (bool main_args_p)
 static void
 ix86_function_specific_save (struct cl_target_option *ptr)
 {
-  gcc_assert (IN_RANGE (ix86_arch, 0, 255));
-  gcc_assert (IN_RANGE (ix86_schedule, 0, 255));
-  gcc_assert (IN_RANGE (ix86_tune, 0, 255));
-  gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
-  gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
-
   ptr->arch = ix86_arch;
   ptr->schedule = ix86_schedule;
   ptr->tune = ix86_tune;
@@ -3439,6 +3433,14 @@ ix86_function_specific_save (struct cl_t
   ptr->arch_specified = ix86_arch_specified;
   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
   ptr->target_flags_explicit = target_flags_explicit;
+
+  /* The fields are char but the variables are not; make sure the
+     values fit in the fields.  */
+  gcc_assert (ptr->arch == ix86_arch);
+  gcc_assert (ptr->schedule == ix86_schedule);
+  gcc_assert (ptr->tune == ix86_tune);
+  gcc_assert (ptr->fpmath == ix86_fpmath);
+  gcc_assert (ptr->branch_cost == ix86_branch_cost);
 }
 
 /* Restore the current options */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]