[llvm] e8232c3 - [ADT] In FoldingSet calulation for APInt add bit width to avoid crash (#88635)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 14 17:54:40 PDT 2024


Author: Andreas Jonson
Date: 2024-04-15T09:54:37+09:00
New Revision: e8232c325f7c56c175b27a3538699c31519c8f5e

URL: https://github.com/llvm/llvm-project/commit/e8232c325f7c56c175b27a3538699c31519c8f5e
DIFF: https://github.com/llvm/llvm-project/commit/e8232c325f7c56c175b27a3538699c31519c8f5e.diff

LOG: [ADT] In FoldingSet calulation for APInt add bit width to avoid crash (#88635)

Multiple ranges attributes with the same lower and upper limit but
different bit width caused a crash.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/FoldingSet.h
    llvm/test/Bitcode/attributes.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/FoldingSet.h b/llvm/include/llvm/ADT/FoldingSet.h
index ddc3e52255d6c0..28a84d96588383 100644
--- a/llvm/include/llvm/ADT/FoldingSet.h
+++ b/llvm/include/llvm/ADT/FoldingSet.h
@@ -356,6 +356,7 @@ class FoldingSetNodeID {
     AddInteger(unsigned(I >> 32));
   }
   void AddInteger(const APInt &Int) {
+    AddInteger(Int.getBitWidth());
     const auto *Parts = Int.getRawData();
     for (int i = 0, N = Int.getNumWords(); i < N; ++i) {
       AddInteger(Parts[i]);

diff  --git a/llvm/test/Bitcode/attributes.ll b/llvm/test/Bitcode/attributes.ll
index 26163b4d38c89d..0c753e58d43586 100644
--- a/llvm/test/Bitcode/attributes.ll
+++ b/llvm/test/Bitcode/attributes.ll
@@ -531,6 +531,11 @@ define range(i32 -1, 42) i32 @range_attribute(<4 x i32> range(i32 -1, 42) %a) {
   ret i32 0
 }
 
+; CHECK: define range(i32 0, 42) i32 @range_attribute_same_range_other_bitwidth(i8 range(i8 0, 42) %a)
+define range(i32 0, 42) i32 @range_attribute_same_range_other_bitwidth(i8 range(i8 0, 42) %a) {
+  ret i32 0
+}
+
 ; CHECK: define void @wide_range_attribute(i128 range(i128 618970019642690137449562111, 618970019642690137449562114) %a)
 define void @wide_range_attribute(i128 range(i128 618970019642690137449562111, 618970019642690137449562114) %a) {
   ret void


        


More information about the llvm-commits mailing list