We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6ddd99 commit 240af05Copy full SHA for 240af05
3 files changed
compiler/rustc_codegen_llvm/src/llvm/ffi.rs
@@ -1881,12 +1881,15 @@ unsafe extern "C" {
1881
C: &Context,
1882
effects: MemoryEffects,
1883
) -> &Attribute;
1884
- pub(crate) fn LLVMRustCreateRangeAttribute(
1885
- C: &Context,
1886
- num_bits: c_uint,
1887
- lower_words: *const u64,
1888
- upper_words: *const u64,
1889
- ) -> &Attribute;
+ /// Lower and upper bounds are each passed as a `u128` broken into low and high 64-bit parts.
+ pub(crate) safe fn LLVMRustCreateRangeAttribute<'ll>(
+ C: &'ll Context,
+ NumBits: c_uint,
+ LowerBoundLo: u64,
+ LowerBoundHi: u64,
1890
+ UpperBoundLo: u64,
1891
+ UpperBoundHi: u64,
1892
+ ) -> &'ll Attribute;
1893
1894
// Operations on functions
1895
pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
compiler/rustc_codegen_llvm/src/llvm/mod.rs
@@ -112,17 +112,22 @@ pub(crate) fn CreateAllocKindAttr(llcx: &Context, kind_arg: AllocKindFlags) -> &
112
113
pub(crate) fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Attribute {
114
let lower = range.start;
115
+ // LLVM treats the upper bound as exclusive, but allows wrapping.
116
let upper = range.end.wrapping_add(1);
- let lower_words = [lower as u64, (lower >> 64) as u64];
117
- let upper_words = [upper as u64, (upper >> 64) as u64];
118
- unsafe {
119
- LLVMRustCreateRangeAttribute(
120
- llcx,
121
- size.bits().try_into().unwrap(),
122
- lower_words.as_ptr(),
123
- upper_words.as_ptr(),
124
- )
125
- }
+
+ // Split each endpoint into a pair of u64 values to make FFI easier.
+ let as_lo_hi_pair = |x: u128| (x as u64, (x >> 64) as u64);
+ let (lower_bound_lo, lower_bound_hi) = as_lo_hi_pair(lower);
+ let (upper_bound_lo, upper_bound_hi) = as_lo_hi_pair(upper);
+ LLVMRustCreateRangeAttribute(
+ llcx,
+ size.bits().try_into().unwrap(),
126
+ lower_bound_lo,
127
+ lower_bound_hi,
128
+ upper_bound_lo,
129
+ upper_bound_hi,
130
+ )
131
}
132
133
#[derive(Copy, Clone)]
compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -486,10 +486,15 @@ LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) {
486
487
extern "C" LLVMAttributeRef
488
LLVMRustCreateRangeAttribute(LLVMContextRef C, unsigned NumBits,
489
- const uint64_t LowerWords[],
490
- const uint64_t UpperWords[]) {
491
- return LLVMCreateConstantRangeAttribute(C, Attribute::Range, NumBits,
492
- LowerWords, UpperWords);
+ uint64_t LowerBoundLo, uint64_t LowerBoundHi,
+ uint64_t UpperBoundLo, uint64_t UpperBoundHi) {
+ // For both endpoints, reassemble the lo/hi parts into into APInt values.
+ // APInt will automatically discard any excess bits.
493
+ ConstantRange RangeValue = {
494
+ APInt(NumBits, ArrayRef{LowerBoundLo, LowerBoundHi}),
495
+ APInt(NumBits, ArrayRef{UpperBoundLo, UpperBoundHi}),
496
+ };
497
+ return wrap(Attribute::get(*unwrap(C), llvm::Attribute::Range, RangeValue));
498
499
500
// These values **must** match ffi::AllocKindFlags.
0 commit comments