aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2018-05-31 10:47:29 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-31 10:47:29 +0000
commit2a35a4ca1429dca015b8c635dc607e8fb7963808 (patch)
tree1c11e3873c2bb91aa4ad11eeeb9622fb5974e14a /gcc
parentd9898483059a497f1f632ab688bcef729e6cb6e0 (diff)
downloadgcc-2a35a4ca1429dca015b8c635dc607e8fb7963808.zip
gcc-2a35a4ca1429dca015b8c635dc607e8fb7963808.tar.gz
gcc-2a35a4ca1429dca015b8c635dc607e8fb7963808.tar.bz2
[Ada] Static predicate check on characters of a string literal
This patch implements the rule given in R< 4.2 (11): if the component type of a string literal is a character type with a static predicate, that predicate must be applied to each character in the string. Compiling the example below must yield: gcc -c -gnata main.adb main.adb:4:23: warning: static expression fails static predicate check on "C" main.adb:4:23: warning: expression is no longer considered static main.adb:4:24: warning: static expression fails static predicate check on "C" main.adb:4:24: warning: expression is no longer considered static main.adb:4:25: warning: static expression fails static predicate check on "C" main.adb:4:25: warning: expression is no longer considered static Execution must yield: raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : Static_Predicate failed at main.adb:4 ---- procedure Main is subtype C is Character with Static_Predicate => C in 'A' | 'B' | 'C'; type S is array (Positive range <>) of C; X : constant S := "abc"; begin null; end; 2018-05-31 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_res.adb (Resolve_String_Literal): If the type is a string type whose component subtype has a static predicate, ensure that the predicate is applied to each character by expanding the string into the equivalent aggregate. This is also done if the component subtype is constrained. From-SVN: r261014
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog8
-rw-r--r--gcc/ada/sem_res.adb8
2 files changed, 14 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 84281e2..f3dce1be 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,11 @@
+2018-05-31 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_res.adb (Resolve_String_Literal): If the type is a string type
+ whose component subtype has a static predicate, ensure that the
+ predicate is applied to each character by expanding the string into the
+ equivalent aggregate. This is also done if the component subtype is
+ constrained.
+
2018-05-31 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (Call_to_gnu): Remove obsolete code.
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 32ea60f..e569cc8 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -10774,7 +10774,9 @@ package body Sem_Res is
-- whether the evaluation of the string will raise constraint error.
-- Otherwise we need to transform the string literal into the
-- corresponding character aggregate and let the aggregate code do
- -- the checking.
+ -- the checking. We use the same transformation if the component
+ -- type has a static predicate, which will be applied to each
+ -- character when the aggregate is resolved.
if Is_Standard_Character_Type (R_Typ) then
@@ -10811,7 +10813,9 @@ package body Sem_Res is
end if;
end loop;
- return;
+ if not Has_Static_Predicate (C_Typ) then
+ return;
+ end if;
end if;
end;
end if;