Skip to content

Miscompilation with release profile, fat lto and target aarch64-linux-android #131071

Open

Description

The test function in this code prints different results depending on the caller context:

use zng::{
    prelude::*,
    view_process::default::*,
};

// Android entry point.
#[no_mangle]
fn android_main(app: android::AndroidApp) {
    zng::env::init!();
    android::init_android_app(app.clone());
    run_same_process(|| {
        APP.defaults().run(async {
            test("app-start");

            TEST_EVENT
                .on_pre_event(app_hn!(|_: &TestArgs, _| {
                    // this fails (prints None)
                    test("test-event");
                }))
                .perm();
            TEST_EVENT.notify(TestArgs::now());

            task::deadline(1.secs()).await;
            APP.exit();
        });
    });
}

pub fn test(ctx: &str) {
    use zng::layout::*;
    let cull = std::hint::black_box(PxRect::new(
        PxPoint::new(Px(-1080), Px(-2400)),
        PxSize::new(Px(3240), Px(7200)),
    ));
    let bounds = std::hint::black_box(PxRect::new(
        PxPoint::new(Px(0), Px(0)),
        PxSize::new(Px(1080), Px(90)),
    ));
    let i = cull.intersection(&bounds);
    println!("!!: {ctx} {:?}", i);
}

Output:

I RustStdoutStderr: !!: app-start Some(Rect(1080pxx90px at (0px, 0px)))
I RustStdoutStderr: !!: test-event None

Meta

Nightly:

rustc 1.83.0-nightly (fb4aebddd 2024-09-30)
binary: rustc
commit-hash: fb4aebddd18d258046ddb51fd41589295259a0fa
commit-date: 2024-09-30
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Stable:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Notes

  • My attempts to reduce the code cause the problem to go away, even just by replacing dependencies to only the crates required.

  • I did not manage to cause miscompilation targeting aarch64-apple-darwin, only Android arm64-v8a.

  • I automated the test in https://github.com/SamRodri/miscomp-issue, see a miscompiled result.

  • The PxRect type is just a type alias for euclid::Rect, there is nothing special about these types.

  • I initially spotted this because it causes the screen to render blank (on this project: https://github.com/zng-ui/zng-template).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeO-androidOperating system: AndroidOperating system: Androidneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions