-
-
Notifications
You must be signed in to change notification settings - Fork 15k
ReferencePropagation introduces UB into code that is accepted by Stacked Borrows #132898
Copy link
Copy link
Open
Open
Copy link
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-needs-investigationCall for participation: This issues needs some investigation to determine current statusCall for participation: This issues needs some investigation to determine current statusI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-mir-optWorking group: MIR optimizationsWorking group: MIR optimizations
Metadata
Metadata
Assignees
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-needs-investigationCall for participation: This issues needs some investigation to determine current statusCall for participation: This issues needs some investigation to determine current statusI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-mir-optWorking group: MIR optimizationsWorking group: MIR optimizations
Type
Fields
Give feedbackNo fields configured for issues without a type.
This program is accepted by Stacked Borrows:
That is a Stacked Borrows limitation; it is caused by the fact that 2-phase borrows cannot be modeled properly with just a Stack.
However, it also shows that defining an aliasing model that rejects this code is non-trivial, and we should be very careful with optimizations on such code until we have a clear plan for how to model this.
And yet, it turns out that running this code with
mir-opt-level=2introduces UB:This is quite surprising, I thought we were very conservative in terms of doing optimizations that rely on the aliasing model. I have not yet figured out where exactly this comes from.
Cc @rust-lang/opsem @rust-lang/wg-mir-opt @cjgillot