[SCEV] Fix FoldID::addInteger(unsigned long I)
authorVitaly Buka <vitalybuka@google.com>
Sat, 18 Feb 2023 02:29:42 +0000 (18:29 -0800)
committerVitaly Buka <vitalybuka@google.com>
Sat, 18 Feb 2023 20:29:17 +0000 (12:29 -0800)
"unsigned long" can be 8 bytes, but the code assumes 4.

This this the real root cause D122215 was reverted.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D144316

llvm/include/llvm/Analysis/ScalarEvolution.h

index c4bd0fa..57107cb 100644 (file)
@@ -1300,7 +1300,14 @@ public:
     SmallVector<unsigned, 4> Bits;
 
   public:
-    void addInteger(unsigned long I) { Bits.push_back(I); }
+    void addInteger(unsigned long I) {
+      if (sizeof(long) == sizeof(int))
+        addInteger(unsigned(I));
+      else if (sizeof(long) == sizeof(long long))
+        addInteger((unsigned long long)I);
+      else
+        llvm_unreachable("unexpected sizeof(long)");
+    }
     void addInteger(unsigned I) { Bits.push_back(I); }
     void addInteger(int I) { Bits.push_back(I); }