Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Compiler Bug in 7.1
@ 2002-07-03 14:16 Martin Frey
  2002-07-04 15:00 ` Martin Frey
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Frey @ 2002-07-03 14:16 UTC (permalink / raw)
  To: axp-list

[-- Attachment #1: Type: text/plain, Size: 1125 bytes --]

Hi,

when compiling the attached program I hit a bug in the
compiler as shipped in Redhat 7.1 (gcc-2.96-87).

Can someone with a Redhat 7.2 installation compile
it and send me the assembler output? If the bug
is also in 7.2 I will try to submit a bug report.

You need to compile it towards a kernel tree that
is configured for SMP and EV6 CPUs.
With ommiting the -mcpu=ev6 compiler option the
problem disappears.

What happens:
when calling an inline function (bogus_inline in the
example) the inlining of the function fails.
At the begin of the function the argument calculated
inside the inline gets computed half through and
stored on the stack [ 80($30) ]. The first instance
of the inline functions used the half computed argument
from the stack while the second instance computes all over
correctly and used the correct result.
Details are in the comments in the C code.

Regards, Martin

-- 
Supercomputing Systems AG       email: frey@scs.ch
Martin Frey                     web:   http://www.scs.ch/~frey/
Technoparkstrasse 1             phone: +41 1 445 16 00
CH-8005 Zuerich                 fax:   +41 1 445 16 10

[-- Attachment #2: gccbug.c --]
[-- Type: application/octet-stream, Size: 2543 bytes --]

/* compile with
   
gcc  -D__KERNEL__ -D__SMP__ -Wall -Wstrict-prototypes -O2 \
     -fomit-frame-pointer -fno-strict-aliasing -pipe -mno-fp-regs -ffixed-8 \
     -mcpu=ev6 -Wa,-mev6 -I/usr/src/linux-2.4.3-12/include -o gccbug.S -S gccbug.c

*/

#include <linux/mm.h>
#include <linux/smp_lock.h>
#include <asm/atomic.h>

struct foo;
struct bar {
        atomic_t atom;
        struct inode *ip;
};



void external_function(struct vm_area_struct *vma, struct inode *vp, struct bar *bar, struct foo *foo);
struct inode *second_external_function(unsigned long var_a, unsigned long var_b, int c);

void function_with_wrong_args(unsigned long var_a, unsigned long var_b,
                              int wrong_flag, int var_d);
static inline void bogus_inline(unsigned long var_a, unsigned long var_b,
                                  int flag, int var_d)
{
        /* the bug occurs only with the pairs 11:3 and 8:3. These
           combination can be calculated with a s4addq or s8addq.
           Changing e.g. the 11:3 to 10:3 avoids the bug.
        */
        function_with_wrong_args(var_a, var_b, flag ? 11: 3, var_d);
}


void bugy_function(struct foo *foo, unsigned long var_a, unsigned long var_b, int var_c)
{
	struct address_space *mapping = NULL;
	struct bar *bar= NULL;
        struct inode *vp = NULL;

	vp = second_external_function(var_b, var_a, 0);

        mapping = vp->i_mapping;
        bar = vp->u.generic_ip;

        if(S_ISDIR(vp->i_mode)) goto almost_end;
retry:
	if (atomic_read(&bar->atom)) {
		struct vm_area_struct *vma;

		spin_lock(&mapping->i_shared_lock);

		vma = mapping->i_mmap_shared;
		while (vma) {
                        if (var_c)
				external_function(vma, vp, bar, foo);
			vma = vma->vm_next_share;
		}
		vma = mapping->i_mmap;
		while (vma) {
			external_function(vma, vp, bar, foo);
			vma = vma->vm_next_share;
		}
		spin_unlock(&mapping->i_shared_lock);

	}

        /* this call ends up buggy. The var_c gets computed in
           the inline function as
           cmpult $31, $13, $1
           and stored on the stack with
           stl $1, 80($30)
           and the arguments gets then reloaded with
           ldl $18, 80($30)
        */
        
        bogus_inline(var_a, var_b, var_c, 0);

	if (var_c)
                goto retry;

	goto end;
        
almost_end:
        /* here we got the right computation of var_c
           in the inline function:
           cmpult $31,$13,$18
           s8addq $18,3,$18
        */

	bogus_inline(var_a, var_b, var_c, 0);
  end:
        
}


[-- Attachment #3: gccbug.S --]
[-- Type: application/octet-stream, Size: 2107 bytes --]

	.file	1 "gccbug.c"
	.set noat
	.set noreorder
	.arch ev6
.text
	.align 4
	.globl bugy_function
	.ent bugy_function
bugy_function:
	.frame $30,96,$26,0
	.mask 0x400fe00,-96
	ldgp $29,0($27)
$bugy_function..ng:
	lda $30,-96($30)
	stq $18,72($30)
	mov $31,$18
	stq $15,56($30)
	mov $16,$15
	ldq $16,72($30)
	stq $11,24($30)
	stq $12,32($30)
	stq $13,40($30)
	mov $19,$13
	stq $14,48($30)
	stq $26,0($30)
	stq $9,8($30)
	stq $10,16($30)
	.prologue 1
	stq $17,64($30)
	jsr $26,second_external_function
	ldgp $29,0($26)
	ldah $2,1
	mov $0,$12
	lda $2,-4096($2)
	ldl $1,80($12)
	ldq $14,288($12)
	ldq $11,480($12)
	and $1,$2,$1
	zapnot $1,15,$1
	lda $1,-16384($1)
	beq $1,$L782
// here we do the first half of the computation
// and store it on the stack.
	cmpult $31,$13,$1
	stl $1,80($30)
$L783:
	ldl $1,0($11)
	beq $1,$L784
	lda $10,96($14)
	1:	ldl_l	$1,0($10)
	blbs	$1,2f
	or	$1,1,$1
	stl_c	$1,0($10)
	beq	$1,2f
	mb
.subsection 2
2:	ldl	$1,0($10)
	blbs	$1,2b
	br	1b
.previous
	ldq $9,88($14)
	beq $9,$L800
	.align 4
$L787:
	mov $9,$16
	mov $12,$17
	mov $11,$18
	mov $15,$19
	beq $13,$L788
	jsr $26,external_function
	ldgp $29,0($26)
$L788:
	ldq $9,72($9)
	bne $9,$L787
$L800:
	ldq $9,80($14)
	beq $9,$L801
	.align 4
$L792:
	mov $9,$16
	mov $12,$17
	mov $11,$18
	mov $15,$19
	jsr $26,external_function
	ldgp $29,0($26)
	ldq $9,72($9)
	bne $9,$L792
$L801:
	mb
	stl $31,0($10)
$L784:
// here we fetch the first half of the computation
// and use it. The s8addq instruction is missing!
	ldl $18,80($30)
	ldq $16,64($30)
	mov $31,$19
	ldq $17,72($30)
	jsr $26,function_with_wrong_args
	ldgp $29,0($26)
	beq $13,$L797
	br $31,$L783
	.align 4
$L782:
	ldq $16,64($30)
	ldq $17,72($30)
// here we do the whole computation as it should
// be: cmpult + s8addq!
	cmpult $31,$13,$18
	mov $31,$19
	s8addq $18,3,$18
	jsr $26,function_with_wrong_args
	ldgp $29,0($26)
$L797:
	ldq $26,0($30)
	ldq $9,8($30)
	ldq $10,16($30)
	ldq $11,24($30)
	ldq $12,32($30)
	ldq $13,40($30)
	ldq $14,48($30)
	ldq $15,56($30)
	lda $30,96($30)
	ret $31,($26),1
	.end bugy_function
	.ident	"GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-87)"

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

end of thread, other threads:[~2002-07-04 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-03 14:16 Compiler Bug in 7.1 Martin Frey
2002-07-04 15:00 ` Martin Frey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox