[PATCH] D59016: [TableGen] Allow 2^63-1 and 2^63-2 as int literals.

Simon Tatham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 02:31:28 PST 2019


simon_tatham created this revision.
simon_tatham added reviewers: nhaehnle, hfinkel, javedabsar.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

These two values correspond to the 'Empty' and 'Tombstone' special
keys defined by DenseMapInfo<int64_t>, which means that neither one
can be used as a key in DenseMap<int64_t, anything>. Hence, if you try
to use either of those values as an int literal, IntInit::get() fails
an assertion when it tries to insert them into its static cache of
int-literal objects.

A simple workaround is to detect those two special values in advance
and cache them separately from the DenseMap.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59016

Files:
  llvm/lib/TableGen/Record.cpp
  llvm/test/TableGen/IntSpecialValues.td


Index: llvm/test/TableGen/IntSpecialValues.td
===================================================================
--- /dev/null
+++ 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;
+}
Index: llvm/lib/TableGen/Record.cpp
===================================================================
--- llvm/lib/TableGen/Record.cpp
+++ llvm/lib/TableGen/Record.cpp
@@ -459,7 +459,16 @@
 IntInit *IntInit::get(int64_t V) {
   static DenseMap<int64_t, IntInit*> 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<int64_t>::getEmptyKey() ? EmptyII :
+                 V == DenseMapInfo<int64_t>::getTombstoneKey() ? TombstoneII :
+                 ThePool[V]);
+
   if (!I) I = new(Allocator) IntInit(V);
   return I;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59016.189464.patch
Type: text/x-patch
Size: 1276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190306/45b8b6b9/attachment.bin>


More information about the llvm-commits mailing list