public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/16176] New: Miscompilation of unaligned data in MIPS backend (SB1 flavor)
@ 2004-06-24 15:38 pkoning at equallogic dot com
  2004-06-24 15:56 ` [Bug target/16176] " pkoning at equallogic dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: pkoning at equallogic dot com @ 2004-06-24 15:38 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-06-28 16:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-24 15:38 [Bug target/16176] New: Miscompilation of unaligned data in MIPS backend (SB1 flavor) pkoning at equallogic dot com
2004-06-24 15:56 ` [Bug target/16176] " pkoning at equallogic dot com
2004-06-24 17:26 ` pkoning at equallogic dot com
2004-06-24 18:26 ` rsandifo at gcc dot gnu dot org
2004-06-25 18:34 ` cvs-commit at gcc dot gnu dot org
2004-06-25 18:37 ` pkoning at equallogic dot com
2004-06-25 18:52 ` [Bug target/16176] [3.4 Regression] " rsandifo at gcc dot gnu dot org
2004-06-25 18:56 ` mark at codesourcery dot com
2004-06-28 14:00 ` cvs-commit at gcc dot gnu dot org
2004-06-28 14:17 ` rsandifo at gcc dot gnu dot org
2004-06-28 16:30 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).