[LLVMbugs] [Bug 16236] New: wrong code generated for union with optimization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 5 13:04:12 PDT 2013


            Bug ID: 16236
           Summary: wrong code generated for union with optimization
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dhazeghi at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following code produces 0 at -O0 and 1 at -O1 and above with clang trunk on
x86_64-linux.  I believe the behavior is well-defined here, since the
assignment to the union member is through the union type.  It is a change in
behavior from 2.8.

$ clang-trunk -v
clang version 3.4 (trunk 183303)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ clang-trunk -O0 wrong.c 
$ ./a.out 
$ clang-2.8 -O1 wrong.c 
$ ./a.out 
$ clang-trunk -O1 wrong.c 
$ ./a.out 
int printf(const char *, ...);

  short f0;
  int f1;
} u, *up = &u;

int a;

int main ()
  for (; a <= 0; a++)
    if ((u.f0 = 1))
      up->f1 = 0;

  printf ("%d\n", u.f1);
  return 0;

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130605/5bc1d148/attachment.html>

More information about the llvm-bugs mailing list