https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122282

            Bug ID: 122282
           Summary: [target, ppc64-linux] return of small character array
                    not according to ABI spec
           Product: gcc
           Version: 14.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider gdb test-case gdb.ada/return-small-char-array:
...
$ ls gdb/testsuite/gdb.ada/return-small-char-array
proc.adb  value.adb  value.ads
...

Compiled like so, on cfarm121 with gcc 14.3.0:
...
$ gnatmake proc.adb value.adb -g
powerpc64-linux-gnu-gcc-14 -c -g proc.adb
powerpc64-linux-gnu-gcc-14 -c -g value.adb
powerpc64-linux-gnu-gnatbind-14 -x proc.ali
powerpc64-linux-gnu-gnatlink-14 proc.ali -g
powerpc64-linux-gnu-gcc-14 -c -g value.adb
$ 
...

After using gdb to step into value.name, we have:
...
(gdb) p Of_Value
$1 = "abcd"
(gdb) ptype Of_Value
type = <ref> array (1 .. 4) of character
(gdb)
...
and one instruction before returning from that function, r3 has the value:
...
(gdb) p /x $r3
$3 = 0x3fffffffedb0
(gdb) p /x *$r3
$4 = 0x61626364
(gdb) 
...

Assuming that gcc intends to implement this spec (
https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html ), this is
a bug in GCC because the spec states that:
...
Character arrays of length 8 bytes or less, ... , will be returned right
justified in r3.
...

But instead, r3 is a pointer to the character array.

Reply via email to