]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fe.h (Suppress_Checks): Declare.
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 8 Nov 2018 15:58:16 +0000 (15:58 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 8 Nov 2018 15:58:16 +0000 (15:58 +0000)
* fe.h (Suppress_Checks): Declare.
* gcc-interface/misc.c (gnat_init_gcc_eh): Set -fnon-call-exceptions
only if checks are not suppressed and -faggressive-loop-optimizations
only if they are.
* gcc-interface/trans.c (struct loop_info_d): Remove has_checks and
warned_aggressive_loop_optimizations fields.
(gigi): Do not clear warn_aggressive_loop_optimizations here.
(Raise_Error_to_gnu): Do not set has_checks.
(gnat_to_gnu) <N_Indexed_Component>: Remove support for aggressive
loop optimizations.

From-SVN: r265923

13 files changed:
gcc/ada/ChangeLog
gcc/ada/fe.h
gcc/ada/gcc-interface/misc.c
gcc/ada/gcc-interface/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/null_pointer_deref1.adb
gcc/testsuite/gnat.dg/null_pointer_deref2.adb
gcc/testsuite/gnat.dg/null_pointer_deref3.adb
gcc/testsuite/gnat.dg/opt74.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt74_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt74_pkg.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/warn12.adb [deleted file]
gcc/testsuite/gnat.dg/warn12_pkg.ads [deleted file]

index 0873a0cc0483e9e4435985230b6b53a419d760d5..7f5333f79d6b407bf67763c1a689b3e62ac58300 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-08  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * fe.h (Suppress_Checks): Declare.
+       * gcc-interface/misc.c (gnat_init_gcc_eh): Set -fnon-call-exceptions
+       only if checks are not suppressed and -faggressive-loop-optimizations
+       only if they are.
+       * gcc-interface/trans.c (struct loop_info_d): Remove has_checks and
+       warned_aggressive_loop_optimizations fields.
+       (gigi): Do not clear warn_aggressive_loop_optimizations here.
+       (Raise_Error_to_gnu): Do not set has_checks.
+       (gnat_to_gnu) <N_Indexed_Component>: Remove support for aggressive
+       loop optimizations.
+
 2018-10-22  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/utils.c (unchecked_convert): Use local variables for
index 6d31ae1a5654171c79c8d9b349d28594c63012c5..d02b55fe441b45807b9a8dcdfd9e11d61d3285cd 100644 (file)
@@ -177,6 +177,7 @@ extern Boolean In_Same_Source_Unit              (Node_Id, Node_Id);
 #define GNAT_Mode                      opt__gnat_mode
 #define List_Representation_Info       opt__list_representation_info
 #define No_Strict_Aliasing_CP          opt__no_strict_aliasing
+#define Suppress_Checks                opt__suppress_checks
 
 typedef enum {
   Front_End_SJLJ, Back_End_ZCX, Back_End_SJLJ
@@ -191,6 +192,7 @@ extern Boolean Generate_SCO_Instance_Table;
 extern Boolean GNAT_Mode;
 extern Int List_Representation_Info;
 extern Boolean No_Strict_Aliasing_CP;
+extern Boolean Suppress_Checks;
 
 #define ZCX_Exceptions            opt__zcx_exceptions
 #define SJLJ_Exceptions           opt__sjlj_exceptions
index 11570f0987f3ad59b0a2fd66b29673e1b017fa0f..c9f1c7455315030873df0eb4b745997d2baf8414 100644 (file)
@@ -396,7 +396,7 @@ gnat_init_gcc_eh (void)
   using_eh_for_cleanups ();
 
   /* Turn on -fexceptions, -fnon-call-exceptions and -fdelete-dead-exceptions.
-     The first one triggers the generation of the necessary exception tables.
+     The first one activates the support for exceptions in the compiler.
      The second one is useful for two reasons: 1/ we map some asynchronous
      signals like SEGV to exceptions, so we need to ensure that the insns
      which can lead to such signals are correctly attached to the exception
@@ -406,10 +406,18 @@ gnat_init_gcc_eh (void)
      for such calls to actually raise in Ada.
      The third one is an optimization that makes it possible to delete dead
      instructions that may throw exceptions, most notably loads and stores,
-     as permitted in Ada.  */
+     as permitted in Ada.
+     Turn off -faggressive-loop-optimizations because it may optimize away
+     out-of-bound array accesses that we want to be able to catch.
+     If checks are disabled, we use the same settings as the C++ compiler.  */
   flag_exceptions = 1;
-  flag_non_call_exceptions = 1;
   flag_delete_dead_exceptions = 1;
+  if (!Suppress_Checks)
+    {
+      flag_non_call_exceptions = 1;
+      flag_aggressive_loop_optimizations = 0;
+      warn_aggressive_loop_optimizations = 0;
+    }
 
   init_eh ();
 }
index b8d593b6ea5891034d40db8480cf66c0dcd1969c..14de1fbdf61992c7b943b5e0ebec325af3a313d2 100644 (file)
@@ -198,8 +198,6 @@ struct GTY(()) loop_info_d {
   tree high_bound;
   vec<range_check_info, va_gc> *checks;
   bool artificial;
-  bool has_checks;
-  bool warned_aggressive_loop_optimizations;
 };
 
 typedef struct loop_info_d *loop_info;
@@ -658,10 +656,6 @@ gigi (Node_Id gnat_root,
   /* Now translate the compilation unit proper.  */
   Compilation_Unit_to_gnu (gnat_root);
 
-  /* Disable -Waggressive-loop-optimizations since we implement our own
-     version of the warning.  */
-  warn_aggressive_loop_optimizations = 0;
-
   /* Then process the N_Validate_Unchecked_Conversion nodes.  We do this at
      the very end to avoid having to second-guess the front-end when we run
      into dummy nodes during the regular processing.  */
@@ -5644,7 +5638,6 @@ Raise_Error_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
              rci->inserted_cond
                = build1 (SAVE_EXPR, boolean_type_node, boolean_true_node);
              vec_safe_push (loop->checks, rci);
-             loop->has_checks = true;
              gnu_cond = build_noreturn_cond (gnat_to_gnu (gnat_cond));
              if (flag_unswitch_loops)
                gnu_cond = build_binary_op (TRUTH_ANDIF_EXPR,
@@ -5657,14 +5650,6 @@ Raise_Error_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
                                            gnu_cond,
                                            rci->inserted_cond);
            }
-
-         /* Or else, if aggressive loop optimizations are enabled, we just
-            record that there are checks applied to iteration variables.  */
-         else if (optimize
-                  && flag_aggressive_loop_optimizations
-                  && inside_loop_p ()
-                  && (loop = find_loop_for (gnu_index)))
-           loop->has_checks = true;
        }
       break;
 
