[llvm] [IR] Fix null pointer dereference in Constant::toConstantRange() for ConstantByte (PR #193874)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 02:17:19 PDT 2026
================
@@ -868,5 +869,29 @@ TEST(ConstantsTest, Float128Test) {
LLVMContextDispose(C);
}
+TEST(ConstantsTest, ToConstantRangeConstantByteVector) {
+ LLVMContext Context;
+ // Use 7-bit ByteType so the vector is not folded into ConstantDataVector
+ // (ConstantDataSequential only supports 8/16/32/64-bit element types).
+ ByteType *B7Ty = Type::getByteNTy(Context, 7);
+
+ ConstantByte *CB1 = ConstantByte::get(B7Ty, 10);
+ ConstantByte *CB2 = ConstantByte::get(B7Ty, 20);
+ Constant *Elts[] = {CB1, CB2};
+ Constant *CV = ConstantVector::get(Elts);
+ ASSERT_TRUE(isa<ConstantVector>(CV));
+
+ ConstantRange CR = CV->toConstantRange();
+ EXPECT_TRUE(CR.contains(APInt(7, 10)));
+ EXPECT_TRUE(CR.contains(APInt(7, 20)));
----------------
nikic wrote:
Would be better to check `EXPECT_EQ` with the actual range, rather than just two elements.
https://github.com/llvm/llvm-project/pull/193874
More information about the llvm-commits
mailing list