port compile-fail allocator tests to stable API

This commit is contained in:
Ralf Jung 2020-04-02 13:33:59 +02:00
parent 033eae5ad7
commit cd132f563e
6 changed files with 21 additions and 51 deletions

View file

@ -1,15 +1,10 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
// error-pattern: allocation has size 1 and alignment 1, but gave size 1 and alignment 2
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.dealloc(x, Layout::from_size_align_unchecked(1, 2));
let x = alloc(Layout::from_size_align_unchecked(1, 1));
dealloc(x, Layout::from_size_align_unchecked(1, 2));
}
}

View file

@ -1,15 +1,10 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
// error-pattern: allocation has size 1 and alignment 1, but gave size 2 and alignment 1
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.dealloc(x, Layout::from_size_align_unchecked(2, 1));
let x = alloc(Layout::from_size_align_unchecked(1, 1));
dealloc(x, Layout::from_size_align_unchecked(2, 1));
}
}

View file

@ -1,16 +1,11 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
// error-pattern: dereferenced after this allocation got freed
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
let x = alloc(Layout::from_size_align_unchecked(1, 1));
dealloc(x, Layout::from_size_align_unchecked(1, 1));
dealloc(x, Layout::from_size_align_unchecked(1, 1));
}
}

View file

@ -1,15 +1,10 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
// error-pattern: allocation has size 1 and alignment 1, but gave size 2 and alignment 1
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.realloc(x, Layout::from_size_align_unchecked(2, 1), 1).unwrap();
let x = alloc(Layout::from_size_align_unchecked(1, 1));
realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
}
}

View file

@ -1,14 +1,9 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
let _z = *(x.as_ptr() as *mut u8); //~ ERROR dereferenced after this allocation got freed
let x = alloc(Layout::from_size_align_unchecked(1, 1));
realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
let _z = *x; //~ ERROR dereferenced after this allocation got freed
}
}

View file

@ -1,16 +1,11 @@
#![feature(allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
use std::alloc::{alloc, dealloc, realloc, Layout};
// error-pattern: dereferenced after this allocation got freed
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
let x = alloc(Layout::from_size_align_unchecked(1, 1));
dealloc(x, Layout::from_size_align_unchecked(1, 1));
realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
}
}