From 87d6953719c5b9c3e7fe4c5a97d2e845dcb52d57 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 4 Jan 2020 11:31:56 +0100 Subject: [PATCH] Add documentation about the UB of the stack2reg optimization --- src/optimize/stack2reg.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/optimize/stack2reg.rs b/src/optimize/stack2reg.rs index 2abf865cf3e..4762b40db8d 100644 --- a/src/optimize/stack2reg.rs +++ b/src/optimize/stack2reg.rs @@ -1,3 +1,14 @@ +//! This optimization replaces stack accesses with SSA variables and removes dead stores when possible. +//! +//! # Undefined behaviour +//! +//! This optimization is based on the assumption that stack slots which don't have their address +//! leaked through `stack_addr` are only accessed using `stack_load` and `stack_store` in the +//! function which has the stack slots. This optimization also assumes that stack slot accesses +//! are never out of bounds. If these assumptions are not correct, then this optimization may remove +//! `stack_store` instruction incorrectly, or incorrectly use a previously stored value as the value +//! being loaded by a `stack_load`. + use std::collections::{BTreeMap, HashSet}; use std::ops::Not;