The 6.2(12) paragraph reads: "If one name denotes a part of a formal parameter, and a second name denotes a part of a distinct formal parameter or an object that is not part of a formal parameter, then the two names are considered distinct access paths. If an object is of a type for which the parameter passing mechanism is not specified, then it is a bounded error to assign to the object via one access path, and then read the value of the object via a distinct access path, unless the first access path denotes a part of a formal parameter that no longer exists at the point of the second access (due to leaving the corresponding callable construct). The possible consequences are that Program_Error is raised, or the newly assigned value is read, or some old value of the object is read. "
We leverage it to consider that parameters passed by reference at the sole decision of the compiler are restrict-qualified in the C sense. Tested on i586-suse-linux, applied on the mainline. 2011-12-11 Eric Botcazou <ebotca...@adacore.com> * gcc-interface/decl.c (gnat_to_gnu_param): Set the restrict qualifier on references built for parameters which aren't specifically by-ref. -- Eric Botcazou
Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 182201) +++ gcc-interface/decl.c (working copy) @@ -5518,7 +5518,15 @@ gnat_to_gnu_param (Entity_Id gnat_param, || (!foreign && default_pass_by_ref (gnu_param_type))))) { + /* We take advantage of 6.2(12) by considering that references built for + parameters whose type isn't by-ref and for which the mechanism hasn't + been forced to by-ref are restrict-qualified in the C sense. */ + bool restrict_p + = !TREE_ADDRESSABLE (gnu_param_type) && mech != By_Reference; gnu_param_type = build_reference_type (gnu_param_type); + if (restrict_p) + gnu_param_type + = build_qualified_type (gnu_param_type, TYPE_QUAL_RESTRICT); by_ref = true; /* In some ABIs, e.g. SPARC 32-bit, fat pointer types are themselves