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]
Other format: [Raw text]

[Bug c/31072] New: Wrong code for volatile var with initalization and optimization


I tracked it down to the following code, which is not compiled as expected, if
optimization (> O1) is turned on. 

Contents of fg.c:
---8<------8<---------8<---
extern volatile int ReadyFlag_NotProperlyInitialized;

volatile int ReadyFlag_NotProperlyInitialized=1;
volatile int ReadyFlag_InitializationOk=1;
---8<------8<---------8<---

My command line for GCC 4.3-20070223:
  powerpc-elf-gcc -O1 -S -o fg_O1.s fg.i  


In the generated assembler output, the variable ReadyFlag_InitializationOk is
placed in section .sbss (instead of .sdata) an is initialized with 0 instead of
1. 
ReadyFlag_InitializationOk is initialized as expected. The only difference is
the extern declaration for ReadyFlag_NotProperlyInitialized.

Contents of fg_O1.s:
---8<------8<---------8<---
        .file   "fg.c"
        .globl ReadyFlag_NotProperlyInitialized
        .globl ReadyFlag_InitializationOk
        .section        .sbss,"aw",@nobits
        .align 2
        .type   ReadyFlag_NotProperlyInitialized, @object
        .size   ReadyFlag_NotProperlyInitialized, 4
ReadyFlag_NotProperlyInitialized:
        .zero   4
        .section        .sdata,"aw",@progbits
        .align 2
        .type   ReadyFlag_InitializationOk, @object
        .size   ReadyFlag_InitializationOk, 4
ReadyFlag_InitializationOk:
        .long   1
        .ident  "GCC: (GNU) 4.3.0 20070223 (experimental)"
---8<------8<---------8<---

gcc-3.4.6 built with the same system (same build, host and target) is ok!
gcc-4.1.2 built with the same system (same build, host and target) is ok!

gcc-4.2-20070221 shows the same error as 4.3-20070223 (both built as above)


-- 
           Summary: Wrong code for volatile var with initalization and
                    optimization
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: a_fisch at gmx dot de
 GCC build triplet: mingw32
  GCC host triplet: mingw32
GCC target triplet: powerpc-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31072


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