[cfe-commits] r150144 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/init.c
David Blaikie
dblaikie at gmail.com
Wed Feb 8 19:50:07 PST 2012
On Wed, Feb 8, 2012 at 7:29 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> Author: aaronballman
> Date: Wed Feb 8 21:29:06 2012
> New Revision: 150144
>
> URL: http://llvm.org/viewvc/llvm-project?rev=150144&view=rev
> Log:
> Attempting to initialize a union member that does not exist no longer crashes.
>
> Patch by Remi Gacogne
>
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/Sema/init.c
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=150144&r1=150143&r2=150144&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Feb 8 21:29:06 2012
> @@ -1511,7 +1511,8 @@
> IdentifierInfo *FieldName) {
> assert(AnonField->isAnonymousStructOrUnion());
> Decl *NextDecl = AnonField->getNextDeclInContext();
> - while (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(NextDecl)) {
> + IndirectFieldDecl *IF = NULL;
> + while (NextDecl && (IF = dyn_cast<IndirectFieldDecl>(NextDecl))) {
Unless I'm missing something, this'd be easier with:
while (IndirectFieldDecl *IF = dyn_cast_or_null<IndirectFieldDecl>(NextDecl)) {
perhaps?
> if (FieldName && FieldName == IF->getAnonField()->getIdentifier())
> return IF;
> NextDecl = NextDecl->getNextDeclInContext();
>
> Modified: cfe/trunk/test/Sema/init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=150144&r1=150143&r2=150144&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/init.c (original)
> +++ cfe/trunk/test/Sema/init.c Wed Feb 8 21:29:06 2012
> @@ -18,10 +18,19 @@
> void *g = &x;
> int *h = &x;
>
> +struct union_crash
> +{
> + union
> + {
> + };
> +};
> +
> int test() {
> -int a[10];
> -int b[10] = a; // expected-error {{array initializer must be an initializer list}}
> -int +; // expected-error {{expected identifier or '('}}
> + int a[10];
> + int b[10] = a; // expected-error {{array initializer must be an initializer list}}
> + int +; // expected-error {{expected identifier or '('}}
> +
> + struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}}
> }
>
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list