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

Compiler panic in objrs package attribute macros class and root_class #82836

Closed
ottobommer opened this issue Mar 6, 2021 · 22 comments
Closed
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium 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

@ottobommer
Copy link

Code

git clone https://gitlab.com/ootoo1/objrs.git
cd objrs/frameworks/foundation/
cargo build

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (caca2121f 2021-03-05)
binary: rustc
commit-hash: caca2121ffe4cb47d8ea2d9469c493995f57e0b5
commit-date: 2021-03-05
host: x86_64-apple-darwin
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

   Compiling objrs_frameworks_foundation v0.0.3-dev (/Users/ootoo/Projekte/objrs/frameworks/foundation)
error: any use of this value will cause an error
  --> frameworks/foundation/src/nsobject.rs:18:1
   |
18 | #[objrs(class, root_class)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ inbounds test failed: 0x0 is not a valid pointer
   |
   = note: `#[deny(const_err)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: any use of this value will cause an error
  --> frameworks/foundation/src/nsobject.rs:18:1
   |
18 | #[objrs(class, root_class)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown(T)', compiler/rustc_lint/src/types.rs:802:52
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting module `nsarray`
#1 [analysis] running analysis passes on this crate
end of query stack
@ottobommer ottobommer added C-bug Category: This is a bug. 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. labels Mar 6, 2021
@jonas-schievink jonas-schievink added I-prioritize Issue: Indicates that prioritization has been requested for this issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Mar 6, 2021
@JohnTitor JohnTitor added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 6, 2021
@ottobommer
Copy link
Author

Code

Minor changes to https://gitlab.com/ootoo1/objrs.git (added min_const_generics + allow(const_err)), the above errors are gone, but the compiler panic remains.

Error output

warning: the feature `min_const_generics` has been stable since 1.51.0 and no longer requires an attribute to enable
 --> macros/src/lib.rs:6:73
  |
6 | #![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site, min_const_generics)]
  |                                                                         ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default

warning: 1 warning emitted

   Compiling objrs_frameworks_foundation_macros v0.0.3-dev (/Users/ootoo/tmp/objrs/frameworks/foundation/macros)
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
  --> src/lib.rs:13:3
   |
13 |   specialization,
   |   ^^^^^^^^^^^^^^
   |
   = note: `#[warn(incomplete_features)]` on by default
   = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
   = help: consider using `min_specialization` instead, which is more stable and complete

warning: 1 warning emitted

   Compiling objrs_frameworks_foundation v0.0.3-dev (/Users/ootoo/tmp/objrs/frameworks/foundation)
warning: field is never read: `isa`
  --> frameworks/foundation/src/nsobject.rs:22:3
   |
22 |   isa: *mut objrs::Class,
   |   ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown(T)', compiler/rustc_lint/src/types.rs:802:52
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting module `nsarray`
#1 [analysis] running analysis passes on this crate
end of query stack
warning: 1 warning emitted

error: could not compile `objrs_frameworks_foundation`

To learn more, run the command again with --verbose.

@apiraino
Copy link
Contributor

@ottobommer would be great to provide a smaller reproducible for this

also cc: @rustbot ping icebreakers-cleanup-crew

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Mar 10, 2021
@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2021

@hellow554
Copy link
Contributor

hellow554 commented Mar 11, 2021

I can't compile this code:

error: /tmp/tmp.XE6gfi1VBB/objrs/target/debug/deps/libobjrs_macros-214fa04ac9aaf3b1.so: undefined symbol: arc4random_buf
 --> src/__objrs.rs:8:1
  |
8 | pub extern crate objrs_macros;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `objrs`

@ottobommer what is wrong here?
I did exactly what you wrote (clone, cd, cargo build) with your exact compiler version.

Edit: I removed the code that did not compile, It panics now.

@hellow554
Copy link
Contributor

hellow554 commented Mar 11, 2021

This is a somewhat minimal example, next step would be to get rid of all the other code (:

extern crate objrs;

use objrs::objrs;

#[objrs(class, root_class)]
pub struct NSArray<T: objrs::marker::Class + ?Sized>;

#[objrs(impl)]
#[link(name = "Foundation", kind = "framework")]
impl<T: objrs::marker::Class + ?Sized> NSArray<T> {
    #[objrs(selector = "firstObject")]
    pub fn first_object<'a>(&'a self) -> Option<&'a T> {}
}

@hellow554
Copy link
Contributor

searched toolchains nightly-2020-06-01 through nightly-2021-02-04
Regression in nightly-2020-08-09

So the error is somewhere here: 09f4c9f...ceedf1d

sadly there are no more artifacts available and I don't want to compile rust on my machine today.. ^^ So this must be it.

@ottobommer
Copy link
Author

@apiraino OK, will try to make a smaller example. As it is not my code this may take some time.

@ottobommer
Copy link
Author

I minimized the example somewhat, it can be pulled from the repository below, let me know if a further reduction is needed.

git clone https://gitlab.com/ootoo1/objrs-min.git
cd objrs-min/frameworks/foundation/
cargo build
    Updating crates.io index
  Downloaded syn v1.0.64
  Downloaded 1 crate (231.5 KB) in 0.48s
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.64
   Compiling libc v0.2.88
   Compiling quote v1.0.9
   Compiling objrs_macros v0.0.3-dev (/Users/ootoo/tmp/objrs-min/macros)
   Compiling objrs v0.0.3-dev (/Users/ootoo/tmp/objrs-min)
   Compiling objrs_frameworks_foundation v0.0.3-dev (/Users/ootoo/tmp/objrs-min/frameworks/foundation)
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown(T)', compiler/rustc_lint/src/types.rs:802:52
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `objrs_frameworks_foundation`

