This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
It is now illegal to use Unrestricted_Access to directly generate a thin pointer of an unconstrained array type which references a non- aliased object. This never worked, and we might as well catch it as illegal, since it is not hard to do so, as shown in the following example: 1. with System; use System; 2. procedure SliceUA2 is 3. type A is access all String; 4. for A'Size use Standard'Address_Size; 5. 6. procedure P (Arg : A) is 7. begin 8. null; 9. end P; 10. 11. X : String := "hello world!"; 12. X2 : aliased String := "hello world!"; 13. 14. AV : A := X'Unrestricted_Access; -- ERROR | >>> illegal use of Unrestricted_Access attribute >>> attempt to generate thin pointer to unaliased object 15. 16. begin 17. P (X'Unrestricted_Access); -- ERROR | >>> illegal use of Unrestricted_Access attribute >>> attempt to generate thin pointer to unaliased object 18. P (X(7 .. 12)'Unrestricted_Access); -- ERROR | >>> illegal use of Unrestricted_Access attribute >>> attempt to generate thin pointer to unaliased object 19. P (X2'Unrestricted_Access); -- OK 20. end; However we can't catch all cases, so some cases just remain erroneous: 1. with System; use System; 2. procedure SliceUA is 3. type AF is access all String; 4. 5. type A is access all String; 6. for A'Size use Standard'Address_Size; 7. 8. procedure P (Arg : A) is 9. begin 10. if Arg'Length /= 6 then 11. raise Program_Error; 12. end if; 13. end P; 14. 15. X : String := "hello world!"; 16. Y : AF := X (7 .. 12)'Unrestricted_Access; 17. 18. begin 19. P (A (Y)); 20. end; Here the conversion in the call on line 19 from a fat pointer to a thin pointer is erroneous, and executing this program inevitably raises Program_Error since the bounds get lost in the conversion. Tested on x86_64-pc-linux-gnu, committed on trunk 2014-07-16 Robert Dewar <dewar@adacore.com> * gnat_rm.texi: Document illegal case of Unrestricted_Access. * sem_attr.adb (Analyze_Access_Attribute): Set_Non_Aliased_Prefix where it applies. (Resolve_Attribute, case Access): Flag illegal Unrestricted_Access use. * sinfo.ads, sinfo.adb (Non_Aliased_Prefix): New flag.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |