https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119643
Bug ID: 119643 Summary: Subprogram parameter subtypes in renaming-as-declaration are not ignored Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: mnpjm6zqj6tckbx8zscf at mailbox dot org CC: dkm at gcc dot gnu.org Target Milestone: --- Created attachment 61015 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61015&action=edit Source of the test program reproducing the bug Ada's subprogram "renaming-as-declaration" takes subprogram subtypes from the profile of the renamed entity. ARM 2022 [8.5.4] Subprogram Renaming Declarations [1] says: > Static Semantics > A renaming-as-declaration declares a new view of the renamed entity. > The profile of this new view takes its subtypes, parameter modes, and > calling convention from the original profile of the callable entity, > while taking the formal parameter names and default_expressions from > the profile given in the subprogram_renaming_declaration. The new > view is a function or procedure, never an entry. This formulation does not forbid changes to the subtypes in a subprogram renaming-as-declaration. It warrants, however, that any changed subtypes are not to be considered. Tests show that in a subprogram renaming declaration a changed return subtype has no effect (as expected). On the other hand, changed parameter subtypes seem to be adopted into the new view of a subprogram (instead of being ignored). The following program illustrates the erroneous behaviour. ```ada with Ada.Text_IO; procedure Rename_Subprogram_Types is function Incr (V : Integer; I : Integer := 1) return Integer is (V + I); function Incr_Ren (V : Integer; I : Positive := 1) return Positive renames Incr; -- function Incr_Ren (V : Integer; I : Integer := 1) return Positive renames Incr; procedure Test_Incr (V : Integer; I : Integer := 1) is Blab : constant String := ("Incr_Ren (" & V'Image & ", " & I'Image & ") = "); begin Ada.Text_IO.Put (Blab); Ada.Text_IO.Put (Incr_Ren (V, I)'Image); Ada.Text_IO.Put (" (subtypes Positive ignored)"); Ada.Text_IO.New_Line; end Test_Incr; begin Test_Incr (-3); Test_Incr (-3, 2); Test_Incr (-3, 0); exception when Constraint_Error => Ada.Text_IO.Put_Line ("Constraint_Error on parameter subtype Positive"); end Rename_Subprogram_Types; ``` Expected output: ```text Incr_Ren (-3, 1) = -2 (subtypes Positive ignored) Incr_Ren (-3, 2) = -1 (subtypes Positive ignored) Incr_Ren (-3, 0) = -3 (subtypes Positive ignored) ``` Actual output: ```console Incr_Ren (-3, 1) = -2 (subtypes Positive ignored) Incr_Ren (-3, 2) = -1 (subtypes Positive ignored) Incr_Ren (-3, 0) = Constraint_Error on parameter subtype Positive ``` Note: It is enough to swap the comment in the two `Incr_Ren` lines to get the expected output. Environment information: ```console # BUILD COMMAND # $ gnatmake -gnatwae rename_subprogram_types.adb gcc -c -gnatwae rename_subprogram_types.adb gnatbind -x rename_subprogram_types.ali gnatlink rename_subprogram_types.ali # GCC VERSION # $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.2.1-build/gcc-14.2.1-20250110/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.2.1 20250110 (Red Hat 14.2.1-7) (GCC) # SYSTEM INFORMATION # $ uname -mors Linux 6.13.8-200.fc41.x86_64 x86_64 GNU/Linux ``` [1] www.ada-auth.org/standards/22rm/html/RM-8-5-4.html