]> granicus.if.org Git - llvm/commitdiff
[MC] Fix constant pools with DenseMap sentinel values
authorOliver Stannard <oliver.stannard@arm.com>
Tue, 30 May 2017 09:37:11 +0000 (09:37 +0000)
committerOliver Stannard <oliver.stannard@arm.com>
Tue, 30 May 2017 09:37:11 +0000 (09:37 +0000)
The MC ConstantPool class uses a DenseMap to track generated constants, with
the int64_t value of the constant as the key. This fails when values of
0x7fffffffffffffff or 0x7ffffffffffffffe are inserted into the constant pool, as
these are sentinel values for DenseMap.

The fix is to use std::map instead, which doesn't use sentinel values.

Differential revision: https://reviews.llvm.org/D33667

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304199 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/ConstantPools.h
test/MC/AArch64/ldr-pseudo.s

index 5d4e32a672ddd6e6115b3a6498ce0a64aba37c94..ef33250204ecff8d52bf2e4326b83bd7e9a4dff5 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/SMLoc.h"
 #include <cstdint>
+#include <map>
 
 namespace llvm {
 
@@ -44,7 +45,7 @@ struct ConstantPoolEntry {
 class ConstantPool {
   using EntryVecTy = SmallVector<ConstantPoolEntry, 4>;
   EntryVecTy Entries;
-  DenseMap<int64_t, const MCSymbolRefExpr *> CachedEntries;
+  std::map<int64_t, const MCSymbolRefExpr *> CachedEntries;
 
 public:
   // Initialize a new empty constant pool
index e132f7cf651f1f861207a45ab42e2266a33df5fe..1d99d14018017beb74103081f2c75a14f70295d0 100644 (file)
@@ -205,6 +205,13 @@ f18:
   ldr x1, =0x320064
 // CHECK: ldr x1, .Ltmp[[TMP26:[0-9]+]]
 
+// We previously used a DenseMap with constant values as keys, check that
+// sentinel values can be used.
+  ldr x0, =0x7ffffffffffffffe
+// CHECK: ldr x0, .Ltmp[[TMP27:[0-9]+]]
+  ldr x1, =0x7fffffffffffffff
+// CHECK: ldr x1, .Ltmp[[TMP28:[0-9]+]]
+
 //
 // Constant Pools
 //
@@ -311,3 +318,8 @@ f18:
 // CHECK: .p2align 2
 // CHECK: .Ltmp[[TMP25]]
 // CHECK: .word 3276900
+
+// CHECK: .Ltmp[[TMP27]]
+// CHECK: .xword 9223372036854775806
+// CHECK: .Ltmp[[TMP28]]
+// CHECK: .xword 9223372036854775807