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]

[EGCS 2.96, 2000/01/17 snapshot] Bad assembly code


The attached file "bug.c" makes the compiler emit code erroneous in that

  bug.c:0: #define VAL (1<<7)
  bug.c:7: if (i & VAL) {

is compiled (via `gcc -S -g bug.c`) as

  bug.s:44: andl    $-128, %eax

which should be $128 (0xffffff80 vs. 0x00000080), since "(1<<7)" is a 
type int expression (-128 would have been the correct value if VAL was 
of type signed char).  Note: this also happened with the 2000/01/03
snapshot.

Attaching both "bug.c" and "bug.s".

  OS:             Linux 2.3.36
  compiler:       EGCS 2.96, 2000/01/17 snapshot
  compiler setup: native i586-pc-linux-gnu, configure switches:
                    --enable-shared --prefix=/usr
  glibc version:  2.1.2
#define VAL (1<<7)

int main()
{
  int i;

  if (i & VAL) {  /* <-- results in bad code */
    i = 0;  /* dummy instruction */
  }
}
	.file	"bug.c"
	.version	"01.01"
.stabs "/home/gomar/bug/",100,0,0,.Ltext0
.stabs "bug.c",100,0,0,.Ltext0
.text
.Ltext0:
	.stabs	"gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
.stabs "long int:t(0,3)=r(0,3);-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,4);0000000000000;0037777777777;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,5);0000000000000;0037777777777;",128,0,0,0
.stabs "long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long long unsigned int:t(0,7)=@s64;r(0,7);0000000000000;01777777777777777777777;",128,0,0,0
.stabs "short int:t(0,8)=@s16;r(0,8);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,9)=@s16;r(0,9);0;65535;",128,0,0,0
.stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,0,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,0,0
.stabs "long double:t(0,14)=r(0,1);12;0;",128,0,0,0
.stabs "complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
.stabs "complex float:t(0,16)=r(0,16);4;0;",128,0,0,0
.stabs "complex double:t(0,17)=r(0,17);8;0;",128,0,0,0
.stabs "complex long double:t(0,18)=r(0,18);12;0;",128,0,0,0
.stabs "void:t(0,19)=(0,19)",128,0,0,0
.stabs "__builtin_va_list:t(0,20)=*(0,19)",128,0,0,0
	.align 16
.stabs "main:F(0,1)",36,0,4,main
.globl main
	.type	 main,@function
main:
	.stabn 68,0,4,.LM1-main
.LM1:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	.stabn 68,0,5,.LM2-main
.LM2:
.LBB2:
	.stabn 68,0,7,.LM3-main
.LM3:
	movb	-4(%ebp), %al
	andl	$-128, %eax
	testb	%al, %al
	je	.L3
	.stabn 68,0,8,.LM4-main
.LM4:
	movl	$0, -4(%ebp)
.L3:
	.stabn 68,0,10,.LM5-main
.LM5:
.LBE2:
	.stabn 68,0,10,.LM6-main
.LM6:
.L2:
	movl	%ebp, %esp
	popl	%ebp
	ret
.Lfe1:
	.size	 main,.Lfe1-main
.stabs "i:(0,1)",128,0,5,-4
.stabn 192,0,0,.LBB2-main
.stabn 224,0,0,.LBE2-main
.Lscope0:
.stabs "",36,0,0,.Lscope0-main
	.text
	.stabs "",100,0,0,Letext
Letext:
	.ident	"GCC: (GNU) 2.96 20000117 (experimental)"

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