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]

Re: EEGCS-1.1.2 bug: handling signed bitfields on ARM processor



Several bugs in bit-field handling were fixed in gcc-2.95; I believe this 
was one of them.  Certainly the development sources seem to be doing the 
right thing now and I get

        ldr     r3, [fp, #-20]
        bic     r3, r3, #1048576000
        orr     r3, r3, #20971520
        str     r3, [fp, #-20]

for the bit of code you cited.

Can you try the latest release (2.95.1) and let me know if that does not 
fix your problem.

Richard.

> Dear Sirs,
> 
> I have found a bug in the egcs-C-compiler, handling (signed) bitfields
> for ARM processor architecture.
> If a signed bitfield is not aligned to a byte boundary, and written with 
> a negative value, this is done by a word access and the instructions "mvn"
> (e.g.:
> 	ldr	ip, [fp, #-16]			!!! error ???
> 	mvn	ip, ip, asl #22			!!! this code sets all upper
> 	mvn	ip, ip, lsr #22			!!! bits too
> 	str	ip, [fp, #-16]			!!! error ???
> ).
> But these instructions sets all upper bits of this word too!
> 
> Example C-code: If in the structure "test_t" the bitfield "d" is set to
> "-1",
> the bits of the elements a,b,c are also set all "1".
> 
> I have appended the following:
> 
> 1. the C-code generating the wrong assembler code output
> 2. the output of the program
> 3. cross compiler version, host OS version, and compiler call
> 4. the assembler output. The error lines are marked with "!!!"
> 
> Hope I give you all information you need.
> 
> best regards
> 
> Stefan
> Sami-Soueiha
> 
> ---------------------------------------------------------------------------
> | Dipl.-Ing. Stefan Sami-Soueiha                 Tel.: +49 911 9673-0    
> |
> | BinTec Communications AG                       Fax : +49 911 9673-1499 
> |
> | Suedwestpark 94                                http://www.bintec.de    
> |
> | D-90449 Nuernberg/Germany                      email: sami@bintec.de   
> |
> ---------------------------------------------------------------------------
> 
> Appendix:
> ---------
> 
> 1. C-code:
> ---------
> void func()
> {
>     typedef struct {
>             unsigned    a:3;
>             unsigned    b:5;
>             int         c:6;
>             int         d:8;
>             unsigned    e:8;
>     } test_t;
> 
>     test_t test;
>     memset(&test, 0 , sizeof(test));
> 
>     test.a = 1;
>     printf("1.a-e: %d %d %d %d %d\n",test.a,test.b,test.c,test.d,test.e);
>     test.b = 2;
>     printf("2.a-e: %d %d %d %d %d\n",test.a,test.b,test.c,test.d,test.e);
>     test.c = 3;
>     printf("3.a-e: %d %d %d %d %d\n",test.a,test.b,test.c,test.d,test.e);
>     test.d = -1;
>     printf("4.a-e: %d %d %d %d %d\n",test.a,test.b,test.c,test.d,test.e);
>     test.e = 5;
>     printf("5.a-e: %d %d %d %d %d\n",test.a,test.b,test.c,test.d,test.e);
> }
> 
> 2. Output:
> -----------
> 1.a-e: 1 0 0 0 0
> 2.a-e: 1 2 0 0 0
> 3.a-e: 1 2 3 0 0
> 4.a-e: 7 31 63 255 0
> 5.a-e: 7 31 63 255 5
> 
> 3. Compiler version/call:
> -------------------------
> 
> %uname -a
> SunOS junior 5.6 Generic_105181-14 sun4u sparc SUNW,Ultra-4
> 
> install-configure:
> ./configure --with-gnu-as --with-gnu-ld --target=arm-aout
> --prefix=/local/bin.SOLARIS_ARM 
> --exec-prefix=/local/bin.SOLARIS_ARM --bindir=/local/bin.SOLARIS_ARM
> 
> 
> %arm-aout-gcc -v
> Reading specs from
> /local/bin.SOLARIS_ARM/lib/gcc-lib/arm-aout/egcs-2.91.66/specs
> gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
> 
> %arm-aout-gcc -nostdinc -fno-builtin -fsigned-char -mbig-endian -mapcs-32 
> -Wa,-EB -mcpu=arm7tdmi 
> -Wall -g -O -O2 -S -o ex2.a4_s ex2.c
> 
> 
> 4. Assembler-file:
> -------------------
> rfp	.req	r9
> sl	.req	r10
> fp	.req	r11
> ip	.req	r12
> sp	.req	r13
> lr	.req	r14
> pc	.req	r15
> gcc2_compiled.:
> ___gnu_compiled_c:
> .stabs "/bintec/bibo/usr/stefans/src/example/app/",100,0,0,Ltext0
> .stabs "ex2.c",100,0,315,Ltext0
> .text
> Ltext0:
> .stabs "int:t1=r1;0020000000000;0017777777777;",128,0,0,0
> .stabs "char:t2=r2;0;127;",128,0,0,0
> .stabs "long int:t3=r1;0020000000000;0017777777777;",128,0,0,0
> .stabs "unsigned int:t4=r1;0000000000000;0037777777777;",128,0,0,0
> .stabs "long unsigned int:t5=r1;0000000000000;0037777777777;",128,0,0,0
> .stabs "long long
> int:t6=r1;01000000000000000000000;0777777777777777777777;",128,0,0,0
> .stabs "long long unsigned
> int:t7=r1;0000000000000;01777777777777777777777;",128,0,0,0
> .stabs "short int:t8=r8;-32768;32767;",128,0,0,0
> .stabs "short unsigned int:t9=r9;0;65535;",128,0,0,0
> .stabs "signed char:t10=r10;-128;127;",128,0,0,0
> .stabs "unsigned char:t11=r11;0;255;",128,0,0,0
> .stabs "float:t12=r1;4;0;",128,0,0,0
> .stabs "double:t13=r1;8;0;",128,0,0,0
> .stabs "long double:t14=r1;8;0;",128,0,0,0
> .stabs "complex int:t15=s8real:1,0,32;imag:1,32,32;;",128,0,0,0
> .stabs "complex float:t16=r16;4;0;",128,0,0,0
> .stabs "complex double:t17=r17;8;0;",128,0,0,0
> .stabs "complex long double:t18=r18;8;0;",128,0,0,0
> .stabs "void:t19=19",128,0,0,0
> .stabs
> "test_t:t20=21=s4a:4,0,3;b:4,3,5;c:1,8,6;d:1,14,8;e:4,22,8;;",128,0,10,0
> 	.align	0
> LC0:
> 	.ascii	"1.a-e: %d %d %d %d %d\012\000"
> 	.align	0
> LC1:
> 	.ascii	"2.a-e: %d %d %d %d %d\012\000"
> 	.align	0
> LC2:
> 	.ascii	"3.a-e: %d %d %d %d %d\012\000"
> 	.align	0
> LC3:
> 	.ascii	"4.a-e: %d %d %d %d %d\012\000"
> 	.align	0
> LC4:
> 	.ascii	"5.a-e: %d %d %d %d %d\012\000"
> 	.align	0
> 	.global	_func
> _func:
> 	.stabd 68,0,3
> 	@ args = 0, pretend = 0, frame = 4
> 	@ frame_needed = 1, current_function_anonymous_args = 0
> LBB2:
> 	mov	ip, sp
> 	stmfd	sp!, {fp, ip, lr, pc}
> 	.stabd 68,0,13
> 	mov	r1, #0
> 	mov	r2, #4
> 	.stabd 68,0,3
> 	sub	sp, sp, #12
> 	sub	fp, ip, #4
> 	.stabd 68,0,13
> 	sub	r0, fp, #16
> 	bl	_memset
> 	.stabd 68,0,15
> 	ldr	r2, [fp, #-16]
> 	bic	r2, r2, #-1073741824
> 	orr	r2, r2, #536870912
> 	str	r2, [fp, #-16]
> 	.stabd 68,0,16
> 	mov	r3, r2, asl #14
> 	mov	r3, r3, asr #24
> 	str	r3, [sp, #0]
> 	ldrh	r2, [fp, #-14]	@ movhi
> 	mov	r2, r2, lsr #2
> 	and	r2, r2, #255
> 	str	r2, [sp, #4]
> 	ldr	r0, L2
> 	ldrb	r3, [fp, #-15]
> 	ldrb	r1, [fp, #-16]	@ zero_extendqisi2
> 	mov	r3, r3, asl #24
> 	mov	r3, r3, asr #26
> 	mov	r2, r1
> 	mov	r1, r1, lsr #5
> 	and	r2, r2, #31
> 	bl	_printf
> 	.stabd 68,0,17
> 	ldr	r2, [fp, #-16]
> 	bic	r2, r2, #486539264
> 	orr	r2, r2, #33554432
> 	str	r2, [fp, #-16]
> 	.stabd 68,0,18
> 	mov	r3, r2, asl #14
> 	mov	r3, r3, asr #24
> 	str	r3, [sp, #0]
> 	ldrh	r2, [fp, #-14]	@ movhi
> 	mov	r2, r2, lsr #2
> 	and	r2, r2, #255
> 	str	r2, [sp, #4]
> 	ldr	r0, L2+4
> 	ldrb	r3, [fp, #-15]
> 	ldrb	r1, [fp, #-16]	@ zero_extendqisi2
> 	mov	r3, r3, asl #24
> 	mov	r3, r3, asr #26
> 	mov	r2, r1
> 	mov	r1, r1, lsr #5
> 	and	r2, r2, #31
> 	bl	_printf
> 	.stabd 68,0,19
> 	ldr	r2, [fp, #-16]
> 	bic	r2, r2, #15728640
> 	orr	r2, r2, #786432
> 	str	r2, [fp, #-16]
> 	.stabd 68,0,20
> 	mov	r3, r2, asl #14
> 	mov	r3, r3, asr #24
> 	str	r3, [sp, #0]
> 	ldrh	r2, [fp, #-14]	@ movhi
> 	mov	r2, r2, lsr #2
> 	and	r2, r2, #255
> 	str	r2, [sp, #4]
> 	ldr	r0, L2+8
> 	ldrb	r3, [fp, #-15]
> 	ldrb	r1, [fp, #-16]	@ zero_extendqisi2
> 	mov	r3, r3, asl #24
> 	mov	r3, r3, asr #26
> 	mov	r2, r1
> 	mov	r1, r1, lsr #5
> 	and	r2, r2, #31
> 	bl	_printf
> 	.stabd 68,0,21
> 	ldr	ip, [fp, #-16]			!!! error ???
> 	mvn	ip, ip, asl #22			!!! this code sets all upper
> 	mvn	ip, ip, lsr #22			!!! bits too
> 	str	ip, [fp, #-16]			!!! error ???
> 	.stabd 68,0,22
> 	mov	ip, ip, asl #14
> 	mov	ip, ip, asr #24
> 	str	ip, [sp, #0]
> 	ldrh	r3, [fp, #-14]	@ movhi
> 	mov	r3, r3, lsr #2
> 	and	r3, r3, #255
> 	str	r3, [sp, #4]
> 	ldr	r0, L2+12
> 	ldrb	r3, [fp, #-15]
> 	ldrb	r1, [fp, #-16]	@ zero_extendqisi2
> 	mov	r3, r3, asl #24
> 	mov	r3, r3, asr #26
> 	mov	r2, r1
> 	mov	r1, r1, lsr #5
> 	and	r2, r2, #31
> 	bl	_printf
> 	.stabd 68,0,23
> 	ldr	r2, [fp, #-16]
> 	bic	r2, r2, #1000
> 	orr	r2, r2, #20
> 	str	r2, [fp, #-16]
> 	.stabd 68,0,24
> 	mov	r3, r2, asl #14
> 	mov	r3, r3, asr #24
> 	str	r3, [sp, #0]
> 	ldrh	r2, [fp, #-14]	@ movhi
> 	mov	r2, r2, lsr #2
> 	and	r2, r2, #255
> 	str	r2, [sp, #4]
> 	ldr	r0, L2+16
> 	ldrb	r3, [fp, #-15]
> 	ldrb	r1, [fp, #-16]	@ zero_extendqisi2
> 	mov	r3, r3, asl #24
> 	mov	r3, r3, asr #26
> 	mov	r2, r1
> 	mov	r1, r1, lsr #5
> 	and	r2, r2, #31
> 	bl	_printf
> 	.stabd 68,0,25
> LBE2:
> 	ldmea	fp, {fp, sp, pc}
> L3:
> 	.align	0
> L2:
> 	.word	LC0
> 	.word	LC1
> 	.word	LC2
> 	.word	LC3
> 	.word	LC4
> .stabs "func:F19",36,0,3,_func
> .stabs "test:20",128,0,12,-16
> .stabn 192,0,0,LBB2
> .stabn 224,0,0,LBE2
> 
> END.
> 
> -- 
> Sent through Global Message Exchange - http://www.gmx.net
> 



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