Move some -f switches to opts.c

Neil Booth neil@daikokuya.co.uk
Sat Jun 21 15:24:00 GMT 2003


This patch moves some -f switches to opts.c.  In particular,
-ffixed- is moved.  The old switch handling logic would not know whether
a given switch might be handled by the front end or toplev.c itself or
indeed both, so it would give the front end a chance to handle it, and
then allow toplev.c a look too.  This caused an unhappy situation with
the Fortran -ffixed-line-length and -ffixed-form, in which case the
Fortran front end would handle the switch and return a negative number
to indicate that toplev.c should not get a look at it, since it would
get confused thinking e.g. "form" was a register to the -ffixed- switch.

The new switch handler always chooses the best match, so that
-ffixed-form does not match -ffixed- since -ffixed-form itself is a
better (longer) match, but -ffixed-foo does match -ffixed, so the above
kludge is no longer necessary.

However, there was a latent bug that has not been exposed until now.
In seeing -ffixed-line-length-0, the binary search happened to land on
-ffixed- first.  It dutifully remembered that as a match, and checked
the next switch in the sorted array to see if it was a better match.
The next one was "-ffixed-form" which didn't match (strcmp != 0), so it
incorrectly bailed out, assuming no better match was possible and that
-ffixed- was the match.  The correct logic is to bail out only when the
strcmp comparison is < 0.  With this simple tweak to find_opt(), the
code continues looking after -ffixed-form to find -ffixed-line-length,
and everything works.

Neil.

	* c-opts.c (c_common_handle_option): Don't return -1.
	* common.opt: New switches.
	* opts.c: Include rtl.h, ggc.h and output.h.
	(find_opt): Only stop searching when input switch compares
	less than the stored switch.  Continue searching if greater.
	(handle_option): No need to handle negative return values.
	(common_handle_option): Handle new switches.
	(set_fast_math_flags, fast_math_flags_set_p): New.
	* toplev.c (set_fast_math_flags, fast_math_flags_set_p):
	Move to opts.c.
	(decode_f_option): Some switches moved to opts.c.
	(parse_options_and_default_flags): No need to cater for negative
	return values.
f:
	* top.c (ffe_handle_option): No need to return -1 any more.

Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.60
diff -u -p -r1.60 c-opts.c
--- c-opts.c	18 Jun 2003 05:58:49 -0000	1.60
+++ c-opts.c	21 Jun 2003 12:49:13 -0000
@@ -820,8 +820,8 @@ c_common_handle_option (size_t scode, co
     case OPT_ffixed_form:
     case OPT_ffixed_line_length_:
       /* Fortran front end options ignored when preprocessing only.  */
-      if (flag_preprocess_only)
-        result = -1;
+      if (!flag_preprocess_only)
+        result = 0;
       break;
 
     case OPT_ffor_scope:
Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.5
diff -u -p -r1.5 common.opt
--- common.opt	20 Jun 2003 22:56:35 -0000	1.5
+++ common.opt	21 Jun 2003 12:49:13 -0000
@@ -139,6 +139,39 @@ Common Joined
 dumpbase
 Common Separate
 
+falign-functions=
+Common RejectNegative Joined UInteger
+
+falign-jumps=
+Common RejectNegative Joined UInteger
+
+falign-labels=
+Common RejectNegative Joined UInteger
+
+falign-loops=
+Common RejectNegative Joined UInteger
+
+fcall-saved-
+Common Joined RejectNegative
+
+fcall-used-
+Common Joined RejectNegative
+
+ffast-math
+Common
+
+ffixed-
+Common Joined RejectNegative
+
+fstack-limit-register=
+Common RejectNegative Joined
+
+fstack-limit-symbol=
+Common RejectNegative Joined
+
+ftls-model=
+Common Joined RejectNegative
+
 g
 Common JoinedOrMissing
 
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.9
diff -u -p -r1.9 opts.c
--- opts.c	20 Jun 2003 22:56:36 -0000	1.9
+++ opts.c	21 Jun 2003 12:49:14 -0000
@@ -24,6 +24,9 @@ Software Foundation, 59 Temple Place - S
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "rtl.h"
+#include "ggc.h"
+#include "output.h"
 #include "langhooks.h"
 #include "opts.h"
 #include "options.h"
@@ -196,8 +199,11 @@ find_opt (const char *input, int lang_ma
 	      for (md = md + 1; md < cl_options_count; md++)
 		{
 		  opt_len = cl_options[md].opt_len;
-		  if (strncmp (input, cl_options[md].opt_text, opt_len))
+		  comp = strncmp (input, cl_options[md].opt_text, opt_len);
+		  if (comp < 0)
 		    break;
+		  if (comp > 0)
+		    continue;
 		  if (input[opt_len] == '\0')
 		    return md;
 		  if (cl_options[md].flags & lang_mask
@@ -237,7 +243,7 @@ handle_option (int argc ATTRIBUTE_UNUSED
   const char *opt, *arg = 0;
   char *dup = 0;
   int value = 1;
-  int result = 0, temp;
+  int result = 0;
   const struct cl_option *option;
 
   opt = argv[0];
@@ -320,17 +326,12 @@ handle_option (int argc ATTRIBUTE_UNUSED
 	}
 
       if (option->flags & lang_mask)
-	{
-	  temp = (*lang_hooks.handle_option) (opt_index, arg, value);
-	  if (temp <= 0)
-	    result = temp;
-	}
+	if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
+	  result = 0;
 
-      if (result > 0 && (option->flags & CL_COMMON))
-	{
-	  if (common_handle_option (opt_index, arg, value) == 0)
-	    result = 0;
-	}
+      if (result && (option->flags & CL_COMMON))
+	if (common_handle_option (opt_index, arg, value) == 0)
+	  result = 0;
     }
 
  done:
@@ -520,6 +521,65 @@ common_handle_option (size_t scode, cons
       dump_base_name = arg;
       break;
 
+    case OPT_falign_functions_:
+      align_functions = value;
+      break;
+
+    case OPT_falign_jumps_:
+      align_jumps = value;
+      break;
+
+    case OPT_falign_labels_:
+      align_labels = value;
+      break;
+
+    case OPT_falign_loops_:
+      align_loops = value;
+      break;
+
+    case OPT_fcall_used_:
+      fix_register (arg, 0, 1);
+      break;
+
+    case OPT_fcall_saved_:
+      fix_register (arg, 0, 0);
+      break;
+
+    case OPT_ffast_math:
+      set_fast_math_flags (value);
+      break;
+
+    case OPT_ffixed_:
+      fix_register (arg, 1, 1);
+      break;
+
+    case OPT_fstack_limit_register_:
+      {
+	int reg = decode_reg_name (arg);
+	if (reg < 0)
+	  error ("unrecognized register name \"%s\"", arg);
+	else
+	  stack_limit_rtx = gen_rtx_REG (Pmode, reg);
+      }
+      break;
+
+    case OPT_fstack_limit_symbol_:
+      stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
+      break;
+
+    case OPT_ftls_model_:
+      if (!strcmp (arg, "global-dynamic"))
+	flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
+      else if (!strcmp (arg, "local-dynamic"))
+	flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
+      else if (!strcmp (arg, "initial-exec"))
+	flag_tls_default = TLS_MODEL_INITIAL_EXEC;
+      else if (!strcmp (arg, "local-exec"))
+	flag_tls_default = TLS_MODEL_LOCAL_EXEC;
+      else
+	warning ("unknown tls-model \"%s\"", arg);
+      break;
+
     case OPT_g:
       decode_g_option (arg);
       break;
@@ -618,4 +678,27 @@ set_Wunused (int setting)
   warn_unused_parameter = (setting && extra_warnings);
   warn_unused_variable = setting;
   warn_unused_value = setting;
+}
+
+/* The following routines are useful in setting all the flags that
+   -ffast-math and -fno-fast-math imply.  */
+void
+set_fast_math_flags (int set)
+{
+  flag_trapping_math = !set;
+  flag_unsafe_math_optimizations = set;
+  flag_finite_math_only = set;
+  flag_errno_math = !set;
+  if (set)
+    flag_signaling_nans = 0;
+}
+
+/* Return true iff flags are set as if -ffast-math.  */
+bool
+fast_math_flags_set_p (void)
+{
+  return (!flag_trapping_math
+	  && flag_unsafe_math_optimizations
+	  && flag_finite_math_only
+	  && !flag_errno_math);
 }
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.780
diff -u -p -r1.780 toplev.c
--- toplev.c	20 Jun 2003 22:56:36 -0000	1.780
+++ toplev.c	21 Jun 2003 12:49:15 -0000
@@ -1548,30 +1548,6 @@ static const lang_independent_options W_
    N_ ("Warn about code which might break the strict aliasing rules") }
 };
 
-/* The following routines are useful in setting all the flags that
-   -ffast-math and -fno-fast-math imply.  */
-
-void
-set_fast_math_flags (int set)
-{
-  flag_trapping_math = !set;
-  flag_unsafe_math_optimizations = set;
-  flag_finite_math_only = set;
-  flag_errno_math = !set;
-  if (set)
-    flag_signaling_nans = 0;
-}
-
-/* Return true iff flags are set as if -ffast-math.  */
-bool
-fast_math_flags_set_p (void)
-{
-  return (!flag_trapping_math
-	  && flag_unsafe_math_optimizations
-	  && flag_finite_math_only
-	  && !flag_errno_math);
-}
-
 /* Output files for assembler code (real compiler output)
    and debugging dumps.  */
 
@@ -4197,11 +4173,7 @@ decode_f_option (const char *arg)
 	}
     }
 
-  if (!strcmp (arg, "fast-math"))
-    set_fast_math_flags (1);
-  else if (!strcmp (arg, "no-fast-math"))
-    set_fast_math_flags (0);
-  else if ((option_value = skip_leading_substring (arg, "inline-limit-"))
+  if ((option_value = skip_leading_substring (arg, "inline-limit-"))
 	   || (option_value = skip_leading_substring (arg, "inline-limit=")))
     {
       int val =
@@ -4219,55 +4191,10 @@ decode_f_option (const char *arg)
 	    set_param_value ("min-inline-insns", 10);
 	}
     }
