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

Compiling std atomic with thread sanitizer causes broken LLVM emission. #122476

Closed
Lee-Janggun opened this issue Mar 14, 2024 · 5 comments · Fixed by #122772
Closed

Compiling std atomic with thread sanitizer causes broken LLVM emission. #122476

Lee-Janggun opened this issue Mar 14, 2024 · 5 comments · Fixed by #122772
Labels
A-atomic Area: atomics, barriers, and sync primitives A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality. C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Lee-Janggun
Copy link
Contributor

Lee-Janggun commented Mar 14, 2024

Update: I forgot to write the command, its

RUSTFLAGS="-Z sanitizer=thread" cargo +nightly test -Z build-std --target aarch64-apple-darwin "$@"

I tried this code:

// A blank lib.rs for a library project also works.

use core::sync::atomic::AtomicUsize;

fn main() {
    println!("Hello, world!",);
}

I expected to see this happen: compiles fine

Instead, this happened: I get an rustc-LLVM ERROR: Broken function found, compilation aborted!.

This does not occur on nightly-2024-03-12.

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (3cbb93223 2024-03-13)
binary: rustc
commit-hash: 3cbb93223f33024db464a4df27a13c7cce870173
commit-date: 2024-03-13
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0
Backtrace

janggun@J-Lee-MacBook-Air RUSTFLAGS="-Z sanitizer=thread" cargo +nightly test -Z build-std --target aarch64-apple-darwin "$@"
   Compiling std v0.0.0 (/Users/janggun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-std v1.99.0 (/Users/janggun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-std)
   Compiling proc_macro v0.0.0 (/Users/janggun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling unicode-width v0.1.11
   Compiling getopts v0.2.21
   Compiling test v0.0.0 (/Users/janggun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/test)
ZExt only operates on integer
  %13 = zext ptr %1 to i64, !dbg !6602
ZExt only operates on integer
  %16 = zext ptr %1 to i64, !dbg !6603
ZExt only operates on integer
  %19 = zext ptr %1 to i64, !dbg !6604
ZExt only operates on integer
  %22 = zext ptr %1 to i64, !dbg !6605
ZExt only operates on integer
  %25 = zext ptr %1 to i64, !dbg !6606
in function _ZN4core4sync6atomic11atomic_swap17hd7a3400f2ad7716aE
rustc-LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `std` (lib)
warning: build failed, waiting for other jobs to finish...
ZExt only operates on integer
  %13 = zext ptr %1 to i64, !dbg !5113
ZExt only operates on integer
  %16 = zext ptr %1 to i64, !dbg !5114
ZExt only operates on integer
  %19 = zext ptr %1 to i64, !dbg !5115
ZExt only operates on integer
  %22 = zext ptr %1 to i64, !dbg !5116
ZExt only operates on integer
  %25 = zext ptr %1 to i64, !dbg !5117
in function _ZN4core4sync6atomic11atomic_swap17h83c92551d8fdbc7aE
rustc-LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `test` (lib)

@Lee-Janggun Lee-Janggun added the C-bug Category: This is a bug. label Mar 14, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 14, 2024
@jieyouxu jieyouxu added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality. requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-atomic Area: atomics, barriers, and sync primitives T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 14, 2024
@ltratt
Copy link
Contributor

ltratt commented Mar 14, 2024

We are also seeing this error with rust + thread sanitiser on x86.

ltratt added a commit to ltratt/yk that referenced this issue Mar 14, 2024
@nikic
Copy link
Contributor

nikic commented Mar 14, 2024

Probably caused by #122220, though the actual bug may be in LLVM. cc @saethlin

@durin42
Copy link
Contributor

durin42 commented Mar 14, 2024

We're seeing a weird bitcode level error in our rustc built against head that root-caused to that same PR FWIW.

@nikic
Copy link
Contributor

nikic commented Mar 14, 2024

It's a tsan bug: llvm/llvm-project#85226

@durin42
Copy link
Contributor

durin42 commented Mar 14, 2024

Confirmed that llvm/llvm-project#85226 fixes the bug we were seeing too. Thanks for the quick fix!

ltratt added a commit to ltratt/yk that referenced this issue Mar 16, 2024
@nikic nikic added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade label Mar 20, 2024
@bors bors closed this as completed in 6ec953c Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-atomic Area: atomics, barriers, and sync primitives A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality. C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants