Introduce a fallible variant of LLVMConstIntGetZExtValue

which verifies that a constant bit width is within 64 bits or fails.
This commit is contained in:
Tomasz Miąsko 2022-09-09 00:00:00 +00:00
parent 98f3001eec
commit 7279106166
4 changed files with 28 additions and 2 deletions

View file

@ -215,7 +215,11 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
try_as_const_integral(v).map(|v| unsafe { llvm::LLVMConstIntGetZExtValue(v) })
try_as_const_integral(v).and_then(|v| unsafe {
let mut i = 0u64;
let success = llvm::LLVMRustConstIntGetZExtValue(v, &mut i);
success.then_some(i)
})
}
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {

View file

@ -1096,7 +1096,7 @@ extern "C" {
pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
pub fn LLVMRustConstInt128Get(
ConstantVal: &ConstantInt,
SExt: bool,