[llvm] [IR] Fix null pointer dereference in Constant::toConstantRange() for ConstantByte (PR #193874)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 17:56:39 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Jim Lin (tclin914)
<details>
<summary>Changes</summary>
In the ConstantVector path of toConstantRange(), the code checks that each element is either a ConstantInt or ConstantByte but unconditionally dereferences the ConstantInt pointer to get the value. When the element is a ConstantByte, the ConstantInt pointer is null, causing a crash.
This was introduced in 57568c288dbe when ConstantByte support was added to toConstantRange() but the fallback to CB->getValue() was missed.
---
Full diff: https://github.com/llvm/llvm-project/pull/193874.diff
1 Files Affected:
- (modified) llvm/lib/IR/Constants.cpp (+1-1)
``````````diff
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index f07ce527c1240..11b8518830884 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1989,7 +1989,7 @@ ConstantRange Constant::toConstantRange() const {
auto *CB = dyn_cast<ConstantByte>(Elem);
if (!CI && !CB)
return ConstantRange::getFull(BitWidth);
- CR = CR.unionWith(CI->getValue());
+ CR = CR.unionWith(CI ? CI->getValue() : CB->getValue());
}
return CR;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/193874
More information about the llvm-commits
mailing list