[cfe-dev] question about initializing multiple members of unions

Gao, Yunzhong yunzhong_gao at playstation.sony.com
Fri Sep 13 12:23:37 PDT 2013


Hi Matthew,
Hmm I am inclined towards treating a.zero and b[1] as two different sub-objects.
Which svn revision of clang did you use? When I used r190021 on your test case, I got an assertion:

$ clang -S -o - init.c
lib/Sema/SemaInit.cpp:2449: clang::InitializedEntity::InitializedEntity(clang::ASTContext&, unsigned int, const clang::InitializedEntity&): Assertion `CT && "Unexpected type"' failed.

I have some local patches for related initialization problems, but I cannot verify whether they fix the particular problem you have here.

- Gao.


________________________________________
From: cfe-dev-bounces at cs.uiuc.edu [cfe-dev-bounces at cs.uiuc.edu] on behalf of Matthew Curtis [mcurtis at codeaurora.org]
Sent: Thursday, September 12, 2013 2:04 PM
To: Eli Friedman
Cc: clang-dev Developers
Subject: Re: [cfe-dev] question about initializing multiple members of unions

On 9/11/2013 2:30 PM, Eli Friedman wrote:
On Wed, Sep 11, 2013 at 6:10 AM, Matthew Curtis <mcurtis at codeaurora.org<mailto:mcurtis at codeaurora.org>> wrote:
I'm investigating an assert in clang compiling the following code:

  typedef union {
    struct {
      int zero;
      int one;
      int two;
      int three;
    } a;
    int b[4];
  } my_agg_t;

  my_agg_t agg_instance =
  {
    .b[0] = 0,
    .a.one = 1,
    .b[2] = 2,
    .a.three = 3,
  };

I'm a little uncertain as to what this *should* do.

This is also http://llvm.org/bugs/show_bug.cgi?id=16644 .

I would say we should either use gcc's interpretation or reject it.

-Eli

Sounds reasonable. Unless someone has a dissenting opinion, I'll look at fixing this by making clang consistent with gcc.

Thanks,
Matthew Curtis


--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation






More information about the cfe-dev mailing list