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]

[Ada] Enable -fstrict-overflow at all optimization levels


The Ada compiler generates overflow checks by default (as required by the 
language) so it makes sense to enable -fstrict-overflow at all optimization 
levels; this mainly affects -O1 in practice.

Tested on x86_64-suse-linux, applied on the mainline.


2015-11-18  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/misc.c: Move global variables to the top of the file.
	(gnat_handle_option): Remove obsolete ATTRIBUTE_UNUSED markers.
	(gnat_init_options): Minor tweak.
	(gnat_post_options): Set -fstrict-overflow if not done by the user.
	(internal_error_function): Minor reformatting.


2015-11-18  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt52.adb: New test.

-- 
Eric Botcazou
Index: gcc-interface/misc.c
===================================================================
--- gcc-interface/misc.c	(revision 230557)
+++ gcc-interface/misc.c	(working copy)
@@ -62,9 +62,28 @@ void *callgraph_info_file = NULL;
 unsigned int save_argc;
 const char **save_argv;
 
-/* GNAT argc and argv.  */
+/* GNAT argc and argv generated by the binder for all Ada programs.  */
 extern int gnat_argc;
-extern char **gnat_argv;
+extern const char **gnat_argv;
+
+/* Ada code requires variables for these settings rather than elements
+   of the global_options structure because they are imported.  */
+int gnat_encodings = 0;
+
+#undef optimize
+int optimize;
+
+#undef optimize_size
+int optimize_size;
+
+#undef flag_compare_debug
+int flag_compare_debug;
+
+#undef flag_short_enums
+int flag_short_enums;
+
+#undef flag_stack_check
+enum stack_check_type flag_stack_check = NO_STACK_CHECK;
 
 #ifdef __cplusplus
 extern "C" {
@@ -118,9 +137,8 @@ gnat_option_lang_mask (void)
    are marked as Ada-specific.  Return true on success or false on failure.  */
 
 static bool
-gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value,
-		    int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
-		    const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
+gnat_handle_option (size_t scode, const char *arg, int value, int kind,
+		    location_t loc, const struct cl_option_handlers *handlers)
 {
   enum opt_code code = (enum opt_code) scode;
 
@@ -164,8 +182,8 @@ gnat_handle_option (size_t scode, const
 
   Ada_handle_option_auto (&global_options, &global_options_set,
 			  scode, arg, value,
-			  gnat_option_lang_mask (), kind,
-			  loc, handlers, global_dc);
+			  gnat_option_lang_mask (), kind, loc,
+			  handlers, global_dc);
   return true;
 }
 
@@ -194,11 +212,9 @@ gnat_init_options (unsigned int decoded_
      ??? 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++)
+  for (unsigned int i = 0; i < decoded_options_count; i++)
     {
       size_t num_elements = decoded_options[i].canonical_option_num_elements;
 
@@ -223,25 +239,12 @@ gnat_init_options (unsigned int decoded_
     }
   save_argv[save_argc] = NULL;
 
-  gnat_argv = (char **) xmalloc (sizeof (save_argv[0]));
-  gnat_argv[0] = xstrdup (save_argv[0]);     /* name of the command */
+  /* Pass just the name of the command through the regular channel.  */
+  gnat_argv = (const char **) xmalloc (sizeof (char *));
+  gnat_argv[0] = xstrdup (save_argv[0]);
   gnat_argc = 1;
 }
 
-/* Ada code requires variables for these settings rather than elements
-   of the global_options structure.  */
-#undef optimize
-#undef optimize_size
-#undef flag_compare_debug
-#undef flag_short_enums
-#undef flag_stack_check
-int gnat_encodings = 0;
-int optimize;
-int optimize_size;
-int flag_compare_debug;
-int flag_short_enums;
-enum stack_check_type flag_stack_check = NO_STACK_CHECK;
-
 /* Settings adjustments after switches processing by the back-end.
    Note that the front-end switches processing (Scan_Compiler_Arguments)
    has not been done yet at this point!  */
@@ -262,6 +265,10 @@ gnat_post_options (const char **pfilenam
   if (!global_options_set.x_flag_diagnostics_show_caret)
     global_dc->show_caret = false;
 
+  /* Set strict overflow by default for Ada.  */
+  if (!global_options_set.x_flag_strict_overflow)
+    global_options.x_flag_strict_overflow = true;
+
   /* Warn only if STABS is not the default: we don't want to emit a warning if
      the user did not use a -gstabs option.  */
   if (PREFERRED_DEBUGGING_TYPE != DBX_DEBUG && write_symbols == DBX_DEBUG)
@@ -287,8 +294,8 @@ gnat_post_options (const char **pfilenam
 /* Here is the function to handle the compiler error processing in GCC.  */
 
 static void
-internal_error_function (diagnostic_context *context,
-			 const char *msgid, va_list *ap)
+internal_error_function (diagnostic_context *context, const char *msgid,
+			 va_list *ap)
 {
   text_info tinfo;
   char *buffer, *p, *loc;
-- { dg-do compile }
-- { dg-options "-O -fdump-tree-optimized" }

procedure Opt52 (I : Integer) is
begin
  if I + 1 < I then
    raise Program_Error;
  end if;
end;

-- { dg-final { scan-tree-dump-not "check_PE_Explicit_Raise" "optimized" } }

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