about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2022-09-09 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2022-09-09 15:54:14 +0200
commit72791061666c45e830dade2445354a6f60699d69 (patch)
treef45a4677c2e931e0fe07191131df949eb3be91ea /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent98f3001eecbe4cbd091c10ffab45b4c164bb507b (diff)
downloadrust-72791061666c45e830dade2445354a6f60699d69.tar.gz
rust-72791061666c45e830dade2445354a6f60699d69.zip
Introduce a fallible variant of LLVMConstIntGetZExtValue
which verifies that a constant bit width is within 64 bits or fails.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index 931ce78721c..6ee3c7d6821 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -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 wasn’t 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)