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/15849] New: volatile generates bad code


A simple program like:
#include <stdio.h>

volatile int v1 = 0;
volatile int v2 = 1;

int main() {
  if(v1 = v2) {
    printf("v1 = v2\n");
  }
}

Generates (without any optimisation) the x86 assembler code:
        movl    v2, %eax
        movl    %eax, v1
        movl    v1, %eax
        testl   %eax, %eax
        je      .L2
        subl    $12, %esp
        pushl   $.LC0
        call    printf

This is obviously bad code, and so the result of the program is "v1 = v2"
It was originaly a problem in Ada, and so tested it with C code.
So I may be wrong in selecting the C component, my apologies in this case.

I tried with optimisation turned on and off, no influence.

My gcc version:
Reading specs from /usr/lib/gcc/i486-linux/3.4.0/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,
objc,ada,treelang --prefix=/usr --libexecdir=/usr/lib 
--with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib 
--enable-nls --enable-threads=posix --without-included-gettext 
--program-suffix=-3.4 --enable-__cxa_atexit --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk 
--disable-werror i486-linux
Thread model: posix
gcc version 3.4.0 (Debian 20040516)

Regards,
JC

-- 
           Summary: volatile generates bad code
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jc at apinc dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


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


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