[Bug c/28749] New: Miscompilation of glibc/stdio-common/vfprintf.c

carlos at systemhalted dot org gcc-bugzilla@gcc.gnu.org
Wed Aug 16 05:20:00 GMT 2006

This is a regression since 4.1 and 4.0 compile vfprintf.c correctly.

I am using gcc trunk to build libc / libc-ports head. I have a regression in
tst-printfsz which is part of the glibc testsuite. The problem is a
miscompilation of glibc/stdio-common/vfprintf.c by GCC.

The bug is as follows:
Location 1 jumps to location 2.
Compiler moves first insn at location 2 to location 1's branch delay slot.
Location 3 computes a goto to location 2.
Because the first insn at location 2 was moved, the program now crashes.

The concrete debugging example:

The first insn "ldil L%4000,r21" is moved to location 1's branch delay slot.

Location 3:
   468cc:       ea a0 c0 02     bv,n r0(r21)

   r21 == (0x403d3000 + 0x4928c) and is part of "goto *ptr"

Location 1:
   478b4:       82 9c 93 a4     cmpb,<< ret0,r20,4928c <_IO_vfprintf+0x322c>
   478b8:       22 a2 00 00     ldil L%4000,r21

Location 2:                      
   4928c:       36 b5 0a d9     ldo -1a94(r21),r21
   49290:       08 75 0a 15     add,l r21,r3,r21
   49294:       0e a0 10 95     ldw 0(r21),r21
   49298:       92 a0 30 00     cmpiclr,<> 0,r21,r0
   4929c:       e8 1e 0f 45     b,l 46a44 <_IO_vfprintf+0x9e4>,r0
   492a0:       34 15 3f ff     ldi -1,r21

The code at location 3 jumps to location 2, and does not execute the required
"ldil L%4000,r21"

The computed goto should create edges to all the label addresses taken by &&,
and that should prevent the branch delay slot from fill from occuring.

I am recompiling glibc with CFLAGS-vfprintf.c += -fno-delayed-branch to see if
it passes the tst-printfsz test.

How should I proceed on this issue? I have tried to create a testcase, but I
haven't been successfull.

           Summary: Miscompilation of glibc/stdio-common/vfprintf.c
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlos at systemhalted dot org
 GCC build triplet: hppa-linux
  GCC host triplet: hppa-linux
GCC target triplet: hppa-linux


More information about the Gcc-bugs mailing list