This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/16176] New: Miscompilation of unaligned data in MIPS backend (SB1 flavor)


Configure spec:
Configured with: /p3/jim/GCC/gcc-3.4.0/configure
--prefix=/usr/local/EQLGCC_v340/mips64el --enable-languages=c,c++
--target=mips64el-elf --with-newlib --with-arch=sb1 --with-tune=sb1
--with-gnu-as --with-gnu-ld
Thread model: single

The following trivial test program is miscompiled in a way that causes a crash:

struct foo
{
    short x;
    struct foo *p __attribute__((packed));
    short z;
};

struct foo *list;

int walklist(struct foo *p)
{
    int t = 0;
    while (p)
    {
        t += p->x;
        p = p->p;
    }
    return t;
}

The generated code looks like this:

	.file	1 "test.c"
	.section .mdebug.abiO64
	.previous
	.text
	.align	2
	.globl	walklist
	.ent	walklist
walklist:
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	
	beq	$4,$0,$L6
	move	$3,$0

$L4:
	lh	$2,0($4)
	lwl	$4,5($4)
	lwr	$4,2($4)
	bne	$4,$0,$L4
	addu	$3,$3,$2

$L6:
	j	$31
	move	$2,$3

	.set	macro
	.set	reorder
	.end	walklist

	.comm	list,4,4

The error is that an unaligned load is a two-instruction sequence, so you CANNOT
use the same register as source and destination.  The code as shown will crash
when it comes to the null pointer at the end of the list.

The above is with -O1; with -O2 the code is reordered slightly but the code is
wrong in the same way.

-- 
           Summary: Miscompilation of unaligned data in MIPS backend (SB1
                    flavor)
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P1
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pkoning at equallogic dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-netbsd
  GCC host triplet: i386-netbsd
GCC target triplet: mips64el-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16176


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]