Hi all, The code that contains the code shown below is compiled with arm-eabi-gcc -O2.
#include <stdio.h> typedef struct { int member1; } aaa_struct; int bbb; void test(aaa_struct *aaa) { if((aaa_struct *)NULL == aaa) { printf("1\n"); } else { printf("2\n"); } bbb = aaa->member1; if((aaa_struct *)NULL == aaa) { printf("3\n"); } else { printf("4\n"); } } When the argument is NULL, this function outputs the following result. 1 4 However, when optional -O1 is specified, it is correctly executed. When the assembler code is confirmed, the character string "3" does lost by optimization. /* Output wrong code : arm-eabi-gcc -O2 -S -o test.s test.c */ .cpu arm7tdmi .fpu softvfp .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 1 .eabi_attribute 30, 2 .eabi_attribute 18, 4 .file "test.c" .text .align 2 .global test .type test, %function test: @ Function supports interworking. @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 stmfd sp!, {r4, lr} subs r4, r0, #0 beq .L5 ldr r0, .L6 bl puts .L3: ldr r2, [r4, #0] ldr r3, .L6+4 ldr r0, .L6+8 str r2, [r3, #0] bl puts ldmfd sp!, {r4, lr} bx lr .L5: ldr r0, .L6+12 bl puts b .L3 .L7: .align 2 .L6: .word .LC1 .word bbb .word .LC2 .word .LC0 .size test, .-test .comm bbb,4,4 .section .rodata.str1.4,"aMS",%progbits,1 .align 2 .LC0: .ascii "1\000" .space 2 .LC1: .ascii "2\000" .space 2 .LC2: .ascii "4\000" .ident "GCC: (GNU) 4.5.2" arm-eabi-gcc that I used is as follows. $ arm-eabi-gcc -v Using built-in specs. COLLECT_GCC=arm-eabi-gcc COLLECT_LTO_WRAPPER=/home/user/opt/arm-eabi-4.5.2/bin/../libexec/gcc/arm-eabi/4.5.2/lto-wrapper Target: arm-eabi Configured with: ../configure --target=arm-eabi --prefix=/home/user/opt/arm-eabi --enable-interwork --enable-multilib --with-float=soft --with-fpu=vfp --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-headers=/home/user/work01/tmp/gcc-4.5.2/build/../newlib/libc/include/ --disable-newlib-supplied-syscalls Thread model: single gcc version 4.5.2 (GCC) $ Regards, Yuki HOSAKA.