Skip to content

ICE: empty struct + extern function on 32-bit OS #16441

Closed

Description

@klutzy
#![crate_type = "lib"]
#![no_std]

struct Empty;
extern "C" fn ice(_a: Empty) {}

with --target=i686-unknown-linux-gnu or --target=i686-pc-mingw32:

task 'rustc' failed at 'assertion failed: index < LLVMCountParams(llfn)',
/path/to/rust/src/librustc_llvm/lib.rs:2041

stack backtrace:
   1:     0x7f0ae672fe70 - rt::backtrace::imp::write::h43dac5486f5e7461t9p
   2:     0x7f0ae6732f10 - failure::on_fail::h1e234ec252bd138bGuq
   3:     0x7f0ae6ef5a60 - unwind::begin_unwind_inner::h84cc9a0765812e46M8d
   4:     0x7f0ae6ef5750 - unwind::begin_unwind_fmt::h5294fb1154f645ceh6d
   5:     0x7f0ae3604670 - get_param::h6626c97fe8bc39e4rnc
   6:     0x7f0ae7698af0 - middle::trans::foreign::trans_rust_fn_with_foreign_abi::hc91c30d50c9f14e9nil
   7:     0x7f0ae7689820 - middle::trans::base::trans_item::h5d5ded2b8a3e87b4Fhd
   8:     0x7f0ae7755770 - middle::trans::base::trans_crate::h4ac87b78eadb9f067be
   9:     0x7f0ae7b6c440 - driver::driver::phase_4_translate_to_llvm::hacd93d74c4c452e1wCw
...

This causes #15811. (cc jeremyletang/rgtk#26)

Activity

  1. luqmana commented on Aug 12, 2014

    @luqmana
    Contributor

    The reason for this seems to be that we mark zero-sized structs as Ignore in middle::trans::cabi_x86 and thus when we create the foreign wrapper function it doesn't have as many arguments as we expected. Whereas with x86_64 we never mark any arguments as Ignore. I'm not sure as to whether we want to go one way or the other.

    cc @dotdash any opinions on this?

  2. dotdash commented on Aug 13, 2014

    @dotdash
    Contributor

    I just checked with clang, and it always ignores empty structs (tried i686, x86_64, mips and arm targets), though it doesn't seem to affect the generated asm whether or not the argument is present, as long as it's passed as a direct argument (only tried on i686 and x86_64). The problem we had before, which was resolved by introducing the "Ignore" arg kind by @klutzy was that like all structs, the empty struct was passed as an indirect argument on x86. And that messed up the ffi since it used stack space.

    It's a bit sad, since it complicates things, but I guess we should be doing the same as clang here and simply ignore empty structs. Maybe it can be done a bit easier if we make it so that it's not platform specific but done for all foreign functions?

  3. added a commit that references this issue on Aug 13, 2014
    4df0430
  4. added a commit that references this issue on Aug 14, 2014
    56b86aa
  5. added
    O-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)
    and removed on Oct 25, 2023
  6. added a commit that references this issue on Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️O-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions