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]

bug (?) in gcc version 2.95.2 19991024 (release-2)


Hello.  I think I've found a bug in gcc, possibly involving statement
expressions.  Gcc compiles a program so that it does not produce the
expected output.  If the bug can be avoided with a command-line flag
(turning off something) I'd like to know.  The code is machine
generated, so it is not easy for me to fix each time.  (I've
simplified the example as much as I could.)


Thanks for your efforts!
Trevor



Details:

  gcc version 2.95.2 19991024 (release-2)

I'm running Windows 2000 Professional and I got gcc via the Cygwin
binary package.  I compiled the code with no options.  The program is
stand-alone, it requires no input files.

The code should print

  EXPECTING 9999,9999
        GOT 9999,9999

but instead, it prints

  EXPECTING 9999,9999
        GOT 4444,-222

------------------------cut here---------------------------------


#include <stdio.h>

struct A {
  int key;
  int data;
  void *left;
};
struct B {
  struct A *v;
};

struct A yy = { -222, 4444, NULL };

int main() {
  struct A *y = &yy;

  struct A *z = (struct A *)malloc(sizeof(struct A));

  printf("EXPECTING 9999,9999\n");

  *z =
    (struct A) {
      9999,
      9999,
      (void *) ({
        struct B *t2 = (struct B *)malloc(sizeof(struct B));
        *t2 =
          (struct B) {
            ({
              struct A *t3 = (struct A *)malloc(sizeof(struct A));
              *t3 = (struct A){y->key, y->data, NULL};
              t3;
            })
          };
        t2;
      })
    };

  printf("      GOT %d,%d\n",z->data,z->key);

  return 0;
}


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