about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-12 22:29:49 +0100
committerGitHub <noreply@github.com>2023-02-12 22:29:49 +0100
commitf81cb97cb20b7a3f625f8a73b343c27d938bb9b9 (patch)
treef63dcc684c5c0f7ca8002dea6f4bafa3c1790ad8 /tests
parent454ae9fb8b34917eedf1bfbc482aecd4c10e56bc (diff)
parent0ea0c90d58cccccd7039334092f8ee85bc4db394 (diff)
downloadrust-f81cb97cb20b7a3f625f8a73b343c27d938bb9b9.tar.gz
rust-f81cb97cb20b7a3f625f8a73b343c27d938bb9b9.zip
Rollup merge of #107955 - RalfJung:ancient-ub, r=jyn514
fix UB in ancient test

This seems to go back all the way to the [original version of this test](https://github.com/rust-lang/rust/blob/b9aa9def858cfc66d411972b10ce3d98479acd78/src/test/run-pass/regions-mock-trans.rs) from ten years ago... ``@nikomatsakis`` trip down memory lane? ;)

Clearly deallocation is a form of mutation so doing it to a (pointer derived from a) shared reference cannot be legal. Let's use mutable references instead.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/regions/regions-mock-codegen.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/ui/regions/regions-mock-codegen.rs b/tests/ui/regions/regions-mock-codegen.rs
index 9d0ca76e409..d5c93f81fd8 100644
--- a/tests/ui/regions/regions-mock-codegen.rs
+++ b/tests/ui/regions/regions-mock-codegen.rs
@@ -22,15 +22,15 @@ struct Ccx {
     x: isize,
 }
 
-fn allocate(_bcx: &arena) -> &Bcx<'_> {
+fn allocate(_bcx: &arena) -> &mut Bcx<'_> {
     unsafe {
         let layout = Layout::new::<Bcx>();
         let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
-        &*(ptr.as_ptr() as *const _)
+        &mut *ptr.as_ptr().cast()
     }
 }
 
-fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
+fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
     return allocate(bcx.fcx.arena);
 }
 
@@ -38,7 +38,7 @@ fn g(fcx: &Fcx) {
     let bcx = Bcx { fcx };
     let bcx2 = h(&bcx);
     unsafe {
-        Global.deallocate(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
+        Global.deallocate(NonNull::new_unchecked(bcx2 as *mut _ as *mut _), Layout::new::<Bcx>());
     }
 }