Skip to content

std::thread::panicking() doesn't simplify to false when compiled with panic=abort #151458

@gendx

Description

@gendx

I tried compiling this code with -C panic=abort:

std::thread::panicking()

I expected to see this happen: this should simplify to false because the documentation of panicking() says "Determines whether the current thread is unwinding because of panic", but the current thread cannot be unwinding when we are in panic=abort mode.

Instead, this happened: a dozen instructions are generated, referring to GLOBAL_PANIC_COUNT, etc. See https://rust.godbolt.org/z/93Yax7rT9.

Can the implementation be changed to something like this? Due to constant folding, this could potentially automatically optimize away a lot of code referring to std::thread::panicking() when compiled in panic=abort mode.

fn panicking() -> bool {
    if cfg!(panic = "abort") {
        false
    } else {
        panicking::panicking()
    }
}

Meta

Rust version 1.92.0 on https://rust.godbolt.org/

Metadata

Metadata

Assignees

Labels

-Zbuild-stdUnstable cargo option: -Zbuild-stdA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-panicArea: Panicking machineryC-discussionCategory: Discussion or questions that doesn't represent real issues.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions