r343042 - [Sema] Use a more civilized hash map to implement -Wduplicate-enum.

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 25 15:53:07 PDT 2018


Author: epilk
Date: Tue Sep 25 15:53:06 2018
New Revision: 343042

URL: http://llvm.org/viewvc/llvm-project?rev=343042&view=rev
Log:
[Sema] Use a more civilized hash map to implement -Wduplicate-enum.

DenseMap<long, SOMETHING> used LONG_MAX as a tombstone, so it asserts
when you try to insert it!

rdar://44774672

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=343042&r1=343041&r2=343042&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 25 15:53:06 2018
@@ -16402,7 +16402,7 @@ static void CheckForDuplicateEnumValues(
   typedef SmallVector<std::unique_ptr<ECDVector>, 3> DuplicatesVector;
 
   typedef llvm::PointerUnion<EnumConstantDecl*, ECDVector*> DeclOrVector;
-  typedef llvm::DenseMap<int64_t, DeclOrVector> ValueToVectorMap;
+  typedef std::unordered_map<int64_t, DeclOrVector> ValueToVectorMap;
 
   // Use int64_t as a key to avoid needing special handling for DenseMap keys.
   auto EnumConstantToKey = [](const EnumConstantDecl *D) {

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=343042&r1=343041&r2=343042&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-duplicate-enum.c (original)
+++ cfe/trunk/test/Sema/warn-duplicate-enum.c Tue Sep 25 15:53:06 2018
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -Wduplicate-enum
-// RUN: %clang_cc1 %s -x c++ -fsyntax-only -verify -Wduplicate-enum
+// RUN: %clang_cc1 %s -x c++ -DCPP -fsyntax-only -verify -Wduplicate-enum
 enum A {
   A1 = 0,  // expected-note {{element 'A1' also has value 0}}
   A2 = -1,
@@ -99,3 +99,11 @@ enum enum1 {
 enum enum2 {
   VALUE // expected-error{{redefinition of enumerator 'VALUE'}}
 };
+
+// rdar://44774672
+#ifdef CPP
+enum BigEnumerators : long {
+  e1,
+  e2 = 9223372036854775807L,
+};
+#endif




More information about the cfe-commits mailing list