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

ICE: malformed malformed repr(align(N)) #132391

Closed
matthiaskrgr opened this issue Oct 31, 2024 · 16 comments · Fixed by #133925 or #135726
Closed

ICE: malformed malformed repr(align(N)) #132391

matthiaskrgr opened this issue Oct 31, 2024 · 16 comments · Fixed by #133925 or #135726
Assignees
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-attributes Area: Attributes (`#[…]`, `#![…]`) A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 31, 2024

Code

trait MyTrait {
    #[repr(align)]
    fn myfun();
}

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (759e07f06 2024-10-30)
binary: rustc
commit-hash: 759e07f063fb8e6306ff1bdaeb70af56a878b415
commit-date: 2024-10-30
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Error output

<output>
Backtrace

warning: trait `MyTrait` is never used
 --> a.rs:1:7
  |
1 | trait MyTrait {
  |       ^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: malformed repr(align(N))
 --> a.rs:2:12
  |
2 |     #[repr(align)]
  |            ^^^^^
  |
note: delayed at compiler/rustc_passes/src/check_attr.rs:1932:28
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <rustc_passes::check_attr::CheckAttrVisitor>::check_attributes
         5: <rustc_passes::check_attr::CheckAttrVisitor as rustc_hir::intravisit::Visitor>::visit_trait_item
         6: rustc_passes::check_attr::check_mod_attrs
         7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
         8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
         9: rustc_query_impl::query_impl::check_mod_attrs::get_query_non_incr::__rust_end_short_backtrace
        10: <rustc_middle::hir::map::Map>::par_for_each_module::<rustc_interface::passes::run_required_analyses::{closure#0}::{closure#0}::{closure#1}::{closure#0}>::{closure#0}
        11: rustc_interface::passes::run_required_analyses
        12: rustc_interface::passes::analysis
        13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        16: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        17: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        18: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        19: std::sys::pal::unix::thread::Thread::new::thread_start
        20: <unknown>
        21: <unknown>
 --> a.rs:2:12
  |
2 |     #[repr(align)]
  |            ^^^^^

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/im/rustc-ice-2024-10-31T07_01_17-3418840.txt` to your bug report

note: compiler flags: --crate-type lib

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr 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 Oct 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 31, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: malformed `malformed repr(align(N) ICE: malformed malformed repr(align(N)) Oct 31, 2024
@jieyouxu jieyouxu self-assigned this Oct 31, 2024
@jieyouxu jieyouxu added A-attributes Area: Attributes (`#[…]`, `#![…]`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 31, 2024
@jieyouxu
Copy link
Member

Without performing an exact bisection, I think this is #131633.

@jieyouxu
Copy link
Member

jieyouxu commented Oct 31, 2024

Actually, #131633 simply exposed a pre-existing bug: this doesn't even error on stable or beta, lmao. Actually there's like at least 2 separate bugs here:

  1. I don't think it's allowed to use #[repr()] on a method, first of all. EDIT: based on Tracking Issue for #[repr(align(...))] on function items (fn_align) #82232, that should at least be feature-gated under fn_align.
    • To be pedantic, #[repr()] should additionally emit a warning about empty repr() doing, well, nothing. There should be already UI tests for that on some other targets, just need to also be the case for repr() on a trait's fn.
  2. align requires a value.

@workingjubilee
Copy link
Member

workingjubilee commented Oct 31, 2024

cargo bisect-rustc does pin it down to that:

@jieyouxu
Copy link
Member

Yes, #131633, because we should've emitted an error already by that point but didn't.

@workingjubilee
Copy link
Member

...I guess this is technically a regression?

@jieyouxu
Copy link
Member

The previous behavior is also unintentionally accepted code, I think.

@jieyouxu
Copy link
Member

jieyouxu commented Oct 31, 2024

This is actually a deficiency in how attributes are currently handled, pending a work cf. rust-lang/compiler-team#796. This should not be spot-fixed, how this is even handled in the first place needs to be fixed (allow-list rather than deny-list), and preferably don't mix AST with HIR.

cf. https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Attribute.20handling.20reworks.20compiler-team.23796/near/479823942

@jieyouxu jieyouxu removed their assignment Oct 31, 2024
@workingjubilee
Copy link
Member

expecting this to be resolved either by #131808 or a followup

@jdonszelmann
Copy link
Contributor

@rustbot claim

@jieyouxu jieyouxu added the P-low Low priority label Oct 31, 2024
@jieyouxu
Copy link
Member

Marking as P-low because it's accepting code that we shouldn't be accepting, the ICE is just "don't write malformed code" but yeah.

@asquared31415
Copy link
Contributor

woo i uncovered a bug! i knew attribute handling was weird, but i'm shocked that it's possible to hit this code path without trying to parse the repr attribute anywhere else that would error.

@jdonszelmann
Copy link
Contributor

@rustbot label +A-repr +A-align

@rustbot rustbot added A-align Area: alignment control (`repr(align(N))` and so on) A-repr Area: the `#[repr(stuff)]` attribute labels Nov 1, 2024
@fmease
Copy link
Member

fmease commented Nov 6, 2024

(due diligence, cc #132693 (comment))

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Nov 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 18, 2025
…<try>

disallow `repr()` on invalid items

fixes rust-lang#129606
fixes rust-lang#132391

Disallows `repr()` (so a repr with no arguments) on items where that won't ever make sense.

Also this generates an error when `repr` is used on a trait method and the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first accepts the align attribute on trait methods.

r? `@compiler-errors`

cc `@jdonszelmann` who claimed rust-lang#132391 and generally has been working on attributes
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 6, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 6, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2025
…r=compiler-errors

disallow `repr()` on invalid items

fixes rust-lang#129606
fixes rust-lang#132391

Disallows `repr()` (so a repr with no arguments) on items where that won't ever make sense.

Also this generates an error when `repr` is used on a trait method and the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first accepts the align attribute on trait methods.

r? `@compiler-errors`

cc `@jdonszelmann` who claimed rust-lang#132391 and generally has been working on attributes
@bors bors closed this as completed in 4b7e55a Feb 7, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 7, 2025
Rollup merge of rust-lang#133925 - folkertdev:improve-repr-warnings, r=compiler-errors

disallow `repr()` on invalid items

fixes rust-lang#129606
fixes rust-lang#132391

Disallows `repr()` (so a repr with no arguments) on items where that won't ever make sense.

Also this generates an error when `repr` is used on a trait method and the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first accepts the align attribute on trait methods.

r? `@compiler-errors`

cc `@jdonszelmann` who claimed rust-lang#132391 and generally has been working on attributes
@chenyukang
Copy link
Member

This should be reopen, PR #133925 only fixed the ICE for

#[repr()]

Not fixed for code in this case:

#[repr(align)]

@chenyukang chenyukang reopened this Feb 9, 2025
@jdonszelmann
Copy link
Contributor

jdonszelmann commented Feb 9, 2025

there's a test for this in #135726 to show that this it fixes this. I expect to merge it in the coming week or two closing this one for good

@chenyukang
Copy link
Member

there's a test for this in #135726 to show that this it fixes this. I expect to merge it in the coming week or two closing this one for good

great! please also link #136717 for that PR.

jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 9, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 9, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 9, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 10, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 10, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 10, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 11, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 22, 2025
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 22, 2025
New attribute parsing infrastructure

Another step in the plan outlined in rust-lang#131229

introduces infrastructure for structured parsers for attributes, as well as converting a couple of complex attributes to have such structured parsers.

This PR may prove too large to review. I left some of my own comments to guide it a little. Some general notes:

- The first commit is basically standalone. It just preps some mostly unrelated sources for the rest of the PR to work. It might not have enormous merit on its own, but not negative merit either. Could be merged alone, but also doesn't make the review a whole lot easier. (but it's only +274 -209)
- The second commit is the one that introduces new infrastructure. It's the important one to review.
- The 3rd commit uses the new infrastructure showing how some of the more complex attributes can be parsed using it. Theoretically can be split up, though the parsers in this commit are the ones that really test the new infrastructure and show that it all works.
- The 4th commit fixes up rustdoc and clippy. In the previous 2 they didn't compile yet while the compiler does. Separated them out to separate concerns and make the rest more palatable.
- The 5th commit blesses some test outputs. Sometimes that's just because a diagnostic happens slightly earlier than before, which I'd say is acceptable. Sometimes a diagnostic is now only emitted once where it would've been twice before (yay! fixed some bugs). One test I actually moved from crashes to fixed, because it simply doesn't crash anymore. That's why this PR  Closes rust-lang#132391. I think most choices I made here are generally reasonable, but let me know if you disagree anywhere.
- The 6th commit adds a derive to pretty print attributes
- The 7th removes smir apis for attributes, for the time being. The api will at some point be replaced by one based on `rustc_ast_data_structures::AttributeKind`

In general, a lot of the additions here are comments. I've found it very important to document new things in the 2nd commit well so other people can start using it.

Closes rust-lang#132391
Closes rust-lang#136717
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue Feb 24, 2025
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 24, 2025
New attribute parsing infrastructure

Another step in the plan outlined in rust-lang#131229

introduces infrastructure for structured parsers for attributes, as well as converting a couple of complex attributes to have such structured parsers.

This PR may prove too large to review. I left some of my own comments to guide it a little. Some general notes:

- The first commit is basically standalone. It just preps some mostly unrelated sources for the rest of the PR to work. It might not have enormous merit on its own, but not negative merit either. Could be merged alone, but also doesn't make the review a whole lot easier. (but it's only +274 -209)
- The second commit is the one that introduces new infrastructure. It's the important one to review.
- The 3rd commit uses the new infrastructure showing how some of the more complex attributes can be parsed using it. Theoretically can be split up, though the parsers in this commit are the ones that really test the new infrastructure and show that it all works.
- The 4th commit fixes up rustdoc and clippy. In the previous 2 they didn't compile yet while the compiler does. Separated them out to separate concerns and make the rest more palatable.
- The 5th commit blesses some test outputs. Sometimes that's just because a diagnostic happens slightly earlier than before, which I'd say is acceptable. Sometimes a diagnostic is now only emitted once where it would've been twice before (yay! fixed some bugs). One test I actually moved from crashes to fixed, because it simply doesn't crash anymore. That's why this PR  Closes rust-lang#132391. I think most choices I made here are generally reasonable, but let me know if you disagree anywhere.
- The 6th commit adds a derive to pretty print attributes
- The 7th removes smir apis for attributes, for the time being. The api will at some point be replaced by one based on `rustc_ast_data_structures::AttributeKind`

In general, a lot of the additions here are comments. I've found it very important to document new things in the 2nd commit well so other people can start using it.

Closes rust-lang#132391
Closes rust-lang#136717
@bors bors closed this as completed in 7d8c6e7 Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-attributes Area: Attributes (`#[…]`, `#![…]`) A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants