1
Fork 0

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

@ -1618,6 +1618,14 @@ extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty,
return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList));
}
extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) {
auto C = unwrap<llvm::ConstantInt>(CV);
if (C->getBitWidth() > 64)
return false;
*value = C->getZExtValue();
return true;
}
// Returns true if both high and low were successfully set. Fails in case constant wasnt any of
// the common sizes (1, 8, 16, 32, 64, 128 bits)
extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low)