Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miscompilation with incremental + unpacked debug + macos #108216

Open
ehuss opened this issue Feb 18, 2023 · 3 comments
Open

miscompilation with incremental + unpacked debug + macos #108216

ehuss opened this issue Feb 18, 2023 · 3 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-macos Operating system: macOS P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 18, 2023

The following script illustrates a miscompilation on macOS when using incremental and unpacked debug:

I tried this code:

#!/bin/bash 

rm -rf *.o incremental foo

echo "fn main() { let a: i64 = 1 << 64; }" > foo1.rs
echo "fn main() { let a: i64 = 1 << 63; }" > foo2.rs

ARGS="--crate-name foo -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=incremental"

for i in {1..20}
do
    rustc foo1.rs $ARGS && { echo "ERROR: first build should have failed"; exit 1; }
    rustc foo2.rs $ARGS || { echo "ERROR: second build should have passed"; exit 1; }
    ./foo || { echo "ERROR: executing should have passed"; exit 1; }
done

The first compilation should fail due to the overflow error:

error: this arithmetic operation will overflow
 --> src/main.rs:1:26
  |
1 | fn main() { let a: i64 = 1 << 64; }
  |                          ^^^^^^^ attempt to shift left by `64_i32`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

The second compilation should succeed since the overflow has been removed.
Then executing the binary should pass, since there is no overflow.

Instead, this happened:

Sometimes executing the binary will fail, as-if it compiled with the incorrect constant value:

thread 'main' panicked at 'attempt to shift left with overflow', foo1.rs:1:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
ERROR: executing should have passed

This doesn't happen always, although it usually happens right away (thus the reason for the loop in the script).

Testing on macOS 13.2 aarch64 and macOS 12.6.3 x86_64 with either Xcode 14 or 13.

I couldn't get it to fail on Linux.

Bisection

This appears to be a regression introduced in #87337. Presumably because before that it wouldn't write any .o files (or write anything to the incremental db) due to the error. Strangely, I cannot get it to fail with #![allow(arithmetic_overflow)], and I don't really have a theory as to why.

@ehuss ehuss added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. labels Feb 18, 2023
@jyn514 jyn514 added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Apr 10, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 10, 2023
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 12, 2023
@ldm0
Copy link
Contributor

ldm0 commented Jul 3, 2023

This can be reproduced easily by rustc with toolchain: nightly-2023-02-08-aarch64-apple-darwin.
But cannot be reproduced by rustc with toolchain: nightly-2023-07-03-aarch64-apple-darwin.

environment: macOS 13.4.1 + Xcode 14.3

@lqd lqd self-assigned this Nov 17, 2023
@lqd
Copy link
Member

lqd commented Nov 17, 2023

I'll try to reproduce the issue as well.

@bstrie bstrie added the O-macos Operating system: macOS label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-macos Operating system: macOS P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants