[PATCH] Gracefully (and correctly) handle init of multiple union members
Eli Friedman
eli.friedman at gmail.com
Tue Sep 24 16:37:18 PDT 2013
One more thing I didn't catch the first time: please add a test for
something like the following:
typedef union {
struct {
int zero;
int one;
int two;
int three;
} a;
int b[4];
} union_16644_t;
union_16644_t x[2] = { [0].a.one = 2, [1].a.zero = 3, [0].a.zero = 5 };
-Eli
On Tue, Sep 24, 2013 at 2:06 PM, Matthew Curtis <mcurtis at codeaurora.org>wrote:
> New patch incorporating Eli's feedback.
>
> Thanks Eli!
>
> Matthew Curtis
>
>
> On 9/24/2013 2:07 PM, Eli Friedman wrote:
>
> On Tue, Sep 24, 2013 at 8:04 AM, Matthew Curtis <mcurtis at codeaurora.org>wrote:
>
>> We now emit warnings when doing so and code generation is consistent
>> with GCC. Note that the C99 spec is unclear as to the precise
>> behavior.
>>
>> See also ...
>> Bug:
>> http://llvm.org/bugs/show_bug.cgi?id=16644 and
>>
>> cfe-dev discussion:
>> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-September/031918.html
>>
>>
>>
> + FieldDecl *CFD = ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
> + assert((FD == 0 || CFD == 0 || CFD == FD)
> + && "Only one field of a union may be initiazed at a time!");
>
> This will cause an unused variable warning in release builds. Also,
> spelling.
>
> diff --git a/test/Sema/designated-initializers.c
> b/test/Sema/designated-initializers.c
> index 36fa559..be365a0 100644
> --- a/test/Sema/designated-initializers.c
> +++ b/test/Sema/designated-initializers.c
> @@ -1,5 +1,8 @@
> // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-unknown %s
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -DCHECK_CODEGEN=1 \
> +// RUN: -S -emit-llvm -o - 2>&1 | FileCheck %s
>
> Please put a separate code generation test into test/CodeGen. It's okay
> if you duplicate the test code.
>
> The approach looks fine.
>
> -Eli
>
>
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130924/2464ea7c/attachment.html>
More information about the cfe-commits
mailing list