http://llvm.org/bugs/show_bug.cgi?id=16236

            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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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 
0
$ clang-2.8 -O1 wrong.c 
$ ./a.out 
0
$ clang-trunk -O1 wrong.c 
$ ./a.out 
1
$
----------------------------------
int printf(const char *, ...);

union
{
  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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to