@@ -6280,45 +6265,9 @@ gnat_to_gnu (Node_Id gnat_node)
            gcc_assert (TREE_CODE (gnu_type) == ARRAY_TYPE);
            gnat_temp = gnat_expr_array[i];
            gnu_expr = maybe_character_value (gnat_to_gnu (gnat_temp));
-           struct loop_info_d *loop;
 
            gnu_result
              = build_binary_op (ARRAY_REF, NULL_TREE, gnu_result, gnu_expr);
-
-           /* Array accesses are bound-checked so they cannot trap, but this
-              is valid only if they are not hoisted ahead of the check.  We
-              need to mark them as no-trap to get decent loop optimizations
-              in the presence of -fnon-call-exceptions, so we do it when we
-              know that the original expression had no side-effects.  */
-           if (TREE_CODE (gnu_result) == ARRAY_REF
-               && !(Nkind (gnat_temp) == N_Identifier
-                    && Ekind (Entity (gnat_temp)) == E_Constant))
-             TREE_THIS_NOTRAP (gnu_result) = 1;
-
-           /* If aggressive loop optimizations are enabled, we warn for loops
-              overrunning a simple array of size 1 not at the end of a record.
-              This is aimed to catch misuses of the trailing array idiom.  */
-           if (optimize
-               && flag_aggressive_loop_optimizations
-               && inside_loop_p ()
-               && TREE_CODE (TREE_TYPE (gnu_type)) != ARRAY_TYPE
-               && TREE_CODE (gnu_array_object) != ARRAY_REF
-               && tree_int_cst_equal (TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_type)),
-                                      TYPE_MAX_VALUE (TYPE_DOMAIN (gnu_type)))
-               && !array_at_struct_end_p (gnu_result)
-               && (loop = find_loop_for (gnu_expr))
-               && !loop->artificial
-               && !loop->has_checks
-               && tree_int_cst_equal (TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_type)),
-                                      loop->low_bound)
-               && can_be_lower_p (loop->low_bound, loop->high_bound)
-               && !loop->warned_aggressive_loop_optimizations
-               && warning (OPT_Waggressive_loop_optimizations,
-                           "out-of-bounds access may be optimized away"))
-             {
-               inform (EXPR_LOCATION (loop->stmt), "containing loop");
-               loop->warned_aggressive_loop_optimizations = true;
-             }
          }
 
        gnu_result_type = get_unpadded_type (Etype (gnat_node));
