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 when returning an repr(i8) enum from an extern c function #80556

Closed
GabeRealB opened this issue Dec 31, 2020 · 3 comments · Fixed by #80562
Closed

ICE when returning an repr(i8) enum from an extern c function #80556

GabeRealB opened this issue Dec 31, 2020 · 3 comments · Fixed by #80562
Assignees
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@GabeRealB
Copy link

Code

#[repr(i8)]
#[derive(Debug)]
enum Type {
    Type1 = 0,
    Type2 = 1
}

extern "C" fn test() -> Type {
    Type::Type1
}

fn main() {
    println!("{:?}", test())
}

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (e22670468 2020-12-30)
binary: rustc
commit-hash: e2267046859c9ceb932abc983561d53a117089f6
commit-date: 2020-12-30
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly

Error output

Attributes 'zeroext and signext' are incompatible!
i1 ()* @_ZN10playground4test17hdbd7051ebdf54fe6E
in function _ZN10playground4test17hdbd7051ebdf54fe6E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `playground`
Backtrace

thread 'rustc' panicked at 'assertion failed: self.arg_ext == ArgExtension::None || self.arg_ext == ext', compiler/rustc_target/src/abi/call/mod.rs:100:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e2267046859c9ceb932abc983561d53a117089f6/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/e2267046859c9ceb932abc983561d53a117089f6/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/e2267046859c9ceb932abc983561d53a117089f6/library/core/src/panicking.rs:50:5
   3: rustc_target::abi::call::ArgAttributes::ext
   4: rustc_target::abi::call::x86_64::compute_abi_info::{{closure}}
   5: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_middle::ty::layout::FnAbiExt<C>>::adjust_for_abi
   6: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_middle::ty::layout::FnAbiExt<C>>::of_instance
   7: rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_llvm::context::CodegenCx>::predefine_fn
   8: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  10: rustc_codegen_llvm::base::compile_codegen_unit
  11: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  12: rustc_session::utils::<impl rustc_session::session::Session>::time
  13: rustc_interface::passes::QueryContext::enter
  14: rustc_interface::queries::Queries::ongoing_codegen
  15: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  16: rustc_span::with_source_map
  17: rustc_interface::interface::create_compiler_and_run

@GabeRealB GabeRealB 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 Dec 31, 2020
@jonas-schievink jonas-schievink added A-codegen Area: Code generation I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 31, 2020
@matthiaskrgr
Copy link
Member

@rustbot modify labels: +regression-from-stable-to-stable
This happens since rust 1.24

@rustbot rustbot added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 31, 2020
@nagisa
Copy link
Member

nagisa commented Dec 31, 2020

#![crate_type="rlib"]

#[repr(i8)]
pub enum Type {
    Type1 = 0,
    Type2 = 1
}

pub extern "C" fn test() -> Type {
    Type::Type1
}

More minimal reproducer. Does not occur with just 1 variant. Or if one of the variants has a negative discriminant. Affects most targets if not all of them, despite the failure seemingly occurring inside the target-specific code.

@rylev
Copy link
Member

rylev commented Jan 4, 2021

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

@rylev rylev added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 4, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 30, 2021
…=eddyb

Consider Scalar to be a bool only if its unsigned

This seems right, given that conceptually bools are unsigned, but the
implications of this change may have more action at distance that I'm
not sure how to exhaustively consider.

For instance there are a number of cases where code attaches range
metadata if `scalar.is_bool()` holds. Supposedly it would no longer be
attached to the `repr(i8)` enums? Though I'm not sure why booleans are
being special-cased here in the first place...

Fixes rust-lang#80556

cc `@eddyb`
@bors bors closed this as completed in 915a04e Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

Successfully merging a pull request may close this issue.

6 participants