aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2007-12-07 14:35:22 +0000
committerSamuel Tardieu <sam@gcc.gnu.org>2007-12-07 14:35:22 +0000
commit2eb160f205ce2a807ecdef95b2e88652a5e3f0ed (patch)
tree99ac07d9e57d5b57c2e90cab12cbde419f4ecfb6 /gcc
parente397a9f1b6dcd66e4d5606588c3e3cdf687cf194 (diff)
downloadgcc-2eb160f205ce2a807ecdef95b2e88652a5e3f0ed.zip
gcc-2eb160f205ce2a807ecdef95b2e88652a5e3f0ed.tar.gz
gcc-2eb160f205ce2a807ecdef95b2e88652a5e3f0ed.tar.bz2
re PR ada/15805 (Illegal program not detected, allows writing through access to constant)
gcc/ada/ PR ada/15805 * sem_ch6.adb (Process_Formals): Prevent an access type formal to be initialized with an access to constant object. gcc/testsuite/ PR ada/15805 * gnat.dg/specs/access_constants.ads: New test. From-SVN: r130676
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/sem_ch6.adb14
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/specs/access_constant.ads13
4 files changed, 38 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 5a10332..9ddc6da 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-07 Samuel Tardieu <sam@rfc1149.net>
+
+ PR ada/15805
+ * sem_ch6.adb (Process_Formals): Prevent an access type formal
+ to be initialized with an access to constant object.
+
2007-12-07 Olivier Hainque <hainque@adacore.com>
PR ada/34173
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 69064c2..b2451cb 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -6998,6 +6998,20 @@ package body Sem_Ch6 is
Analyze_Per_Use_Expression (Default, Formal_Type);
+ -- Check that an access to constant is not used with an
+ -- access type.
+
+ if Ekind (Formal_Type) = E_Anonymous_Access_Type
+ and then not Is_Access_Constant (Formal_Type)
+ and then Is_Access_Type (Etype (Default))
+ and then Is_Access_Constant (Etype (Default))
+ then
+ Error_Msg_NE ("parameter of type& cannot be initialized " &
+ "with an access-to-constant expression",
+ Default,
+ Formal_Type);
+ end if;
+
-- Check that the designated type of an access parameter's default
-- is not a class-wide type unless the parameter's designated type
-- is also class-wide.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 12aad8c..2342e5e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-07 Samuel Tardieu <sam@rfc1149.net>
+
+ PR ada/15805
+ * gnat.dg/specs/access_constants.ads: New test.
+
2007-12-07 Olivier Hainque <hainque@adacore.com>
PR ada/34173
diff --git a/gcc/testsuite/gnat.dg/specs/access_constant.ads b/gcc/testsuite/gnat.dg/specs/access_constant.ads
new file mode 100644
index 0000000..fa9829e
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/access_constant.ads
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+package Access_Constant is
+
+ c: aliased constant integer := 3;
+
+ type const_ptr is access constant integer;
+ cp : const_ptr := c'access;
+
+ procedure inc (var_ptr: access integer :=
+ cp) -- { dg-error "access-to-constant" }
+ is abstract;
+
+end Access_Constant;