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]

bug report for c++, gcc 2.95.2


I'm using gcc 2.95.2 to compile my C++ program for
PalmOS 2.0. (I realize that 2.95.2 has been patched
somewhat for PalmOS support for prc-tools 2.0, but the

three lines of code generating the bug seem to be more

gcc-relevant than PalmOS relevant.) I've attached a 
text file describing the bug, and showing the assembly

code where things seem to be going wrong.

If you think this bug is more properly reported to
the developers of the Palm GCC port, please let me
know, and/or (even better) forward to them.

I compiled this source file with -g -O2 -c -fno-rtti
-fno-exceptions -fno-implicit-templates.

Evan Sherbrooke

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
This is the block of code causing the trouble.

    CFloat ret = 0;
    short i;
    for (i=CBSOrder; i < CBSOrder*2-1; i++, first++) {
	ret += GetCpt (first) * basis_[i];
    }

GetCpt is a virtual function; I've verified that the lines doing this
(up to line 0x100a675a) are doing the right thing, and the correct
value is being returned. The trouble is in basis_[i]. basis_ is a
static member of the class that this code snippet is a member function of.
On line 0x100a6740, you can see how register a3 is getting the address
of basis_, and on line 0x100a673a you can see that register d3 is getting
initialized to the value of 4. I should mention here that CBSOrder is
#define'd to be 4.

The trouble is on line 0x100a675c. Notice that this is basically incrementing
i, but incrementing it _before_ looking up basis_[i] (the lookup takes
place in lines 0x100a6764 and 0x100a6768). At the end of the loop, where
you'd expect incrementing to happen, first is getting incremented 
(line 0x100a678e) but i is not.

(gdb) disas 0x100a673a 0x100a6798
Dump of assembler code from 0x100a673a to 0x100a6798:
0x100a673a <EvalDeriv__17CubicBSplineCurved+46>:	moveq #4,%d3
0x100a673c <EvalDeriv__17CubicBSplineCurved+48>:	lea %sp@(18),%sp
0x100a6740 <EvalDeriv__17CubicBSplineCurved+52>:	lea %a5@(-96),%a3
0x100a6744 <EvalDeriv__17CubicBSplineCurved+56>:	moveal %a2@(6),%a0
0x100a6748 <EvalDeriv__17CubicBSplineCurved+60>:	lea %a0@(48),%a1
0x100a674c <EvalDeriv__17CubicBSplineCurved+64>:	movew %fp@(-2),%sp@-
0x100a6750 <EvalDeriv__17CubicBSplineCurved+68>:	moveaw %a1@,%a0
0x100a6752 <EvalDeriv__17CubicBSplineCurved+70>:	
    pea %a0@(00000000,%a2:l)
0x100a6756 <EvalDeriv__17CubicBSplineCurved+74>:	moveal %a1@(4),%a0
0x100a675a <EvalDeriv__17CubicBSplineCurved+78>:	jsr %a0@
0x100a675c <EvalDeriv__17CubicBSplineCurved+80>:	addqw #1,%d3
0x100a675e <EvalDeriv__17CubicBSplineCurved+82>:	movew %d3,%d2
0x100a6760 <EvalDeriv__17CubicBSplineCurved+84>:	extl %d2
0x100a6762 <EvalDeriv__17CubicBSplineCurved+86>:	lsll #3,%d2
0x100a6764 <EvalDeriv__17CubicBSplineCurved+88>:	
    movel %a3@(00000004,%d2:l),%sp@-
0x100a6768 <EvalDeriv__17CubicBSplineCurved+92>:	
    movel %a3@(00000000,%d2:l),%sp@-
0x100a676c <EvalDeriv__17CubicBSplineCurved+96>:	movel %d1,%sp@-
0x100a676e <EvalDeriv__17CubicBSplineCurved+98>:	movel %d0,%sp@-
0x100a6770 <EvalDeriv__17CubicBSplineCurved+100>:	
    bsrw 0x100a55ee <__muldf3>
0x100a6774 <EvalDeriv__17CubicBSplineCurved+104>:	lea %sp@(16),%sp
0x100a6778 <EvalDeriv__17CubicBSplineCurved+108>:	movel %d1,%sp@-
0x100a677a <EvalDeriv__17CubicBSplineCurved+110>:	movel %d0,%sp@-
0x100a677c <EvalDeriv__17CubicBSplineCurved+112>:	movel %d5,%sp@-
0x100a677e <EvalDeriv__17CubicBSplineCurved+114>:	movel %d4,%sp@-
0x100a6780 <EvalDeriv__17CubicBSplineCurved+116>:	
    bsrw 0x100a5572 <__adddf3>
0x100a6784 <EvalDeriv__17CubicBSplineCurved+120>:	lea %sp@(16),%sp
0x100a6788 <EvalDeriv__17CubicBSplineCurved+124>:	movel %d0,%d4
0x100a678a <EvalDeriv__17CubicBSplineCurved+126>:	movel %d1,%d5
0x100a678c <EvalDeriv__17CubicBSplineCurved+128>:	addql #6,%sp
0x100a678e <EvalDeriv__17CubicBSplineCurved+130>:	addqw #1,%fp@(-2)
0x100a6792 <EvalDeriv__17CubicBSplineCurved+134>:	cmpiw #6,%d3
0x100a6796 <EvalDeriv__17CubicBSplineCurved+138>:	
    bles 0x100a6744 <EvalDeriv__17CubicBSplineCurved+56>
End of assembler dump.
(gdb) 

Contrast this with the following piece of nearly identical code, which
works great; the only difference is that i is going from 0 to 3
instead of 4 to 7. Note that the increment of i has been moved to
its proper place (line 0x100a66f6). Weird, huh?


    CFloat ret = 0;
    short i;
    for (i=0; i < CBSOrder; i++, first++) {
	ret += GetCpt (first) * basis_[i];
    }

(gdb) disas 0x100a66a4 0x100a6702
Dump of assembler code from 0x100a66a4 to 0x100a6702:
0x100a66a4 <Eval__17CubicBSplineCurved+44>:	clrw %d3
0x100a66a6 <Eval__17CubicBSplineCurved+46>:	lea %sp@(18),%sp
0x100a66aa <Eval__17CubicBSplineCurved+50>:	lea %a5@(-96),%a3
0x100a66ae <Eval__17CubicBSplineCurved+54>:	moveal %a2@(6),%a0
0x100a66b2 <Eval__17CubicBSplineCurved+58>:	lea %a0@(48),%a1
0x100a66b6 <Eval__17CubicBSplineCurved+62>:	movew %fp@(-2),%sp@-
0x100a66ba <Eval__17CubicBSplineCurved+66>:	moveaw %a1@,%a0
0x100a66bc <Eval__17CubicBSplineCurved+68>:	pea %a0@(00000000,%a2:l)
0x100a66c0 <Eval__17CubicBSplineCurved+72>:	moveal %a1@(4),%a0
0x100a66c4 <Eval__17CubicBSplineCurved+76>:	jsr %a0@
0x100a66c6 <Eval__17CubicBSplineCurved+78>:	movew %d3,%d2
0x100a66c8 <Eval__17CubicBSplineCurved+80>:	extl %d2
0x100a66ca <Eval__17CubicBSplineCurved+82>:	lsll #3,%d2
0x100a66cc <Eval__17CubicBSplineCurved+84>:	
    movel %a3@(00000004,%d2:l),%sp@-
0x100a66d0 <Eval__17CubicBSplineCurved+88>:	
    movel %a3@(00000000,%d2:l),%sp@-
0x100a66d4 <Eval__17CubicBSplineCurved+92>:	movel %d1,%sp@-
0x100a66d6 <Eval__17CubicBSplineCurved+94>:	movel %d0,%sp@-
0x100a66d8 <Eval__17CubicBSplineCurved+96>:	bsrw 0x100a55ee <__muldf3>
0x100a66dc <Eval__17CubicBSplineCurved+100>:	lea %sp@(16),%sp
0x100a66e0 <Eval__17CubicBSplineCurved+104>:	movel %d1,%sp@-
0x100a66e2 <Eval__17CubicBSplineCurved+106>:	movel %d0,%sp@-
0x100a66e4 <Eval__17CubicBSplineCurved+108>:	movel %d5,%sp@-
0x100a66e6 <Eval__17CubicBSplineCurved+110>:	movel %d4,%sp@-
0x100a66e8 <Eval__17CubicBSplineCurved+112>:	bsrw 0x100a5572 <__adddf3>
0x100a66ec <Eval__17CubicBSplineCurved+116>:	lea %sp@(16),%sp
0x100a66f0 <Eval__17CubicBSplineCurved+120>:	movel %d0,%d4
0x100a66f2 <Eval__17CubicBSplineCurved+122>:	movel %d1,%d5
0x100a66f4 <Eval__17CubicBSplineCurved+124>:	addql #6,%sp
0x100a66f6 <Eval__17CubicBSplineCurved+126>:	addqw #1,%d3
0x100a66f8 <Eval__17CubicBSplineCurved+128>:	addqw #1,%fp@(-2)
0x100a66fc <Eval__17CubicBSplineCurved+132>:	cmpiw #3,%d3
0x100a6700 <Eval__17CubicBSplineCurved+136>:	
    bles 0x100a66ae <Eval__17CubicBSplineCurved+54>
End of assembler dump.
(gdb) 

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