Hi.
>Hello,
>
>I think I came across a possible bug in gcc when using -O2 optimisation on
>using
>the following program .
>
>int global_var;
>
>int switch_test(void) {
> int sw = 4;
> int dmy = (sw == 77) ? 11 : 0x101;
> global_var = dmy * ((sw >= 5) +1);
>
> switch (sw) {
> case 4: return(0); // okay
> default: return(99); //error
> }
> }
>
>int main(void) {
> printf("result=%d\n", switch_test()); return(0);
>}
>
>When executed, the function returns "99", i.e. at the time the switch(sw)
>is
>calculated, the wrong case is taken.
>
>The following assembly code is generated :
>
> * 13 .global switch_test
> * 14 .type switch_test,function
> * 15 switch_test:
> * 16 @ args = 0, pretend = 0, frame = 0
> * 17 @ frame_needed = 1,
>current_function_anonymous_args = 0
> * 18 0000 0DC0A0E1 mov ip, sp
> * 19 0004 00D82DE9 stmfd sp!, {fp, ip, lr, pc}
> * 20 0008 04B04CE2 sub fp, ip, #4
> * 21 000c 0B30A0E3 mov r3, #11 ; dmy = constant 11
I have missed something? Here (above) should be 0x101, not 11 (dmy value).
> * 22 0010 08209FE5 ldr r2, .L40 ; load adrs of
>global
> * 23 0014 6300A0E3 mov r0, #99 ; load result = 99
>(wrong !!!)
> * 24 0018 003082E5 str r3, [r2, #0] ; store dmy = 257
>into global
> * 25 001c 00A81BE9 ldmea fp, {fp, sp, pc}
> * 27 .L41:
> * 28 .align 2
> * 29 .L40:
> * 30 0024 00000000 .word global
--
+--------------------------------+
| Marcel Telka <[EMAIL PROTECTED]> |
| http://telka.sk/ |
+--------------------------------+
_______________________________________________
http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
Please visit the above address for information on this list.