This is a regression present since the 4.5.x series at least. We generate wrong code (infinite loop for the testcase) for the renaming of a volatile packed array with an address clause.
Tested on i586-suse-linux, applied on the trunk, 4.6 and 4.5 branches. 2012-01-21 Eric Botcazou <ebotca...@adacore.com> PR ada/46192 * gcc-interface/decl.c (gnat_to_gnu_entity) <object>: In the case of a renaming, preserve the volatileness through the indirection, if any. 2012-01-21 Eric Botcazou <ebotca...@adacore.com> * gnat.dg/renaming5.ad[sb]: New test. -- Eric Botcazou
Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 183348) +++ gcc-interface/decl.c (working copy) @@ -1051,6 +1051,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entit entity is always accessed indirectly through it. */ else { + /* We need to preserve the volatileness of the renamed + object through the indirection. */ + if (TREE_THIS_VOLATILE (gnu_expr) + && !TYPE_VOLATILE (gnu_type)) + gnu_type + = build_qualified_type (gnu_type, + (TYPE_QUALS (gnu_type) + | TYPE_QUAL_VOLATILE)); gnu_type = build_reference_type (gnu_type); inner_const_flag = TREE_READONLY (gnu_expr); const_flag = true;
-- PR ada/46192 -- Testcase by Rolf Ebert <rolf.ebert....@gmx.de> -- { dg-do compile } -- { dg-options "-O2 -fdump-tree-optimized" } with System; use System; package body Renaming5 is type Bits_In_Byte is array (0 .. 7) of Boolean; pragma Pack (Bits_In_Byte); A : Bits_In_Byte; for A'Address use System'To_Address(16#c0#); pragma Volatile (A); B : Bits_In_Byte renames A; procedure Proc is begin while B (0) = False loop null; end loop; end; end Renaming5; -- { dg-final { scan-tree-dump-times "goto" 2 "optimized" } } -- { dg-final { cleanup-tree-dump "optimized" } }
package Renaming5 is procedure Proc; end Renaming5;