-  else if ((option_value = skip_leading_substring (arg, "tls-model=")))
-    {
-      if (strcmp (option_value, "global-dynamic") == 0)
-	flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
-      else if (strcmp (option_value, "local-dynamic") == 0)
-	flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
-      else if (strcmp (option_value, "initial-exec") == 0)
-	flag_tls_default = TLS_MODEL_INITIAL_EXEC;
-      else if (strcmp (option_value, "local-exec") == 0)
-	flag_tls_default = TLS_MODEL_LOCAL_EXEC;
-      else
-	warning ("`%s': unknown tls-model option", arg - 2);
-    }
 #ifdef INSN_SCHEDULING
   else if ((option_value = skip_leading_substring (arg, "sched-verbose=")))
     fix_sched_param ("verbose", option_value);
 #endif
-  else if ((option_value = skip_leading_substring (arg, "fixed-")))
-    fix_register (option_value, 1, 1);
-  else if ((option_value = skip_leading_substring (arg, "call-used-")))
-    fix_register (option_value, 0, 1);
-  else if ((option_value = skip_leading_substring (arg, "call-saved-")))
-    fix_register (option_value, 0, 0);
-  else if ((option_value = skip_leading_substring (arg, "align-loops=")))
-    align_loops = read_integral_parameter (option_value, arg - 2, align_loops);
-  else if ((option_value = skip_leading_substring (arg, "align-functions=")))
-    align_functions
-      = read_integral_parameter (option_value, arg - 2, align_functions);
-  else if ((option_value = skip_leading_substring (arg, "align-jumps=")))
-    align_jumps = read_integral_parameter (option_value, arg - 2, align_jumps);
-  else if ((option_value = skip_leading_substring (arg, "align-labels=")))
-    align_labels
-      = read_integral_parameter (option_value, arg - 2, align_labels);
-  else if ((option_value
-	    = skip_leading_substring (arg, "stack-limit-register=")))
-    {
-      int reg = decode_reg_name (option_value);
-      if (reg < 0)
-	error ("unrecognized register name `%s'", option_value);
-      else
-	stack_limit_rtx = gen_rtx_REG (Pmode, reg);
-    }
-  else if ((option_value
-	    = skip_leading_substring (arg, "stack-limit-symbol=")))
-    {
-      const char *nm;
-      nm = ggc_strdup (option_value);
-      stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, nm);
-    }
   else if ((option_value
 	    = skip_leading_substring (arg, "message-length=")))
     output_set_maximum_length
@@ -4896,25 +4823,16 @@ parse_options_and_default_flags (int arg
   /* Perform normal command line switch decoding.  */
   for (i = 1; i < argc;)
     {
-      int lang_processed;
-      int indep_processed;
+      int processed;
 
       /* Give the language a chance to decode the option for itself.  */
-      lang_processed = handle_option (argc - i, argv + i, lang_mask);
+      processed = handle_option (argc - i, argv + i, lang_mask);
 
-      if (lang_processed >= 0)
-	/* Now see if the option also has a language independent meaning.
-	   Some options are both language specific and language independent,
-	   eg --help.  */
-	indep_processed = independent_decode_option (argv + i);
-      else
-	{
-	  lang_processed = -lang_processed;
-	  indep_processed = 0;
-	}
+      if (!processed)
+	processed = independent_decode_option (argv + i);
 
-      if (lang_processed || indep_processed)
-	i += MAX (lang_processed, indep_processed);
+      if (processed)
+	i += processed;
       else
 	{
 	  const char *option = NULL;
Index: f/top.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/top.c,v
retrieving revision 1.32
diff -u -p -r1.32 top.c
--- f/top.c	14 Jun 2003 12:26:35 -0000	1.32
+++ f/top.c	21 Jun 2003 12:49:16 -0000
@@ -239,8 +239,6 @@ ffe_handle_option (size_t scode, const c
 
     case OPT_ffixed_form:
       ffe_set_is_free_form (!value);
-      if (value)
-	return -1;
       break;
 
     case OPT_fpedantic:
@@ -564,16 +562,12 @@ ffe_handle_option (size_t scode, const c
 
     case OPT_ffixed_line_length_:
       if (strcmp (arg, "none") == 0)
-	{
-	  ffe_set_fixed_line_length (0);
-	  return -1;
-	}
+	ffe_set_fixed_line_length (0);
       else if (ffe_is_digit_string_ (arg))
-	{
-	  ffe_set_fixed_line_length (atol (arg));
-	  return -1;
-	}
-      return 0;
+	ffe_set_fixed_line_length (atol (arg));
+      else
+	return 0;
+      break;
 
     case OPT_Wcomment:
     case OPT_Wcomments:



More information about the Gcc-patches mailing list