r178975 - Sema: Don't crash when trying to emit a warning for a duplicate value in an invalid enum.
Benjamin Kramer
benny.kra at googlemail.com
Sun Apr 7 07:10:40 PDT 2013
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?
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'}}
+};
More information about the cfe-commits
mailing list