http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52415
--- Comment #8 from Michal Hlavinka <mhlavink at redhat dot com> 2012-04-18 12:22:34 UTC --- Created attachment 27182 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27182 pre-processed reproducer (avr) (In reply to comment #7) > Would you please post a complete test case to reproduce? > See http://gcc.gnu.org/bugs/#need $ avr-gcc --version avr-gcc (Fedora 4.7-0.fc17.1.20120302) 4.7.1 20120414 (prerelease) Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (ignore old date in package name) $ uname -ra Linux nbone.mihlnet 3.3.0-8.fc16.x86_64 #1 SMP Thu Mar 29 18:37:19 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux command for compilation: avr-g++ -mmcu=atmega2560 -gdwarf-2 -DF_CPU=16000000UL -O1 -Wall -Wno-unused-variable -fno-inline-small-functions -fwhole-program testitb.cpp --output test0.S -S In reproducer there are 3 options for structure swapping. First two reproduce the problem. The last one works. This problem does not exist in avr-gcc 4.6.2 Original code: DirEnt tmp = eeFs.files[i_fileId1]; eeFs.files[i_fileId1] = eeFs.files[i_fileId2]; eeFs.files[i_fileId2] = tmp; s_sync_write = true; EeFsFlushDirEnt(i_fileId1); EeFsFlushDirEnt(i_fileId2); What happens: it copies structures and then it calls EeFsFlushDirEnt but with corrupted values. .L__stack_usage = 4 mov r28,r22 .LBB2: .loc 1 50 0 mov r18,r24 ldi r19,0 movw r26,r18 lsl r26 rol r27 add r26,r18 adc r27,r19 subi r26,lo8(-(eeFs)) sbci r27,hi8(-(eeFs)) adiw r26,4 ld r24,X+ ld r25,X+ ld r26,X sbiw r26,4+2 .LVL2: .loc 1 51 0 mov r30,r22 ldi r31,0 movw r12,r30 lsl r12 rol r13 add r30,r12 adc r31,r13 subi r30,lo8(-(eeFs)) sbci r31,hi8(-(eeFs)) ldd r12,Z+4 ldd r13,Z+5 ldd r14,Z+6 adiw r26,4 st X+,r12 st X+,r13 st X,r14 .loc 1 52 0 std Z+4,r18 std Z+5,r19 std Z+6,r20 .LVL3: .loc 1 60 0 call _ZL15EeFsFlushDirEnth .LVL4: .loc 1 61 0 mov r24,r28 call _ZL15EeFsFlushDirEnth First call is made with r24 that got overwritten during structure copy. In the third structure copy code (the working one) r24 is not changed. I'm not too good in assembler interpretation, so this is what it seems to me is happening, but I can be wrong and there can be different problem than r24.