[LLVMbugs] [Bug 20829] New: Initialization of union type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Sep 1 23:09:51 PDT 2014


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

            Bug ID: 20829
           Summary: Initialization of union type
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: Jani_Lahtinen at mcafee.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following code:

typedef union {
  struct {
    int a:1;
    int b:1;
    int c:1;
    int d:1;
  };
  uint8_t mask;
} foo;

int main(void)
{
  foo x;
  x.mask = 0xff;
  x = (foo){.a = 1};
  printf("%02x\n", x.mask);
  return 0;
}

when compiled with -O0 prints two hex-digits the last of which is one, and the
first is random.

C99 standard says:

6.7.8 Initialization

...

8. Except where explicitly stated otherwise, for the purposes of this subclause
unnamed members of objects of structure and union type do not participate in
initialization. Unnamed members of structure objects have indeterminate value
even after initialization.

...

21. If there are fewer initializers in a brace-enclosed list than there are
elements or members
of an aggregate, or fewer characters in a string literal used to initialize an
array of known
size than there are elements in the array, the remainder of the aggregate shall
be
initialized implicitly the same as objects that have static storage duration.

I am unsure is the Clang behaviour according to standard or not.

-- 
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/20140902/9890c1b3/attachment.html>


More information about the llvm-bugs mailing list