Patchwork [Ada,C++,etc.] Options patches pending review

login
register
mail settings
Submitter Joseph S. Myers
Date July 27, 2010, 10:02 a.m.
Message ID <Pine.LNX.4.64.1007271001510.5121@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/59986/
State New
Headers show

Comments

Joseph S. Myers - July 27, 2010, 10:02 a.m.
On Fri, 2 Jul 2010, Geert Bosch wrote:

> > > <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html> needs C++ and
> > > Ada review.
> > 
> > Ada review still needed.
> 
> Ada changes are OK.

Thanks for the review.  I have now updated the patch to apply to current 
trunk, retested and committed in the following form.

2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* langhooks-def.h (lhd_init_options, LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): New.
	(LANG_HOOKS_INIT_OPTIONS): Update default definition.
	(LANG_HOOKS_INITIALIZER): Add new hooks.
	* langhooks.c (lhd_init_options, lhd_complain_wrong_lang_p): New.
	* langhooks.h (struct lang_hooks): Add new hooks option_lang_mask
	and complain_wrong_lang_p.  Update init_options prototype.
	* c-objc-common.c (c_initialize_diagnostics): First call
	c_common_initialize_diagnostics.
	* c-objc-common.h (LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): Define.
	* coretypes.h (struct cl_option, struct cl_decoded_option):
	Declare.
	* hooks.c (hook_uint_uint_constcharptrptr_0): Remove.
	(hook_uint_void_0): New.
	* hooks.h (hook_uint_uint_constcharptrptr_0): Remove.
	(hook_uint_void_0): New.
	* opts-common.c (decode_cmdline_option,
	decode_cmdline_options_to_array): Also fill in canonical_option
	field.
	* opts.c (complain_wrong_lang): Use langhook to determine whether
	to complain instead of special-casing LTO.
	(decode_options): Separate lang_mask determination with
	option_lang_mask hook from call of init_options hook.
	* opts.h (struct cl_decoded_option): Add canonical_option.

ada:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* gcc-interface/misc.c (gnat_option_lang_mask): New.
	(gnat_init_options): Update prototype.  Reconstruct argv array
	from decoded options.

c-family:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* c-common.h (c_common_option_lang_mask,
	c_common_initialize_diagnostics, c_common_complain_wrong_lang_p):
	New.
	(c_common_init_options): Update prototype.
	* c-opts.c (c_common_option_lang_mask): New.
	(c_common_initialize_diagnostics): Split out of
	c_common_init_options.
	(accept_all_c_family_options, c_common_complain_wrong_lang_p):
	New.
	(c_common_init_options): Update prototype.  Use decoded options in
	search for -lang-asm.

cp:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* cp-objcp-common.c (cxx_initialize_diagnostics): First call
	c_common_initialize_diagnostics.
	* cp-objcp-common.h (LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): Define.

fortran:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* cpp.c (gfc_cpp_init_options): Update prototype.  Use number of
	decoded options in allocating deferred_opt.
	* cpp.h (gfc_cpp_init_options): Update prototype.
	* f95-lang.c (LANG_HOOKS_OPTION_LANG_MASK): Define.
	* gfortran.h (gfc_option_lang_mask): New.
	(gfc_init_options): Update prototype.
	* options.c (gfc_option_lang_mask): New.
	(gfc_init_options): Update prototype.  Pass new arguments to
	gfc_cpp_init_options.

java:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* lang.c (java_option_lang_mask): New.
	(java_init_options): Update prototype.
	(LANG_HOOKS_OPTION_LANG_MASK): Define.

lto:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* lto-lang.c (lto_option_lang_mask, lto_complain_wrong_lang_p):
	New.
	(lto_init_options): Update prototype.
	(LANG_HOOKS_OPTION_LANG_MASK, LANG_HOOKS_COMPLAIN_WRONG_LANG_P):
	Define.

Patch

Index: gcc/hooks.c
===================================================================
--- gcc/hooks.c	(revision 162559)
+++ gcc/hooks.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -176,8 +176,7 @@  hook_int_size_t_constcharptr_int_0 (size
 }
 
 unsigned int
-hook_uint_uint_constcharptrptr_0 (unsigned int a ATTRIBUTE_UNUSED,
-				  const char **b ATTRIBUTE_UNUSED)
+hook_uint_void_0 (void)
 {
   return 0;
 }
Index: gcc/hooks.h
===================================================================
--- gcc/hooks.h	(revision 162559)
+++ gcc/hooks.h	(working copy)
@@ -1,5 +1,5 @@ 
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -73,7 +73,7 @@  extern tree hook_tree_tree_tree_tree_nul
 extern tree hook_tree_tree_tree_tree_3rd_identity (tree, tree, tree);
 extern tree hook_tree_tree_int_treep_bool_null (tree, int, tree *, bool);
 
-extern unsigned hook_uint_uint_constcharptrptr_0 (unsigned, const char **);
+extern unsigned hook_uint_void_0 (void);
 
 extern bool default_can_output_mi_thunk_no_vcall (const_tree, HOST_WIDE_INT,
 						  HOST_WIDE_INT, const_tree);
Index: gcc/opts-common.c
===================================================================
--- gcc/opts-common.c	(revision 162559)
+++ gcc/opts-common.c	(working copy)
@@ -245,10 +245,14 @@  decode_cmdline_option (const char **argv
     {
     case 1:
       decoded->orig_option_with_args_text = argv[0];
+      decoded->canonical_option[0] = argv[0];
+      decoded->canonical_option[1] = NULL;
       break;
     case 2:
       decoded->orig_option_with_args_text = concat (argv[0], " ",
 						    argv[1], NULL);
+      decoded->canonical_option[0] = argv[0];
+      decoded->canonical_option[1] = argv[1];
       break;
     default:
       gcc_unreachable ();
@@ -279,6 +283,8 @@  decode_cmdline_options_to_array (unsigne
   opt_array[0].opt_index = OPT_SPECIAL_program_name;
   opt_array[0].arg = argv[0];
   opt_array[0].orig_option_with_args_text = argv[0];
+  opt_array[0].canonical_option[0] = argv[0];
+  opt_array[0].canonical_option[1] = NULL;
   opt_array[0].value = 1;
   opt_array[0].errors = 0;
   num_decoded_options = 1;
@@ -293,6 +299,8 @@  decode_cmdline_options_to_array (unsigne
 	  opt_array[num_decoded_options].opt_index = OPT_SPECIAL_input_file;
 	  opt_array[num_decoded_options].arg = opt;
 	  opt_array[num_decoded_options].orig_option_with_args_text = opt;
+	  opt_array[num_decoded_options].canonical_option[0] = opt;
+	  opt_array[num_decoded_options].canonical_option[1] = NULL;
 	  opt_array[num_decoded_options].value = 1;
 	  opt_array[num_decoded_options].errors = 0;
 	  num_decoded_options++;
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 162559)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -281,14 +281,19 @@  warning_as_error_callback (int option_in
     }
 }
 
-/* Common initialization before parsing options.  */
+/* Return language mask for option parsing.  */
 unsigned int
-c_common_init_options (unsigned int argc, const char **argv)
+c_common_option_lang_mask (void)
 {
   static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
-  unsigned int i, result;
-  struct cpp_callbacks *cb;
 
+  return lang_flags[c_language];
+}
+
+/* Common diagnostics initialization.  */
+void
+c_common_initialize_diagnostics (diagnostic_context *context)
+{
   /* Register callback for warnings enabled by -Werror=.  */
   register_warning_as_error_callback (warning_as_error_callback);
 
@@ -298,13 +303,37 @@  c_common_init_options (unsigned int argc
     {
       /* By default wrap lines at 80 characters.  Is getenv
 	 ("COLUMNS") preferable?  */
-      diagnostic_line_cutoff (global_dc) = 80;
+      diagnostic_line_cutoff (context) = 80;
       /* By default, emit location information once for every
 	 diagnostic message.  */
-      diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+      diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
     }
 
-  global_dc->opt_permissive = OPT_fpermissive;
+  context->opt_permissive = OPT_fpermissive;
+}
+
+/* Whether options from all C-family languages should be accepted
+   quietly.  */
+static bool accept_all_c_family_options = false;
+
+/* Return whether to complain about a wrong-language option.  */
+bool
+c_common_complain_wrong_lang_p (const struct cl_option *option)
+{
+  if (accept_all_c_family_options
+      && (option->flags & c_family_lang_mask))
+    return false;
+
+  return true;
+}
+
+/* Common initialization before calling option handlers.  */
+void
+c_common_init_options (unsigned int decoded_options_count,
+		       struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  struct cpp_callbacks *cb;
 
   parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
 				ident_hash, line_table);
@@ -327,23 +356,19 @@  c_common_init_options (unsigned int argc
   /* By default, C99-like requirements for complex multiply and divide.  */
   flag_complex_method = 2;
 
-  deferred_opts = XNEWVEC (struct deferred_opt, argc);
-
-  result = lang_flags[c_language];
+  deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
 
   if (c_language == clk_c)
     {
       /* If preprocessing assembly language, accept any of the C-family
 	 front end options since the driver may pass them through.  */
-      for (i = 1; i < argc; i++)
-	if (! strcmp (argv[i], "-lang-asm"))
+      for (i = 1; i < decoded_options_count; i++)
+	if (decoded_options[i].opt_index == OPT_lang_asm)
 	  {
-	    result |= CL_C | CL_ObjC | CL_CXX | CL_ObjCXX;
+	    accept_all_c_family_options = true;
 	    break;
 	  }
     }
-
-  return result;
 }
 
 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 162559)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1,6 +1,6 @@ 
 /* Definitions for c-common.c.
    Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -724,7 +724,12 @@  extern void set_compound_literal_name (t
 
 extern tree build_va_arg (location_t, tree, tree);
 
-extern unsigned int c_common_init_options (unsigned int, const char **);
+struct diagnostic_context;
+
+extern unsigned int c_common_option_lang_mask (void);
+extern void c_common_initialize_diagnostics (struct diagnostic_context *);
+extern bool c_common_complain_wrong_lang_p (const struct cl_option *);
+extern void c_common_init_options (unsigned int, struct cl_decoded_option *);
 extern bool c_common_post_options (const char **);
 extern bool c_common_init (void);
 extern void c_common_finish (void);
Index: gcc/java/lang.c
===================================================================
--- gcc/java/lang.c	(revision 162559)
+++ gcc/java/lang.c	(working copy)
@@ -46,7 +46,8 @@  The Free Software Foundation is independ
 
 static bool java_init (void);
 static void java_finish (void);
-static unsigned int java_init_options (unsigned int, const char **);
+static unsigned int java_option_lang_mask (void);
+static void java_init_options (unsigned int, struct cl_decoded_option *);
 static bool java_post_options (const char **);
 
 static int java_handle_option (size_t scode, const char *arg, int value, int kind);
@@ -121,6 +122,8 @@  struct GTY(()) language_function {
 #define LANG_HOOKS_INIT java_init
 #undef LANG_HOOKS_FINISH
 #define LANG_HOOKS_FINISH java_finish
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK java_option_lang_mask
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS java_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
@@ -525,8 +528,14 @@  lang_init_source (int level)
 }
 
 static unsigned int
-java_init_options (unsigned int argc ATTRIBUTE_UNUSED,
-		   const char **argv ATTRIBUTE_UNUSED)
+java_option_lang_mask (void)
+{
+  return CL_Java;
+}
+
+static void
+java_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		   struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   flag_bounds_check = 1;
   flag_exceptions = 1;
@@ -542,8 +551,6 @@  java_init_options (unsigned int argc ATT
   flag_evaluation_order = 1;
 
   jcf_path_init ();
-
-  return CL_Java;
 }
 
 /* Post-switch processing.  */
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 162559)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -129,8 +129,13 @@  cp_var_mod_type_p (tree type, tree fn)
 void
 cxx_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base = context->printer;
-  cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
+  pretty_printer *base;
+  cxx_pretty_printer *pp;
+
+  c_common_initialize_diagnostics (context);
+
+  base = context->printer;
+  pp = XNEW (cxx_pretty_printer);
   memcpy (pp_base (pp), base, sizeof (pretty_printer));
   pp_cxx_pretty_printer_init (pp);
   context->printer = (pretty_printer *) pp;
Index: gcc/cp/cp-objcp-common.h
===================================================================
--- gcc/cp/cp-objcp-common.h	(revision 162559)
+++ gcc/cp/cp-objcp-common.h	(working copy)
@@ -1,5 +1,6 @@ 
 /* Language hooks common to C++ and ObjC++ front ends.
-   Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Ziemowit Laski  <zlaski@apple.com>
 
 This file is part of GCC.
@@ -40,6 +41,10 @@  extern bool cp_function_decl_explicit_p 
 #define LANG_HOOKS_FINISH cxx_finish
 #undef LANG_HOOKS_CLEAR_BINDING_STACK
 #define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK c_common_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P c_common_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
Index: gcc/c-objc-common.c
===================================================================
--- gcc/c-objc-common.c	(revision 162559)
+++ gcc/c-objc-common.c	(working copy)
@@ -184,8 +184,13 @@  has_c_linkage (const_tree decl ATTRIBUTE
 void
 c_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base = context->printer;
-  c_pretty_printer *pp = XNEW (c_pretty_printer);
+  pretty_printer *base;
+  c_pretty_printer *pp;
+
+  c_common_initialize_diagnostics (context);
+
+  base = context->printer;
+  pp = XNEW (c_pretty_printer);
   memcpy (pp_base (pp), base, sizeof (pretty_printer));
   pp_c_pretty_printer_init (pp);
   context->printer = (pretty_printer *) pp;
Index: gcc/c-objc-common.h
===================================================================
--- gcc/c-objc-common.h	(revision 162559)
+++ gcc/c-objc-common.h	(working copy)
@@ -1,5 +1,6 @@ 
 /* Language hooks common to C and ObjC front ends.
-   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Ziemowit Laski  <zlaski@apple.com>
 
 This file is part of GCC.
@@ -28,6 +29,10 @@  along with GCC; see the file COPYING3.  
 #define LANG_HOOKS_IDENTIFIER_SIZE C_SIZEOF_STRUCT_LANG_IDENTIFIER
 #undef LANG_HOOKS_FINISH
 #define LANG_HOOKS_FINISH c_common_finish
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK c_common_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P c_common_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 162559)
+++ gcc/opts.c	(working copy)
@@ -416,15 +416,7 @@  complain_wrong_lang (const char *text, c
 {
   char *ok_langs, *bad_lang;
 
-  /* The LTO front end inherits all the options from the first front
-     end that was used.  However, not all the original front end
-     options make sense in LTO.
-
-     A real solution would be to filter this in collect2, but collect2
-     does not have access to all the option attributes to know what to
-     filter.  So, in lto1 we silently accept inherited flags and do
-     nothing about it.  */
-  if (lang_mask & CL_LTO)
+  if (!lang_hooks.complain_wrong_lang_p (option))
     return;
 
   ok_langs = write_langs (option->flags);
@@ -715,7 +707,7 @@  decode_options (unsigned int argc, const
   if (first_time_p)
     {
       /* Perform language-specific options initialization.  */
-      initial_lang_mask = lang_mask = lang_hooks.init_options (argc, argv);
+      initial_lang_mask = lang_mask = lang_hooks.option_lang_mask ();
 
       lang_hooks.initialize_diagnostics (global_dc);
 
@@ -732,6 +724,9 @@  decode_options (unsigned int argc, const
 
   decode_cmdline_options_to_array (argc, argv, lang_mask,
 				   decoded_options, decoded_options_count);
+  if (first_time_p)
+    /* Perform language-specific options initialization.  */
+    lang_hooks.init_options (*decoded_options_count, *decoded_options);
 
   /* Scan to see what optimization level has been specified.  That will
      determine the default value of many flags.  */
Index: gcc/opts.h
===================================================================
--- gcc/opts.h	(revision 162559)
+++ gcc/opts.h	(working copy)
@@ -117,6 +117,14 @@  struct cl_decoded_option
      -frecord-gcc-switches.  */
   const char *orig_option_with_args_text;
 
+  /* The canonical form of the option and its argument, for when it is
+     necessary to reconstruct argv elements (in particular, for
+     processing specs and passing options to subprocesses from the
+     driver).  The first element of this array is non-NULL; the second
+     is NULL if the canonical form uses only one argv element,
+     non-NULL otherwise.  */
+  const char *canonical_option[2];
+
   /* For a boolean option, 1 for the true case and 0 for the "no-"
      case.  For an unsigned integer option, the value of the
      argument.  1 in all other cases.  */
Index: gcc/ada/gcc-interface/misc.c
===================================================================
--- gcc/ada/gcc-interface/misc.c	(revision 162559)
+++ gcc/ada/gcc-interface/misc.c	(working copy)
@@ -61,7 +61,9 @@ 
 #include "gigi.h"
 
 static bool gnat_init			(void);
-static unsigned int gnat_init_options	(unsigned int, const char **);
+static unsigned int gnat_option_lang_mask (void);
+static void gnat_init_options		(unsigned int,
+					 struct cl_decoded_option *);
 static int gnat_handle_option		(size_t, const char *, int, int);
 static bool gnat_post_options		(const char **);
 static alias_set_type gnat_get_alias_set (tree);
@@ -85,6 +87,8 @@  static tree gnat_eh_personality		(void);
 #define LANG_HOOKS_IDENTIFIER_SIZE	sizeof (struct tree_identifier)
 #undef  LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT			gnat_init
+#undef  LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK	gnat_option_lang_mask
 #undef  LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS		gnat_init_options
 #undef  LANG_HOOKS_HANDLE_OPTION
@@ -249,22 +253,43 @@  gnat_handle_option (size_t scode, const 
   return 1;
 }
 
-/* Initialize for option processing.  */
+/* Return language mask for option processing.  */
 
 static unsigned int
-gnat_init_options (unsigned int argc, const char **argv)
+gnat_option_lang_mask (void)
 {
-  gnat_argv = (char **) xmalloc (sizeof (argv[0]));
-  gnat_argv[0] = xstrdup (argv[0]);     /* name of the command */
-  gnat_argc = 1;
+  return CL_Ada;
+}
 
-  save_argc = argc;
-  save_argv = argv;
+/* Initialize for option processing.  */
+
+static void
+gnat_init_options (unsigned int decoded_options_count,
+		   struct cl_decoded_option *decoded_options)
+{
+  /* Reconstruct an argv array for use of back_end.adb.
+
+     ??? back_end.adb should not rely on this; instead, it should work
+     with decoded options without such reparsing, to ensure
+     consistency in how options are decoded.  */
+  unsigned int i;
+
+  save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
+  save_argc = 0;
+  for (i = 0; i < decoded_options_count; i++)
+    {
+      save_argv[save_argc++] = decoded_options[i].canonical_option[0];
+      if (decoded_options[i].canonical_option[1] != NULL)
+	save_argv[save_argc++] = decoded_options[i].canonical_option[1];
+    }
+  save_argv[save_argc] = NULL;
+
+  gnat_argv = (char **) xmalloc (sizeof (save_argv[0]));
+  gnat_argv[0] = xstrdup (save_argv[0]);     /* name of the command */
+  gnat_argc = 1;
 
   /* Uninitialized really means uninitialized in Ada.  */
   flag_zero_initialized_in_bss = 0;
-
-  return CL_Ada;
 }
 
 /* Post-switch processing.  */
Index: gcc/fortran/cpp.c
===================================================================
--- gcc/fortran/cpp.c	(revision 162559)
+++ gcc/fortran/cpp.c	(working copy)
@@ -304,8 +304,8 @@  gfc_cpp_temporary_file (void)
 }
 
 void
-gfc_cpp_init_options (unsigned int argc,
-		      const char **argv ATTRIBUTE_UNUSED)
+gfc_cpp_init_options (unsigned int decoded_options_count,
+		      struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   /* Do not create any objects from libcpp here. If no
      preprocessing is requested, this would be wasted
@@ -337,7 +337,8 @@  gfc_cpp_init_options (unsigned int argc,
   gfc_cpp_option.prefix = NULL;
   gfc_cpp_option.sysroot = NULL;
 
-  gfc_cpp_option.deferred_opt = XNEWVEC (gfc_cpp_deferred_opt_t, argc);
+  gfc_cpp_option.deferred_opt = XNEWVEC (gfc_cpp_deferred_opt_t,
+					 decoded_options_count);
   gfc_cpp_option.deferred_opt_count = 0;
 }
 
Index: gcc/fortran/cpp.h
===================================================================
--- gcc/fortran/cpp.h	(revision 162559)
+++ gcc/fortran/cpp.h	(working copy)
@@ -1,4 +1,4 @@ 
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -36,7 +36,8 @@  const char *gfc_cpp_temporary_file (void
 void gfc_cpp_init_0 (void);
 void gfc_cpp_init (void);
 
-void gfc_cpp_init_options (unsigned int argc, const char **argv);
+void gfc_cpp_init_options (unsigned int decoded_options_count,
+			   struct cl_decoded_option *decoded_options);
 
 int gfc_cpp_handle_option(size_t scode, const char *arg, int value);
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 162559)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -2355,7 +2355,9 @@  void gfc_done_2 (void);
 int get_c_kind (const char *, CInteropKind_t *);
 
 /* options.c */
-unsigned int gfc_init_options (unsigned int, const char **);
+unsigned int gfc_option_lang_mask (void);
+void gfc_init_options (unsigned int,
+		       struct cl_decoded_option *);
 int gfc_handle_option (size_t, const char *, int, int);
 bool gfc_post_options (const char **);
 
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c	(revision 162559)
+++ gcc/fortran/f95-lang.c	(working copy)
@@ -101,6 +101,7 @@  static void gfc_init_ts (void);
 #undef LANG_HOOKS_INIT
 #undef LANG_HOOKS_FINISH
 #undef LANG_HOOKS_WRITE_GLOBALS
+#undef LANG_HOOKS_OPTION_LANG_MASK
 #undef LANG_HOOKS_INIT_OPTIONS
 #undef LANG_HOOKS_HANDLE_OPTION
 #undef LANG_HOOKS_POST_OPTIONS
@@ -130,6 +131,7 @@  static void gfc_init_ts (void);
 #define LANG_HOOKS_INIT                 gfc_init
 #define LANG_HOOKS_FINISH               gfc_finish
 #define LANG_HOOKS_WRITE_GLOBALS	gfc_write_global_declarations
+#define LANG_HOOKS_OPTION_LANG_MASK	gfc_option_lang_mask
 #define LANG_HOOKS_INIT_OPTIONS         gfc_init_options
 #define LANG_HOOKS_HANDLE_OPTION        gfc_handle_option
 #define LANG_HOOKS_POST_OPTIONS		gfc_post_options
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 162559)
+++ gcc/fortran/options.c	(working copy)
@@ -53,11 +53,21 @@  set_default_std_flags (void)
 }
 
 
+/* Return language mask for Fortran options.  */
+
+unsigned int
+gfc_option_lang_mask (void)
+{
+  return CL_Fortran;
+}
+
+
 /* Get ready for options handling. Keep in sync with
    libgfortran/runtime/compile_options.c (init_compile_options). */
 
-unsigned int
-gfc_init_options (unsigned int argc, const char **argv)
+void
+gfc_init_options (unsigned int decoded_options_count,
+		  struct cl_decoded_option *decoded_options)
 {
   gfc_source_file = NULL;
   gfc_option.module_dir = NULL;
@@ -143,9 +153,7 @@  gfc_init_options (unsigned int argc, con
   flag_short_enums = targetm.default_short_enums ();
 
   /* Initialize cpp-related options.  */
-  gfc_cpp_init_options(argc, argv);
-
-  return CL_Fortran;
+  gfc_cpp_init_options (decoded_options_count, decoded_options);
 }
 
 
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c	(revision 162559)
+++ gcc/langhooks.c	(working copy)
@@ -337,6 +337,20 @@  lhd_initialize_diagnostics (struct diagn
 {
 }
 
+/* Called to perform language-specific options initialization.  */
+void
+lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		  struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
+{
+}
+
+/* By default, always complain about options for the wrong language.  */
+bool
+lhd_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
+{
+  return true;
+}
+
 /* The default function to print out name of current function that caused
    an error.  */
 void
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h	(revision 162559)
+++ gcc/langhooks.h	(working copy)
@@ -1,5 +1,5 @@ 
 /* The lang_hooks data structure.
-   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -269,15 +269,24 @@  struct lang_hooks
      on unrecognized codes.  */
   size_t (*tree_size) (enum tree_code);
 
-  /* The first callback made to the front end, for simple
-     initialization needed before any calls to handle_option.  Return
-     the language mask to filter the switch array with.  */
-  unsigned int (*init_options) (unsigned int argc, const char **argv);
+  /* Return the language mask used for converting argv into a sequence
+     of options.  */
+  unsigned int (*option_lang_mask) (void);
+
+  /* After the initialize_diagnostics hook is called, do any simple
+     initialization needed before any calls to handle_option.  */
+  void (*init_options) (unsigned int decoded_options_count,
+			struct cl_decoded_option *decoded_options);
 
   /* Callback used to perform language-specific initialization for the
      global diagnostic context structure.  */
   void (*initialize_diagnostics) (struct diagnostic_context *);
 
+  /* Return true if a warning should be given about option OPTION,
+     which is for the wrong language, false if it should be quietly
+     ignored.  */
+  bool (*complain_wrong_lang_p) (const struct cl_option *option);
+
   /* Handle the switch CODE, which has real type enum opt_code from
      options.h.  If the switch takes an argument, it is passed in ARG
      which points to permanent storage.  The handler is responsible for
Index: gcc/coretypes.h
===================================================================
--- gcc/coretypes.h	(revision 162559)
+++ gcc/coretypes.h	(working copy)
@@ -1,5 +1,6 @@ 
 /* GCC core type declarations.
-   Copyright (C) 2002, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -65,6 +66,8 @@  union section;
 typedef union section section;
 struct cl_target_option;
 struct cl_optimization;
+struct cl_option;
+struct cl_decoded_option;
 struct gimple_seq_d;
 typedef struct gimple_seq_d *gimple_seq;
 typedef const struct gimple_seq_d *const_gimple_seq;
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 162559)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -595,16 +595,34 @@  static GTY(()) tree registered_builtin_f
 /* Language hooks.  */
 
 static unsigned int
-lto_init_options (unsigned int argc ATTRIBUTE_UNUSED,
-		  const char **argv ATTRIBUTE_UNUSED)
+lto_option_lang_mask (void)
+{
+  return CL_LTO;
+}
+
+static bool
+lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
+{
+  /* The LTO front end inherits all the options from the first front
+     end that was used.  However, not all the original front end
+     options make sense in LTO.
+
+     A real solution would be to filter this in collect2, but collect2
+     does not have access to all the option attributes to know what to
+     filter.  So, in lto1 we silently accept inherited flags and do
+     nothing about it.  */
+  return false;
+}
+
+static void
+lto_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		  struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   /* By default, C99-like requirements for complex multiply and divide.
      ???  Until the complex method is encoded in the IL this is the only
      safe choice.  This will pessimize Fortran code with LTO unless
      people specify a complex method manually or use -ffast-math.  */
   flag_complex_method = 2;
-
-  return CL_LTO;
 }
 
 /* Handle command-line option SCODE.  If the option takes an argument, it is
@@ -1116,6 +1134,10 @@  static void lto_init_ts (void)
 
 #undef LANG_HOOKS_NAME
 #define LANG_HOOKS_NAME "GNU GIMPLE"
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS lto_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h	(revision 162559)
+++ gcc/langhooks-def.h	(working copy)
@@ -1,5 +1,5 @@ 
 /* Default macros to initialize the lang_hooks data structure.
-   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Alexandre Oliva  <aoliva@redhat.com>
 
@@ -66,6 +66,9 @@  extern tree lhd_builtin_function (tree);
 
 /* Declarations of default tree inlining hooks.  */
 extern void lhd_initialize_diagnostics (struct diagnostic_context *);
+extern void lhd_init_options (unsigned int,
+			      struct cl_decoded_option *);
+extern bool lhd_complain_wrong_lang_p (const struct cl_option *);
 extern tree lhd_callgraph_analyze_expr (tree *, int *);
 
 
@@ -82,8 +85,10 @@  extern void lhd_omp_firstprivatize_type_
 #define LANG_HOOKS_INIT			hook_bool_void_false
 #define LANG_HOOKS_FINISH		lhd_do_nothing
 #define LANG_HOOKS_PARSE_FILE		lhd_do_nothing_i
-#define LANG_HOOKS_INIT_OPTIONS		hook_uint_uint_constcharptrptr_0
+#define LANG_HOOKS_OPTION_LANG_MASK	hook_uint_void_0
+#define LANG_HOOKS_INIT_OPTIONS		lhd_init_options
 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS lhd_initialize_diagnostics
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lhd_complain_wrong_lang_p
 #define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constcharptr_int_0
 #define LANG_HOOKS_MISSING_ARGUMENT	hook_bool_constcharptr_size_t_false
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
@@ -258,8 +263,10 @@  extern void lhd_end_section (void);
   LANG_HOOKS_IDENTIFIER_SIZE, \
   LANG_HOOKS_FREE_LANG_DATA, \
   LANG_HOOKS_TREE_SIZE, \
+  LANG_HOOKS_OPTION_LANG_MASK, \
   LANG_HOOKS_INIT_OPTIONS, \
   LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \
+  LANG_HOOKS_COMPLAIN_WRONG_LANG_P, \
   LANG_HOOKS_HANDLE_OPTION, \
   LANG_HOOKS_MISSING_ARGUMENT, \
   LANG_HOOKS_POST_OPTIONS, \