[LLVMbugs] [Bug 10006] New: Behavior of Overridden Initializations with Designated Initializers

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 24 17:43:03 PDT 2011


           Summary: Behavior of Overridden Initializations with Designated
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: rgamble99 at gmail.com
                CC: llvmbugs at cs.uiuc.edu

When a designated initializer is used to override a previous initializer in an
initialization list and the overriding initializer does not explicitly
initialize all of the members from the previous initialization, the members not
explicitly initialized retain the values from the previous initialization. 
Instead, the values for the subobjects in the prior initialization should be
completely discarded and the subobjects not initialized in the later
initialization should be implicitly initialized.

The below program demonstrates the issue:

#include <stdio.h>

struct foo { int a, b; };

int main(void) {
    struct foo foo_array[2] =
        { {1, 2}, {3, 4}, [0] = { .a = 10 }, { .b = 40 } };
    printf("{%d, %d}, {%d, %d}\n",
        foo_array[0].a, foo_array[0].b,
        foo_array[1].a, foo_array[1].b);
    return 0;

When compiled with clang, the resulting program prints "{10, 2}, {3, 40}".  I
believe the correct output (as per 9889:1999 ยง6.7.8p19) is "{10, 0}, {0, 40}"
and this is what gcc and Intel produce.  Tested with clang 2.9 (trunk 120076)
and clang 3.0 (trunk 131958)

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