diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-08-26 16:34:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-26 16:34:17 +0200 |
| commit | 6047243330acb6126ba3875abb09285a2f7a0356 (patch) | |
| tree | 74936f90406f91745724609ed21995424f41a0b2 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 5d95ec05f63209fbb41080425079fba3e20399dc (diff) | |
| parent | fcff8f7f5a0d4add3c05f57de1b34291746c3c08 (diff) | |
| download | rust-6047243330acb6126ba3875abb09285a2f7a0356.tar.gz rust-6047243330acb6126ba3875abb09285a2f7a0356.zip | |
Rollup merge of #145867 - Zalathar:range-attr, r=nikic
cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes that each of `LowerWords` and `UpperWords` points to enough u64 values to define an integer of the specified bit-length, and will encounter UB if that is not the case. Our safe wrapper function always passes pointers to `[u64; 2]` arrays, regardless of the bit-length specified. That's fine in practice, because scalar primitives never exceed 128 bits, but it is technically a soundness hole in a safe function. We can close the soundness hole by explicitly asserting `size_bits <= 128`. This is effectively just a stricter version of the existing check that the value must be small enough to fit in `c_uint`. --- This is a narrower version of the fix in rust-lang/rust#145846.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
| -rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index e699e4b9c13..cce40da354d 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -488,6 +488,9 @@ extern "C" LLVMAttributeRef LLVMRustCreateRangeAttribute(LLVMContextRef C, unsigned NumBits, const uint64_t LowerWords[], const uint64_t UpperWords[]) { + // FIXME(Zalathar): There appears to be no stable guarantee that C++ + // `AttrKind` values correspond directly to the `unsigned KindID` values + // accepted by LLVM-C API functions, though in practice they currently do. return LLVMCreateConstantRangeAttribute(C, Attribute::Range, NumBits, LowerWords, UpperWords); } |
