aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2016-11-13 18:08:25 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2016-11-13 18:08:25 +0000
commit96826e28ef9a627b82f1d7ccda0906f20dfe96d5 (patch)
treea48f85ec10e25a6592a4c4e4dde297541dd8d217 /gcc
parent854c00dd69de6b13c1dc8d75948360420e4816d6 (diff)
downloadgcc-96826e28ef9a627b82f1d7ccda0906f20dfe96d5.zip
gcc-96826e28ef9a627b82f1d7ccda0906f20dfe96d5.tar.gz
gcc-96826e28ef9a627b82f1d7ccda0906f20dfe96d5.tar.bz2
utils2.c (gnat_protect_expr): Also protect only the address if the expression is the component of a dereference.
* gcc-interface/utils2.c (gnat_protect_expr): Also protect only the address if the expression is the component of a dereference. Do not use a reference type for the final temporary reference. From-SVN: r242358
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/gcc-interface/utils2.c10
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/renaming11.adb12
-rw-r--r--gcc/testsuite/gnat.dg/renaming11.ads19
5 files changed, 48 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index e498316..f896d14 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,5 +1,11 @@
2016-11-13 Eric Botcazou <ebotcazou@adacore.com>
+ * gcc-interface/utils2.c (gnat_protect_expr): Also protect only the
+ address if the expression is the component of a dereference.
+ Do not use a reference type for the final temporary reference.
+
+2016-11-13 Eric Botcazou <ebotcazou@adacore.com>
+
* gcc-interface/Makefile.in (NO_OMIT_ADAFLAGS): Define.
(a-except.o): Replace -fno-inline with NO_INLINE_ADAFLAGS.
(s-memory.o): New rule.
diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c
index c0d831f..fc6f1b8 100644
--- a/gcc/ada/gcc-interface/utils2.c
+++ b/gcc/ada/gcc-interface/utils2.c
@@ -2586,6 +2586,12 @@ gnat_protect_expr (tree exp)
return t;
}
+ /* Likewise if we're indirectly referencing part of something. */
+ if (code == COMPONENT_REF
+ && TREE_CODE (TREE_OPERAND (exp, 0)) == INDIRECT_REF)
+ return build3 (code, type, gnat_protect_expr (TREE_OPERAND (exp, 0)),
+ TREE_OPERAND (exp, 1), NULL_TREE);
+
/* If this is a COMPONENT_REF of a fat pointer, save the entire fat pointer.
This may be more efficient, but will also allow us to more easily find
the match for the PLACEHOLDER_EXPR. */
@@ -2605,9 +2611,7 @@ gnat_protect_expr (tree exp)
/* Otherwise reference, protect the address and dereference. */
return
build_unary_op (INDIRECT_REF, type,
- save_expr (build_unary_op (ADDR_EXPR,
- build_reference_type (type),
- exp)));
+ save_expr (build_unary_op (ADDR_EXPR, NULL_TREE, exp)));
}
/* This is equivalent to stabilize_reference_1 in tree.c but we take an extra
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ee0282c..a273920 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2016-11-13 Eric Botcazou <ebotcazou@adacore.com>
+ * gnat.dg/renaming11.ad[sb]: New test.
+
+2016-11-13 Eric Botcazou <ebotcazou@adacore.com>
+
* c-c++-common/dump-ada-spec-6.c: New test.
2016-11-13 Eric Botcazou <ebotcazou@adacore.com>
diff --git a/gcc/testsuite/gnat.dg/renaming11.adb b/gcc/testsuite/gnat.dg/renaming11.adb
new file mode 100644
index 0000000..c9241c2
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/renaming11.adb
@@ -0,0 +1,12 @@
+-- { dg-do compile }
+
+package body Renaming11 is
+
+ function F (Arg: Ptr3) return Integer is
+ V : Ptr1 renames Arg.all.all;
+ I : Integer renames V.A(1);
+ begin
+ return I;
+ end;
+
+end Renaming11;
diff --git a/gcc/testsuite/gnat.dg/renaming11.ads b/gcc/testsuite/gnat.dg/renaming11.ads
new file mode 100644
index 0000000..d3dda72
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/renaming11.ads
@@ -0,0 +1,19 @@
+package Renaming11 is
+
+ subtype Index_Type is Integer range 1..10;
+
+ type Arr is array (Index_Type range <>) of Integer;
+
+ type Rec (Min : Index_Type; Max : Index_Type) is record
+ A : Arr (Min .. Max);
+ end record;
+
+ type Ptr1 is access Rec;
+
+ type Ptr2 is access Ptr1;
+
+ type Ptr3 is access Ptr2;
+
+ function F (Arg : Ptr3) return Integer;
+
+end Renaming11;