You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Failed assert got 1400 instead of 14 after become tail call at -O3 #158017
A-codegenArea: Code generationC-bugCategory: This is a bug.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`F-unboxed_closures`#![feature(unboxed_closures)]`I-miscompileIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
-O3 passes the previous stack values instead of the tuple values passed to the tail call
I tried a patch but it's a non trivial one so I haven't submitted any PR
Repro:
#![feature(explicit_tail_calls, unboxed_closures)]#![expect(incomplete_features)]#![allow(dead_code)]#[derive(Copy,Clone)]structThing{a:u64,b:u64,c:u64,d:u64}#[inline(never)]fnseed_stack(){letmut values = (Thing{a:100,b:200,c:300,d:400},Thing{a:500,b:600,c:700,d:800},);
std::hint::black_box(&mut values);}#[inline(never)]extern"rust-call"fncallee((left, right):(Thing,Thing)) -> u64{
left.a.wrapping_add(left.b).wrapping_add(right.a).wrapping_add(right.b)}#[inline(never)]extern"rust-call"fncaller((left, right):(Thing,Thing)) -> u64{
become callee((right, left));}fnmain(){seed_stack();let left = Thing{a:1,b:2,c:3,d:4};let right = Thing{a:5,b:6,c:7,d:8};println!("got={}", caller((left, right)));}
A-codegenArea: Code generationC-bugCategory: This is a bug.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`F-unboxed_closures`#![feature(unboxed_closures)]`I-miscompileIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
theemathas commentedon Jun 17, 2026
Possibly related to #155241.
cc @dianqk (author of #155343)
theemathas commentedon Jun 17, 2026
Slightly smaller repro:
Prints
5in debug, prints100in release.WaffleLapkin commentedon Jun 23, 2026
@kevin-valerio is there any particular reason why you were experimenting with
extern "rust-call"tail calls?kevin-valerio commentedon Jun 23, 2026
@WaffleLapkin Yes! It's all described in this Zullip thread
Rollup merge of rust-lang#158374 - WaffleLapkin:no-tail-rust-call, r=…
Rollup merge of rust-lang#158374 - WaffleLapkin:no-tail-rust-call, r=…
Rollup merge of rust-lang#158374 - WaffleLapkin:no-tail-rust-call, r=…
Rollup merge of rust-lang#158374 - WaffleLapkin:no-tail-rust-call, r=…