aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-08-12 08:59:18 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-08-12 08:59:18 +0000
commit1361a4fbe10d119c76339f06992ac60de54f124d (patch)
treea5e0312929d92335c340069f16d6098fbc1a2393
parent935b02aea97d8d2aa40e65e908228c4666cb1803 (diff)
downloadgcc-1361a4fbe10d119c76339f06992ac60de54f124d.zip
gcc-1361a4fbe10d119c76339f06992ac60de54f124d.tar.gz
gcc-1361a4fbe10d119c76339f06992ac60de54f124d.tar.bz2
[Ada] Fix leak of Do_Range_Check flag in -gnatVa mode
This fixes a small glitch in Insert_Valid_Check, which needs to propagate the Do_Range_Check flag onto the rewritten expression, but uses its Original_Node as the source of the copy. Now Original_Node does not necessarily point to the node that was just rewritten, but to the ultimately original node, which is not the same node if the expression was rewritten multiple times. The end result is that a stalled Do_Range_Check flag can be wrongly resintated and leak to the code generator. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Insert_Valid_Check): Do not retrieve the Do_Range_Check flag from the Original_Node but from the Validated_Object. Remove useless bypass for floating-point types. gcc/testsuite/ * gnat.dg/range_check7.adb: New testcase. From-SVN: r274285
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/checks.adb13
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/range_check7.adb22
4 files changed, 38 insertions, 8 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 2f3ec7b..362efba 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2019-08-12 Eric Botcazou <ebotcazou@adacore.com>
+
+ * checks.adb (Insert_Valid_Check): Do not retrieve the
+ Do_Range_Check flag from the Original_Node but from the
+ Validated_Object. Remove useless bypass for floating-point
+ types.
+
2019-08-12 Yannick Moy <moy@adacore.com>
* sem_util.adb, sem_util.ads (Traverse_More_Func,
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 5d8efce..470ea3f 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -7589,17 +7589,14 @@ package body Checks is
Set_Validated_Object (Var_Id, New_Copy_Tree (Exp));
- -- Reset the Do_Range_Check flag so it doesn't leak elsewhere
-
- Set_Do_Range_Check (Validated_Object (Var_Id), False);
-
Rewrite (Exp, New_Occurrence_Of (Var_Id, Loc));
- -- Copy the Do_Range_Check flag over to the new Exp, so it doesn't
- -- get lost. Floating point types are handled elsewhere.
+ -- Move the Do_Range_Check flag over to the new Exp so it doesn't
+ -- get lost and doesn't leak elsewhere.
- if not Is_Floating_Point_Type (Typ) then
- Set_Do_Range_Check (Exp, Do_Range_Check (Original_Node (Exp)));
+ if Do_Range_Check (Validated_Object (Var_Id)) then
+ Set_Do_Range_Check (Exp);
+ Set_Do_Range_Check (Validated_Object (Var_Id), False);
end if;
PV := New_Occurrence_Of (Var_Id, Loc);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 90ce94d..ad20649 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2019-08-12 Eric Botcazou <ebotcazou@adacore.com>
+ * gnat.dg/range_check7.adb: New testcase.
+
+2019-08-12 Eric Botcazou <ebotcazou@adacore.com>
+
* gnat.dg/range_check6.adb: New testcase.
2019-08-11 Iain Buclaw <ibuclaw@gdcproject.org>
diff --git a/gcc/testsuite/gnat.dg/range_check7.adb b/gcc/testsuite/gnat.dg/range_check7.adb
new file mode 100644
index 0000000..def43c9
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/range_check7.adb
@@ -0,0 +1,22 @@
+-- { dg-do compile }
+-- { dg-options "-gnatVa" }
+
+procedure Range_Check7 is
+
+ type Short is range -32768 .. 32767;
+
+ type Int is range -2 ** 31 .. 2 ** 31 - 1;
+
+ subtype Nat is Int range 0 .. Int'Last;
+
+ type Ptr is access all Short;
+
+ procedure Proc (P : Ptr) is
+ N : constant Nat := Nat (P.all);
+ begin
+ null;
+ end;
+
+begin
+ null;
+end;