[LLVMbugs] [Bug 10531] New: In-class initializer weirdness with anonymous unions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 28 16:14:12 PDT 2011


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

           Summary: In-class initializer weirdness with anonymous unions
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++0x
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: schaub.johannes at googlemail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


I couldn't find whether the FDIS forbids this, but it seems to me that it
allows this code:

#include <stdio.h>

template<typename T> static char const * f(T *t) {
  T u(*t);
  u.x = "hello world";
  printf("%s\n", u.x);
  return "initialized";
}

int main() {
  union { char const *x = f(this); };
  printf("%s\n", x);
}

I expect that the program compiled by clang outputs:

    hello world
    initialized

(Copying an union copies its object representation, so I believe I'm fine with
copying "*t"). However, Clang generates this IR code for main:

    $ clang++ -std=c++0x -emit-llvm -S -o - main1.cpp

define i32 @main() {
  %1 = alloca i32, align 4
  %2 = alloca %union.anon, align 4
  store i32 0, i32* %1
  %3 = bitcast %union.anon* %2 to i8**
  %4 = load i8** %3, align 4
  %5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]*
@.str, i32 0, i32 0), i8* %4)
  %6 = load i32* %1
  ret i32 %6
}

The call to "f" and the store into x are completely missing.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list