index 3a49cb38afccd7d5c963850e9f91e073814e0df2..3564bfdc6b021d0ffc1a01ec77f5b12f0d28e6e7 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-08  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/null_pointer_deref1.adb: Remove -gnatp and add pragma.
+       * gnat.dg/null_pointer_deref2.adb: Likewise.
+       * gnat.dg/null_pointer_deref3.adb: Likewise.
+       * gnat.dg/opt74.adb: New test.
+       * gnat.dg/opt74_pkg.ad[sb]: New helper.
+       * gnat.dg/warn12.adb: Delete.
+       * gnat.dg/warn12_pkg.ads: Likewise.
+
 2018-11-03  Tobias Burnus  <burnus@net-b.de>
        Thomas Koenig  <tkoenig@gcc.gnu.org>
 
index ec7f9460559604ea12a040e606552757504b8e5f..0f030b001bd17781c4fa06eb311d1da64d330f10 100644 (file)
@@ -1,11 +1,13 @@
 -- { dg-do run }
--- { dg-options "-gnatp" }
 
 -- This test requires architecture- and OS-specific support code for unwinding
 -- through signal frames (typically located in *-unwind.h) to pass.  Feel free
 -- to disable it if this code hasn't been implemented yet.
 
 procedure Null_Pointer_Deref1 is
+
+   pragma Suppress (All_Checks);
+
    type Int_Ptr is access all Integer;
 
    function Ident return Int_Ptr is
index 284762216c566af3bc35862f5ac659e0904ba2bb..2a4ed0954bb185c7c49bdd1caf7e9871dee9364f 100644 (file)
@@ -1,5 +1,4 @@
 -- { dg-do run }
--- { dg-options "-gnatp" }
 
 -- This test requires architecture- and OS-specific support code for unwinding
 -- through signal frames (typically located in *-unwind.h) to pass.  Feel free
@@ -7,6 +6,8 @@
 
 procedure Null_Pointer_Deref2 is
 
+   pragma Suppress (All_Checks);
+
    task T;
 
    task body T is
index f92242e7e6795c0e15970918535a02a4980b1e14..c8e66a6c94aa62407e8ff79de9f75337d98321d8 100644 (file)
@@ -1,5 +1,4 @@
 -- { dg-do run }
--- { dg-options "-O -gnatp" }
 
 -- This test requires architecture- and OS-specific support code for unwinding
 -- through signal frames (typically located in *-unwind.h) to pass.  Feel free
@@ -7,6 +6,8 @@
 
 procedure Null_Pointer_Deref3 is
 
+   pragma Suppress (All_Checks);
+
    procedure Leaf is
       type Int_Ptr is access all Integer;
       function n return Int_Ptr is
