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]

Re: More use of structures in option processing


On Thu, 30 Sep 2010, Jakub Jelinek wrote:

> On Thu, Sep 30, 2010 at 12:48:27PM +0000, Joseph S. Myers wrote:
> > * The optimize and optimize_size variables move into the gcc_options
> >   structure (so requiring the changes to files that redeclare them or
> >   that have function parameters with those names).
> 
> This change broke Ada bootstrap it seems, ada/opts.ads has
>    Optimization_Level : Int;                                                                                                                       
>    pragma Import (C, Optimization_Level, "optimize");                                                                                              
>    --  Constant reflecting the optimization level (0,1,2,3 for -O0,-O1,-O2,-O3)                                                                    
>    --  See jmissing.c and aamissing.c for definitions for dotnet/jgnat and                                                                         
>    --  GNAAMP back ends.                                                                                                                           
>                                                                                                                                                    
>    Optimize_Size : Int;                                                                                                                            
>    pragma Import (C, Optimize_Size, "optimize_size");                                                                                              
>    --  Constant reflecting setting of -Os (optimize for size). Set to nonzero                                                                      
>    --  in -Os mode and set to zero otherwise. See jmissing.c and aamissing.c                                                                       
>    --  for definitions of "optimize_size" for dotnet/jgnat and GNAAMP backends                                                                     
> 
> No idea whether it is possible just to change the "optimize" string to
> "global_options.x_optimize" or whether some other change is needed.

The following is a minimal fix to define these variables for Ada.  It at 
least allows Ada-enabled stage 1 to build; OK to commit?  (Ada doesn't 
appear to have any equivalent of the "optimize" attribute that would allow 
these variable settings to change after the post_options hook is called so 
setting variables in that hook should be sufficient.)

In general it would be best for Ada to avoid accessing variables and 
functions from core GCC directly like this from Ada code, as such uses 
will break when something becomes a macro, or fail to break in an obvious 
way if the type of a function or variable changes incompatibly.  Thus I'd 
advise the Ada maintainers to consider making the code use gnat_optimize 
and gnat_optimize_size or similar variables here (so avoiding the #undef), 
and similarly using Ada-specific copies (set in the gnat_post_options 
hook) of flag_stack_check and flag_compare_debug.  This seems in 
accordance with the Ada-language code trying to avoid being too closely 
tied to the GCC back end except via the gcc-interface code.

(I don't see any actual *use* of the imported Optimize_Size, so maybe 
everything related to that variable could simply go away.  But 
Optimization_Level is used.)

2010-09-30  Joseph Myers  <joseph@codesourcery.com>

	* gcc-interface/misc.c (optimize, optimize_size): Undefine as
	macros and define as variables.
	(gnat_post_options): Set optimize and optimize_size variables.

Index: gcc-interface/misc.c
===================================================================
--- gcc-interface/misc.c	(revision 164751)
+++ gcc-interface/misc.c	(working copy)
@@ -303,6 +303,13 @@ gnat_init_options (unsigned int decoded_
   flag_zero_initialized_in_bss = 0;
 }
 
+/* Ada code requires variables for these settings rather than elements
+   of the global_options structure.  */
+#undef optimize
+#undef optimize_size
+int optimize;
+int optimize_size;
+
 /* Post-switch processing.  */
 
 static bool
@@ -334,6 +341,9 @@ gnat_post_options (const char **pfilenam
   if (write_symbols == DWARF2_DEBUG)
     use_gnu_debug_info_extensions = gnat_dwarf_extensions > 0;
 
+  optimize = global_options.x_optimize;
+  optimize_size = global_options.x_optimize_size;
+
   return false;
 }
 

-- 
Joseph S. Myers
joseph@codesourcery.com


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