diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -459,7 +459,16 @@ IntInit *IntInit::get(int64_t V) { static DenseMap ThePool; - IntInit *&I = ThePool[V]; + // For any type you can use as the key in a DenseMap, there are two + // special values (called 'empty' and 'tombstone') which cannot be + // used as keys. Deal with those specially, to avoid an assertion + // failure if either one appears as an integer literal. + static IntInit *EmptyII = nullptr, *TombstoneII = nullptr; + + IntInit *&I = (V == DenseMapInfo::getEmptyKey() ? EmptyII : + V == DenseMapInfo::getTombstoneKey() ? TombstoneII : + ThePool[V]); + if (!I) I = new(Allocator) IntInit(V); return I; } diff --git a/llvm/test/TableGen/IntSpecialValues.td b/llvm/test/TableGen/IntSpecialValues.td new file mode 100644 --- /dev/null +++ b/llvm/test/TableGen/IntSpecialValues.td @@ -0,0 +1,8 @@ +// RUN: llvm-tblgen %s | FileCheck %s + +def TestRecord { + // CHECK: int X = 9223372036854775807; + int X = 0x7FFFFFFFFFFFFFFF; + // CHECK: int Y = 9223372036854775806; + int Y = 0x7FFFFFFFFFFFFFFE; +}