Skip to content

Infinite recursion optimized away with opt-level=z #97428

Closed
@ldm0

Description

@ldm0

I tried this code:

#[derive(Default)]
pub struct Run {
    pub a: bool,
    pub b: bool,
    pub c: Option<String>,
}

impl Run {
    pub fn run(&mut self) {
        if !self.a && !self.b {
            self.run();
        }
    }
}

pub fn foo() -> Run {
    let mut run = Run::default();
    run.a = false;
    run.b = false;
    run.run();
    run
}

I expected to see this happen: foo runs infinitely

Instead, this happened: foo return directly

The opt-level is set to z: https://rust.godbolt.org/z/n1v471j6E

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions