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

libc-test panic: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false #120910

Closed
JohnTitor opened this issue Feb 11, 2024 · 5 comments · Fixed by JohnTitor/garando#22
Labels
C-gub Category: the reverse of a compiler bug is generally UB

Comments

@JohnTitor
Copy link
Member

JohnTitor commented Feb 11, 2024

libc-test now panics since 1.78.0-nightly (d44e3b95c 2024-02-09).

Code

repo: https://github.com/rust-lang/libc
example GHA run: https://github.com/rust-lang/libc/actions/runs/7852817358/job/21431727248

Not minimized yet.

gh repo clone rust-lang/libc
cd libc/libc-test
cargo test

Meta

rustc --version --verbose:

rust version 1.78.0-nightly (d44e3b95c 2024-02-09)

Error output

  thread 'main' panicked at library/core/src/panicking.rs:155:5:
  unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  thread caused non-unwinding panic. aborting.
Backtrace

<backtrace>

@JohnTitor JohnTitor added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@JohnTitor JohnTitor changed the title libc-test ICE: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false libc-test panic: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false Feb 11, 2024
@saethlin saethlin removed the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 11, 2024
@asquared31415
Copy link
Contributor

asquared31415 commented Feb 11, 2024

Probably because the condition is now being checked in debug mode even without build-std: #120594

I am inclined to say this is a bug in the calling code.

@asquared31415
Copy link
Contributor

this code is incorrect, it's calling get_unchecked on a slice with length 0 (because the vec had its length set to 0 and is coercing to a slice). Consider raw pointer manipulation with vec.as_mut_ptr() instead.

@saethlin saethlin added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 11, 2024
@JohnTitor
Copy link
Member Author

JohnTitor commented Feb 11, 2024

Thanks for clarifying! Going to close as wontfix then (the linked code is quite old rustc_syntax and yes, it's time that we have to update our test method 😓).

@JohnTitor JohnTitor closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@saethlin
Copy link
Member

This is an old pattern that I rooted out of the compiler when I first worked on these checks about a year ago. We've also since stabilized Vec::spare_capacity_mut which is a more ergonomic way to fiddle with the region between len and capacity.

@scottmcm
Copy link
Member

Also, while blame says that line is 9 years old (👀), today this is documented

It’s UB to call .get_unchecked(len), even if you immediately convert to a pointer.

https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.get_unchecked

jsirois added a commit to jsirois/garando that referenced this issue Feb 12, 2024
The previous use of `get_unchecked` was UB according to
https://doc.rust-lang.org/nightly/std/primitive.slice.html#safety-2
and rust-lang/rust#120594 exposed this leading
to a panic caught by out tests as:
```
cargo test --all
...
thread 'fold::tests::ident_transformation_in_defs' panicked at library/core/src/panicking.rs:155:5:
unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass `-p garando_syntax --lib`
...
```

Fixes rust-lang/rust#120910
@workingjubilee workingjubilee added C-gub Category: the reverse of a compiler bug is generally UB and removed C-discussion Category: Discussion or questions that doesn't represent real issues. labels Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-gub Category: the reverse of a compiler bug is generally UB
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants