From 01cdc505d98b338eb5b28fb03e65f8d1d1731bd6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 25 Jul 2023 11:52:44 +0200 Subject: [PATCH] Fix stack-protector.rs on LLVM 17 Prevent fill from being (correctly) optimized away by passing the address of the alloca to black_box. --- tests/ui/abi/stack-protector.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ui/abi/stack-protector.rs b/tests/ui/abi/stack-protector.rs index 24bd2e21943..e94aa816d90 100644 --- a/tests/ui/abi/stack-protector.rs +++ b/tests/ui/abi/stack-protector.rs @@ -40,6 +40,8 @@ fn vulnerable_function() { // Overwrite the on-stack return address with the address of `malicious_code()`, // thereby jumping to that function when returning from `vulnerable_function()`. unsafe { fill(stackaddr, bad_code_ptr, 20); } + // Capture the address, so the write is not optimized away. + std::hint::black_box(stackaddr); } // Use an uninlined function with its own stack frame to make sure that we don't