------- Comment #3 from dg dot recrutement31 at gmail dot com 2010-05-27 09:03 ------- (In reply to comment #2) > (In reply to comment #1) > > I think your inline-asm is totally broken, the constraints you have don't > > mean > > the extended (32bit) registers. > Humm... strange answer. Certainly, you've read too fast and too late in the > evening. > You "think" but it's better to demonstrate. > How to explain the bug disappears when -g or -O0 turned on ?
To notice: the bug disappears also if function toto is removed and its code moved in the main function like this: #include "far_pointers.h" char u; /*void toto(far_pointer<unsigned char> pt) { u = *pt; }*/ int main(int argc, char **argv) { unsigned short dataSeg = 0; asm ( " \ .intel_syntax noprefix; \n \ mov %0, cs; \n \ " : "=r"(dataSeg) ); far_pointer<unsigned char> pt(dataSeg, (unsigned char*) &main); //toto(pt); u = *pt; return u; } The assembly is correctly generated: .file "main.cpp" .intel_syntax noprefix .def ___main; .scl 2; .type 32; .endef .text .globl _main .def _main; .scl 2; .type 32; .endef _main: LFB30: push ebp LCFI0: mov ebp, esp LCFI1: and esp, -16 LCFI2: call ___main /APP # 19 "main.cpp" 1 .intel_syntax noprefix; mov ax, cs; # 0 "" 2 # 59 "far_pointers.h" 1 .intel_syntax noprefix; mov gs, ax; mov al, gs:[OFFSET FLAT:_main]; # 0 "" 2 /NO_APP mov BYTE PTR _u, al movsx eax, al leave LCFI3: ret LFE30: .globl _u .bss _u: .space 1 All these tests seem to demonstrate there is a bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44288