* [Ada] Fix handling of 'Image acting as a prefix of a slice in CodePeer
@ 2021-10-04 8:47 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-10-04 8:47 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
[-- Attachment #1: Type: text/plain, Size: 932 bytes --]
In CodePeer mode attribute Image is not expanded and has its Etype set
as the unconstrained String type. When this attribute appears as a
prefix of an indexed component, we get a check; when it appears as a
prefix of a slice, we don't get a check.
For indexed components, the check effectively comes from
Apply_Scalar_Range_Check, where prefixes of unconstrained array types
are handled specifically. For slices, the seemingly similar routine
Apply_Range_Check doesn't specifically handle such prefixes. Instead, we
need to give this routine a constrained subtype, just like we do when
slice is prefixed with a call to a function that returns an
unconstrained array.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_res.adb (Resolve_Slice): Add custom handling of attribute
Image and similar in CodePeer mode. This complements the
existing custom handling of these attributes in
Expand_N_Attribute_Reference.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1028 bytes --]
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -11275,10 +11275,20 @@ package body Sem_Res is
end;
end if;
+ -- In CodePeer mode the attribute Image is not expanded, so when it
+ -- acts as a prefix of a slice, we handle it like a call to function
+ -- returning an unconstrained string. Same for the Wide variants of
+ -- attribute Image.
+
elsif Is_Entity_Name (Name)
or else Nkind (Name) = N_Explicit_Dereference
or else (Nkind (Name) = N_Function_Call
and then not Is_Constrained (Etype (Name)))
+ or else (CodePeer_Mode
+ and then Nkind (Name) = N_Attribute_Reference
+ and then Attribute_Name (Name) in Name_Image
+ | Name_Wide_Image
+ | Name_Wide_Wide_Image)
then
Array_Type := Get_Actual_Subtype (Name);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-04 8:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 8:47 [Ada] Fix handling of 'Image acting as a prefix of a slice in CodePeer Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).