On Sun, Apr 7, 2013 at 7:10 AM, Benjamin Kramer <[email protected]> wrote: > Author: d0k > Date: Sun Apr 7 09:10:40 2013 > New Revision: 178975 > > URL: http://llvm.org/viewvc/llvm-project?rev=178975&view=rev > Log: > Sema: Don't crash when trying to emit a warning for a duplicate value in an > invalid enum. > > Fixes PR15693. A null check on a pointer returned from cast<> is a very > dubious > construct, do we have a checker for this somewhere?
Don't think we have much in the way of LLVM-checkers, really. I've suggested we fix this at compile-time (have cast always return references, not pointers, since they can't be null anyway (could go further and have cast/dyn_cast always accept references too, since they can't be null either)) but people (Chandler) didn't much like that notion. > > Modified: > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/test/Sema/warn-duplicate-enum.c > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178975&r1=178974&r2=178975&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 7 09:10:40 2013 > @@ -11538,7 +11538,7 @@ static void CheckForDuplicateEnumValues( > // Populate the EnumMap with all values represented by enum constants > without > // an initialier. > for (unsigned i = 0; i < NumElements; ++i) { > - EnumConstantDecl *ECD = cast<EnumConstantDecl>(Elements[i]); > + EnumConstantDecl *ECD = cast_or_null<EnumConstantDecl>(Elements[i]); > > // Null EnumConstantDecl means a previous diagnostic has been emitted for > // this constant. Skip this enum since it may be ill-formed. > > Modified: cfe/trunk/test/Sema/warn-duplicate-enum.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-duplicate-enum.c?rev=178975&r1=178974&r2=178975&view=diff > ============================================================================== > --- cfe/trunk/test/Sema/warn-duplicate-enum.c (original) > +++ cfe/trunk/test/Sema/warn-duplicate-enum.c Sun Apr 7 09:10:40 2013 > @@ -90,3 +90,12 @@ enum { > NMax = N2, > NCount = NMax + 1 > }; > + > +// PR15693 > +enum enum1 { > + VALUE // expected-note{{previous definition is here}} > +}; > + > +enum enum2 { > + VALUE // expected-error{{redefinition of enumerator 'VALUE'}} > +}; > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