diff --git a/gcc/testsuite/gnat.dg/opt74.adb b/gcc/testsuite/gnat.dg/opt74.adb
new file mode 100644 (file)
index 0000000..8eacaa5
--- /dev/null
@@ -0,0 +1,13 @@
+-- { dg-do run }
+-- { dg-options "-O2" }
+
+with Opt74_Pkg; use Opt74_Pkg;
+
+procedure Opt74 is
+   Index, Found : Integer;
+begin
+   Proc (Found, Index);
+   if Found = 1 then
+      raise Program_Error;
+   end if;
+end;
diff --git a/gcc/testsuite/gnat.dg/opt74_pkg.adb b/gcc/testsuite/gnat.dg/opt74_pkg.adb
new file mode 100644 (file)
index 0000000..4d5ce4f
--- /dev/null
@@ -0,0 +1,16 @@
+package body Opt74_Pkg is
+
+   procedure Proc (Found : out Integer; Index : out Integer) is
+   begin
+      Index := 1;
+      Found := 0;
+      while (Index <= A'Last) and (Found = 0) loop
+         if A (Index) = 2 then
+            Found := 1;
+         else
+            Index := Index + 1;
+         end if;
+      end loop;
+   end;
+
+end Opt74_Pkg;
diff --git a/gcc/testsuite/gnat.dg/opt74_pkg.ads b/gcc/testsuite/gnat.dg/opt74_pkg.ads
new file mode 100644 (file)
index 0000000..7c8e85e
--- /dev/null
@@ -0,0 +1,7 @@
+package Opt74_Pkg is
+
+   A : array (1 .. 10) of Integer := (others => 0);
+
+   procedure Proc (Found : out Integer; Index : out Integer);
+
+end Opt74_Pkg;
diff --git a/gcc/testsuite/gnat.dg/warn12.adb b/gcc/testsuite/gnat.dg/warn12.adb
deleted file mode 100644 (file)
index 8ffd0c7..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
--- { dg-do compile }\r
--- { dg-options "-O2" }\r
-\r
-with Text_IO; use Text_IO;\r
-with System.Storage_Elements; use System.Storage_Elements;\r
-with Warn12_Pkg; use Warn12_Pkg;\r
-\r
-procedure Warn12 (N : Natural) is\r
-\r
-   Buffer_Size : constant Storage_Offset\r
-      := Token_Groups'Size/System.Storage_Unit + 4096;\r
-\r
-   Buffer : Storage_Array (1 .. Buffer_Size);\r
-   for Buffer'Alignment use 8;\r
-\r
-   Tg1 : Token_Groups;\r
-   for Tg1'Address use Buffer'Address;\r
-\r
-   Tg2 : Token_Groups;\r
-   pragma Warnings (Off, Tg2);\r
-\r
-   sid : Sid_And_Attributes;\r
-\r
-   pragma Suppress (Index_Check, Sid_And_Attributes_Array);\r
-\r
-begin\r
-\r
-   for I in 0 .. 7 loop\r
-      sid :=  Tg1.Groups(I);  -- { dg-bogus "out-of-bounds access" }\r
-      Put_Line("Iteration");\r
-   end loop;\r
-\r
-   for I in 0 .. N loop\r
-      sid :=  Tg1.Groups(I);  -- { dg-bogus "out-of-bounds access" }\r
-      Put_Line("Iteration");\r
-   end loop;\r
-\r
-   for I in 0 .. 7 loop\r
-      sid :=  Tg2.Groups(I);  -- { dg-warning "out-of-bounds access" }\r
-      Put_Line("Iteration");\r
-   end loop;\r
-\r
-   for I in 0 .. N loop\r
-      sid :=  Tg2.Groups(I);  -- { dg-warning "out-of-bounds access" }\r
-      Put_Line("Iteration");\r
-   end loop;\r
-\r
-end;\r
diff --git a/gcc/testsuite/gnat.dg/warn12_pkg.ads b/gcc/testsuite/gnat.dg/warn12_pkg.ads
deleted file mode 100644 (file)
index b3191cc..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-with Interfaces.C; use Interfaces.C;
-with System;
-
-package Warn12_Pkg is
-
-   Anysize_Array: constant := 0;
-
-   type Sid_And_Attributes is record
-      Sid        : System.Address;
-      Attributes : Interfaces.C.Unsigned_Long;
-   end record;
-
-   type Sid_And_Attributes_Array
-      is array (Integer range 0..Anysize_Array) of aliased Sid_And_Attributes;
-
-   type Token_Groups is record
-      GroupCount : Interfaces.C.Unsigned_Long;
-      Groups     : Sid_And_Attributes_Array;
-   end record;
-
-end Warn12_Pkg;