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] Fix PR50999, serialize frontend specific flags (-fexceptions)


This tries to find a way to prepend explicitly set command-line options
by those implicitly set by the frontend (-fexceptions in this case).
Unfortunately we don't seem to have a good way to extract this information
easily, so for -fexceptions I hope all frontends set that during
init_options_struct.

Another nice flag to preserve would be the complex eval method, as
LTO currently has

static void
lto_init_options_struct (struct gcc_options *opts)
{
  /* 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.  */
  opts->x_flag_complex_method = 2;
}

But we have multiple flags that influence it(?) and none(!?) seems
to be set by Fortran frontend specific code ... (and Fortran sets
most options during post_options).

Joseph, do you have any advise on how to address frontend specific
options in a more general way?  I'm trying to re-construct a
command-line that when processed frontend agnostic would produce
the same end-result in global_options as if going through the frontend.
Is that even possible (do you have option examples that would show
this is impossible?)

Bootstrap/regtest running on x86_64-unknown-linux-gnu.

Thanks,
Richard.

2011-11-07  Richard Guenther  <rguenther@suse.de>

	PR lto/50999
	* lto-opts.c (append_to_collect_gcc_options): Split out from...
	(lto_write_options): ... here.  Prepend frontend specific flags.

Index: gcc/lto-opts.c
===================================================================
*** gcc/lto-opts.c	(revision 181080)
--- gcc/lto-opts.c	(working copy)
*************** along with GCC; see the file COPYING3.
*** 34,60 ****
  #include "diagnostic.h"
  #include "lto-streamer.h"
  #include "toplev.h"
  
  /* Write currently held options to an LTO IL section.  */
  
  void
  lto_write_options (void)
  {
    struct lto_output_stream stream;
    char *section_name;
    struct obstack temporary_obstack;
    unsigned int i, j;
    char *args;
  
    section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
    lto_begin_section (section_name, false);
    memset (&stream, 0, sizeof (stream));
  
    obstack_init (&temporary_obstack);
    for (i = 1; i < save_decoded_options_count; ++i)
      {
        struct cl_decoded_option *option = &save_decoded_options[i];
-       const char *q, *p;
  
        /* Skip frontend and driver specific options here.  */
        if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
--- 34,97 ----
  #include "diagnostic.h"
  #include "lto-streamer.h"
  #include "toplev.h"
+ #include "langhooks.h"
+ 
+ /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
+    set up by OB, appropriately quoted and separated by spaces
+    (if !*FIRST_P).  */
+ 
+ static void
+ append_to_collect_gcc_options (struct obstack *ob,
+ 			       bool *first_p, const char *opt)
+ {
+   const char *p, *q = opt;
+   if (!first_p)
+     obstack_grow (ob, " ", 1);
+   obstack_grow (ob, "'", 1);
+   while ((p = strchr (q, '\'')))
+     {
+       obstack_grow (ob, q, p - q);
+       obstack_grow (ob, "'\\''", 4);
+       q = ++p;
+     }
+   obstack_grow (ob, q, strlen (q));
+   obstack_grow (ob, "'", 1);
+   *first_p = false;
+ }
  
  /* Write currently held options to an LTO IL section.  */
  
  void
  lto_write_options (void)
  {
+   struct gcc_options lang_opts;
    struct lto_output_stream stream;
    char *section_name;
    struct obstack temporary_obstack;
    unsigned int i, j;
    char *args;
+   bool first_p = true;
  
    section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
    lto_begin_section (section_name, false);
    memset (&stream, 0, sizeof (stream));
  
    obstack_init (&temporary_obstack);
+ 
+   /* Output options enabled by the frontend explicitely.  The C family
+      frontends do that in the init_options_struct langhook.  Eventually
+      we should add a langhook that returns a cl_options array that
+      is processed before the user options.  */
+   memset (&lang_opts, 0, sizeof (lang_opts));
+   lang_hooks.init_options_struct (&lang_opts);
+   if (lang_opts.x_flag_exceptions)
+     append_to_collect_gcc_options (&temporary_obstack, &first_p,
+ 				   "-fexceptions");
+ 
+   /* Output explicitely passed options.  */
    for (i = 1; i < save_decoded_options_count; ++i)
      {
        struct cl_decoded_option *option = &save_decoded_options[i];
  
        /* Skip frontend and driver specific options here.  */
        if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
*************** lto_write_options (void)
*** 82,113 ****
  	  break;
  	}
  
!       if (i != 1)
! 	obstack_grow (&temporary_obstack, " ", 1);
!       obstack_grow (&temporary_obstack, "'", 1);
!       q = option->canonical_option[0];
!       while ((p = strchr (q, '\'')))
! 	{
! 	  obstack_grow (&temporary_obstack, q, p - q);
! 	  obstack_grow (&temporary_obstack, "'\\''", 4);
! 	  q = ++p;
! 	}
!       obstack_grow (&temporary_obstack, q, strlen (q));
!       obstack_grow (&temporary_obstack, "'", 1);
! 
!       for (j = 1; j < option->canonical_option_num_elements; ++j)
! 	{
! 	  obstack_grow (&temporary_obstack, " '", 2);
! 	  q = option->canonical_option[j];
! 	  while ((p = strchr (q, '\'')))
! 	    {
! 	      obstack_grow (&temporary_obstack, q, p - q);
! 	      obstack_grow (&temporary_obstack, "'\\''", 4);
! 	      q = ++p;
! 	    }
! 	  obstack_grow (&temporary_obstack, q, strlen (q));
! 	  obstack_grow (&temporary_obstack, "'", 1);
! 	}
      }
    obstack_grow (&temporary_obstack, "\0", 1);
    args = XOBFINISH (&temporary_obstack, char *);
--- 119,127 ----
  	  break;
  	}
  
!       for (j = 0; j < option->canonical_option_num_elements; ++j)
! 	append_to_collect_gcc_options (&temporary_obstack, &first_p,
! 				       option->canonical_option[j]);
      }
    obstack_grow (&temporary_obstack, "\0", 1);
    args = XOBFINISH (&temporary_obstack, char *);


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