Skip to content

Commit 7d2bfd4

Browse files
committed
Windows debugging
1 parent 78261b7 commit 7d2bfd4

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

.appveyor.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ install:
2929
- rustc --version
3030

3131
build_script:
32-
- set RUST_TEST_NOCAPTURE=1
33-
- set RUST_BACKTRACE=1
3432
- set RUSTFLAGS=-C debug-assertions
3533
# Build and install miri
3634
- cargo build --release --all-features --all-targets
@@ -40,8 +38,12 @@ build_script:
4038
- set MIRI_SYSROOT=%USERPROFILE%\AppData\Local\rust-lang\miri\cache\HOST
4139

4240
test_script:
41+
- set RUST_TEST_NOCAPTURE=1
42+
- set RUST_BACKTRACE=1
43+
- set MIRI_LOG=miri::intptrcast
4344
# Test miri
44-
- cargo test --release --all-features
45+
- cargo test --release --all-features heap
46+
- false
4547
# Test cargo integration
4648
- cd test-cargo-miri
4749
- '"C:\msys64\mingw64\bin\python3.exe" run-test.py'

src/intptrcast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ impl<'mir, 'tcx> GlobalState {
9090
// From next_base_addr + slack, round up to adjust for alignment.
9191
let base_addr = Self::align_addr(global_state.next_base_addr + slack, align.bytes());
9292
entry.insert(base_addr);
93+
trace!(
94+
"Assigning base address {:#x} to allocation {:?} (slack: {}, align: {})",
95+
base_addr, ptr.alloc_id, slack, align.bytes(),
96+
);
9397

9498
// Remember next base address. If this allocation is zero-sized, leave a gap
9599
// of at least 1 to avoid two allocations having the same base address.

tests/run-pass/heap_allocator.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,36 @@ fn check_alloc<T: Alloc>(mut allocator: T) { unsafe {
2929
allocator.dealloc(p4, Layout::from_size_align(10, 4).unwrap());
3030
} }
3131

32-
fn check_overalign_requests<T: Alloc>(mut allocator: T) {
32+
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
33+
ptr.add(align - (ptr as usize & (align - 1)))
34+
}
35+
36+
fn allocate_with_align<T: Alloc>(mut allocator: T, size: usize, align: usize) -> *mut u8 { unsafe {
37+
let ptr = allocator.alloc(Layout::from_size_align(size + align, 1).unwrap()).unwrap().as_ptr();
38+
eprintln!("{}", format!("Before aligning: {:?}", ptr));
39+
let ptr = align_ptr(ptr, align);
40+
eprintln!("{}", format!("After aligning: {:?}", ptr));
41+
ptr
42+
} }
43+
44+
fn check_overalign_requests<T: Alloc+Copy>(mut allocator: T) {
3345
let size = 8;
3446
// Greater than `size`.
3547
let align = 16;
3648

3749
let iterations = 5;
3850
unsafe {
3951
let pointers: Vec<_> = (0..iterations).map(|_| {
40-
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
52+
allocate_with_align(allocator, size, align)
4153
}).collect();
4254
for &ptr in &pointers {
43-
assert_eq!((ptr.as_ptr() as usize) % align, 0,
55+
assert_eq!((ptr as usize) % align, 0,
4456
"Got a pointer less aligned than requested")
4557
}
4658

4759
// Clean up.
4860
for &ptr in &pointers {
49-
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
61+
allocator.dealloc(NonNull::new(ptr).unwrap(), Layout::from_size_align(size, 1).unwrap())
5062
}
5163
}
5264
}

0 commit comments

Comments
 (0)