Skip to content

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

@matthiaskrgr

Description

@matthiaskrgr
Member

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

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Oct 31, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 31, 2024
changed the title [-]ICE: malformed `malformed repr(align(N)[/-] [+]ICE: malformed `malformed repr(align(N))`[/+] on Oct 31, 2024
self-assigned this
on Oct 31, 2024
added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 31, 2024
jieyouxu

jieyouxu commented on Oct 31, 2024

@jieyouxu
Member

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

jieyouxu

jieyouxu commented on Oct 31, 2024

@jieyouxu
Member

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

workingjubilee commented on Oct 31, 2024

@workingjubilee
Member

cargo bisect-rustc does pin it down to that:

jieyouxu

jieyouxu commented on Oct 31, 2024

@jieyouxu
Member

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

workingjubilee

workingjubilee commented on Oct 31, 2024

@workingjubilee
Member

...I guess this is technically a regression?

jieyouxu

jieyouxu commented on Oct 31, 2024

@jieyouxu
Member

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

jieyouxu

jieyouxu commented on Oct 31, 2024

@jieyouxu
Member

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

41 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-alignArea: alignment control (`repr(align(N))` and so on)A-attributesArea: Attributes (`#[…]`, `#![…]`)A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-lowLow priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @chenyukang@matthiaskrgr@fmease@jdonszelmann@asquared31415

    Issue actions

      ICE: malformed `malformed repr(align(N))` · Issue #132391 · rust-lang/rust