Minor g++ bug: Run-time initialization of constant expression.

Sergei Organov osv@javad.ru
Wed Apr 15 01:09:00 GMT 1998


The following initialization generates run-time code:
  int volatile& r = *(int *)20;
Note that changing the line to
  int volatile& r = *(int volatile *)20;
removes run-time initialization.

The session log follows:

$ cat volref.cc
int volatile& r = *(int *)20;
$ ~/local/bin/g++ -c -save-temps volref.cc
$ cat volref.s
        .file   "volref.cc"
        .version        "01.01"
/ GNU C++ version egcs-2.90.27 980315 (egcs-1.0.2 release)
(i586-pc-linux-gnuli
bc1) compiled by GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release).
/ options passed:
/ options enabled:  -fpeephole -ffunction-cse -fkeep-static-consts
/ -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker
-fargument-alias
/ -m80387 -mhard-float -mno-soft-float -mieee-fp -mfp-ret-in-387
/ -mschedule-prologue -mcpu=pentium -march=pentium

gcc2_compiled.:
.globl r
.bss
        .align 4
        .type    r,@object
        .size    r,4
r:
        .zero   4
.text
        .align 4
.globl _GLOBAL_.I.r
        .type    _GLOBAL_.I.r,@function
_GLOBAL_.I.r:
        pushl %ebp
        movl %esp,%ebp
        movl $20,%eax
        movl %eax,r
        jmp .L2
        .align 4
        jmp .L1
        .align 4
.L2:
.L1:
        movl %ebp,%esp
        popl %ebp
        ret
.Lfe1:
        .size    _GLOBAL_.I.r,.Lfe1-_GLOBAL_.I.r
.section        .ctors,"aw"
        .long    _GLOBAL_.I.r
        .ident  "GCC: (GNU) egcs-2.90.27 980315 (egcs-1.0.2 release)"
$



More information about the Gcc-bugs mailing list