To learn more, run the command again with --verbose.

@JohnTitor
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@JohnTitor JohnTitor added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 17, 2021
@hellow554
Copy link
Contributor

hellow554 commented Mar 17, 2021

@ottobommer an ideal testcase would be one file without any dependencies (even std, but #![no_std] is not required), but sometimes the proc macro is needed, thefore 1 + 1 for proc macro would work as well.

@ottobommer
Copy link
Author

@hellow554 OK, I got it down to 3 files (proc macro lib.rs, lib.rs, test case panic.rs), however the total lines of code is still around 1000:

git clone https://gitlab.com/ootoo1/objrs-min.git
cd objrs-min/
cargo test
    Updating crates.io index
  Downloaded libc v0.2.89
  Downloaded 1 crate (516.0 KB) in 1.45s
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.64
   Compiling libc v0.2.89
   Compiling quote v1.0.9
   Compiling objrs_macros v0.0.3-dev (/Users/ootoo/tmp/objrs-min/macros)
   Compiling objrs v0.0.3-dev (/Users/ootoo/tmp/objrs-min)
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown(T)', compiler/rustc_lint/src/types.rs:802:52
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `objrs`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

@hellow554
Copy link
Contributor

hellow554 commented Mar 19, 2021

In the end, it's so simple...

extern "C" fn _panic<'a, T: ?Sized>() -> Option<&'a T> {
    panic!()
}

fn main() {}

It seems to be a problem with ?Sized and extern "C".
Interesting enough, it only works with Option, not with a custom enum. Maybe a lang_item thing?


After all, my humble advice would be, stay away from that code. It is the most unrusty code I've seen in a long time. So many mut variables, returns, unnecessary nested types (Result<Result<...>>)... I mean it's impressive that it works, and if you have a usecase, go for it. Make the world a better place ;)

I'm bisecting it now.

@rustbot modify labels: -E-needs-mcve

@rustbot rustbot removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 19, 2021
@hellow554
Copy link
Contributor

Regression in nightly-2020-07-31, somewhere between db0492a...cfc572c

@apiraino
Copy link
Contributor

(not sure if it helps but) I'll add the relevant merged PRs

found 10 bors merge commits in the specified range
  commit[0] 2020-07-29UTC: Auto merge of #74733 - richkadel:llvm-coverage-map-gen-5, r=tmandry
  commit[1] 2020-07-29UTC: Auto merge of #73767 - P1n3appl3:rustdoc-formats, r=tmandry
  commit[2] 2020-07-30UTC: Auto merge of #74929 - Manishearth:rollup-z2vflrp, r=Manishearth
  commit[3] 2020-07-30UTC: Auto merge of #74923 - ehuss:update-cargo, r=Mark-Simulacrum
  commit[4] 2020-07-30UTC: Auto merge of #74876 - oli-obk:lumberjack_disable, r=RalfJung
  commit[5] 2020-07-30UTC: Auto merge of #74105 - npmccallum:naked, r=matthewjasper
  commit[6] 2020-07-30UTC: Auto merge of #74930 - ecstatic-morse:const-size-align-of-val, r=oli-obk
  commit[7] 2020-07-30UTC: Auto merge of #73990 - jumbatm:clashing-extern-decl, r=nagisa
  commit[8] 2020-07-30UTC: Auto merge of #74908 - RalfJung:miri, r=RalfJung
  commit[9] 2020-07-30UTC: Auto merge of #74957 - Manishearth:rollup-3wudwlg, r=Manishearth

@hellow554
Copy link
Contributor

hellow554 commented Mar 19, 2021

@jonas-schievink you tagged this as A-Lint, but I don't think it has anything to do with linting. May you be able to spot the right label for this? Also this is regression-from-stable-to-stable

@hellow554
Copy link
Contributor

@rustbot glacier "https://gist.github.com/rust-play/386467d4077592c6699192161ac33044"

@jonas-schievink
Copy link
Contributor

I tagged it based on the panic path compiler/rustc_lint/src/types.rs.

The backtrace involves rustc_lint::types::ImproperCTypesVisitor::check_type_for_ffi, so this looks like a duplicate of #80125

@jonas-schievink
Copy link
Contributor

Ah, nevermind, that one looks related but different.

@jonas-schievink jonas-schievink added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Mar 19, 2021
@hellow554
Copy link
Contributor

#52334 looks also very similar to this.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 6, 2021
@Enselic
Copy link
Member

Enselic commented Sep 9, 2023

Turns out it is not a duplicate, because this still reproduces on nightly. An easy way to reproduce is to copy-paste this to bash:

cat <<EOF | rustc +nightly --crate-type lib -
extern "C" fn _panic<'a, T: ?Sized>() -> Option<&'a T> {
    panic!()
}
EOF

@JohnTitor
Copy link
Member

Triage: Fixed on the latest nightly, marking as E-needs-test but feel free to close if there's a regression test already.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Mar 26, 2024

Fixed in 1.74.0 by #115631, which already added a test to tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs.

@Enselic Enselic closed this as completed Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium 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

9 participants