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

Array as asm output ICEs LLVM #13368

Closed
kmcallister opened this issue Apr 7, 2014 · 13 comments
Closed

Array as asm output ICEs LLVM #13368

kmcallister opened this issue Apr 7, 2014 · 13 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kmcallister
Copy link
Contributor

#![feature(asm)]

fn main() {
    let arr: [u8; 16];
    unsafe { asm!("" : "=m"(arr)); }
    println!("{:?}", arr);
}
$ rustc --version
rustc 1.0.0-dev (896cb36ec 2015-01-14 12:19:58 +0000)

$ rustc foo.rs
Unknown type!
UNREACHABLE executed at /home/keegan/rust-master/src/llvm/lib/IR/ValueTypes.cpp:251!
Aborted
@erickt
Copy link
Contributor

erickt commented May 10, 2014

visiting for triage. Still reproducible.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 22, 2014
@steveklabnik
Copy link
Member

Triage: still reproduces

@kmcallister
Copy link
Contributor Author

Updated the code.

@tamird
Copy link
Contributor

tamird commented Apr 21, 2015

Triage: this is worse now - no longer an ICE, this now causes all kinds of failures:

$ rustc --version
rustc 1.0.0-dev (f46c4e158 2015-04-20) (built 2015-04-20)
$ rustc src/bin/main.rs
Segmentation fault: 11
$ rustc src/bin/main.rs
Segmentation fault: 11
$ rustc src/bin/main.rs
Segmentation fault: 11
$ RUST_BACKTRACE=1 rustc src/bin/main.rs
Illegal instruction: 4
$ RUST_BACKTRACE=1 rustc src/bin/main.rs
Segmentation fault: 11
$ RUST_BACKTRACE=1 rustc src/bin/main.rs
Segmentation fault: 11
$ RUST_BACKTRACE=1 rustc src/bin/main.rs
Illegal instruction: 4

@kmcallister
Copy link
Contributor Author

I don't remember whether we now disable LLVM assertions by default, but that might explain the change.

@dotdash
Copy link
Contributor

dotdash commented Apr 22, 2015

LLVM assertions are off by default now, only with --enable-llvm-assertions or --enable-debug and the nightly channel have them enabled. @tamird could you please check whether LLVM assertions are enabled in your rustc, and if not, re-check this and any other issues that you triaged that were about LLVM assertions? Thanks!

@jooert
Copy link
Contributor

jooert commented May 11, 2015

With LLVM assertions enabled, this still fails with the original error.

@jethrogb
Copy link
Contributor

Possibly related to #15402

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed I-wrong labels Jul 20, 2017
@chordowl
Copy link
Contributor

Triage: still reproduces:

Unknown type!
UNREACHABLE executed at /checkout/src/llvm/lib/IR/ValueTypes.cpp:285!
error: Could not compile `playground`.

@cuviper
Copy link
Member

cuviper commented Sep 11, 2018

With llvm-assertions, the error is still in the same place:

Unknown type!
UNREACHABLE executed at [...]/rust/src/llvm/lib/CodeGen/ValueTypes.cpp:285!
Aborted (core dumped)

The code in question doesn't look able to support direct arrays:
https://github.com/rust-lang/llvm/blob/5a081f0363340dd895d0958955d0c84661f60f05/lib/CodeGen/ValueTypes.cpp#L285

Backtrace from GDB:

#0  0x00007ffff72f4eab in raise () from /lib64/libc.so.6
#1  0x00007ffff72df5b9 in abort () from /lib64/libc.so.6
#2  0x00007fffede0bbba in llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) ()
#3  0x00007fffed381cb1 in llvm::MVT::getVT(llvm::Type*, bool) [clone .localalias.44] ()
#4  0x00007fffed381ce4 in llvm::EVT::getEVT(llvm::Type*, bool) ()
#5  0x00007fffecfa75bb in llvm::TargetLowering::ParseConstraints(llvm::DataLayout const&, llvm::TargetRegisterInfo const*, llvm::ImmutableCallSite) const ()
#6  0x00007fffece2eb6e in llvm::FunctionLoweringInfo::set(llvm::Function const&, llvm::MachineFunction&, llvm::SelectionDAG*) ()
#7  0x00007fffecf83b96 in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .part.971] ()
#8  0x00007fffebfeb874 in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
#9  0x00007fffed1972a4 in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
#10 0x00007fffedba2658 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
#11 0x00007fffedba26d9 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
#12 0x00007fffedba1cb8 in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
#13 0x00007fffebf0fdd2 in LLVMRustWriteOutputFile ()
[...]

The LLVM-IR for the call looks like:

  %arr = alloca [16 x i8], align 1
  %0 = call [16 x i8] asm "", "=m,~{dirflag},~{fpsr},~{flags}"(), !srcloc !6
  store [16 x i8] %0, [16 x i8]* %arr, align 1

I tried to create a similar input for clang:

#include <stdint.h>
#include <stdio.h>
int main() {
    uint8_t arr[16];
    asm("" : "=m" (arr));
    printf("[%i, ..]\n", arr[0]);
    return 0;
}

The IR here instead gives the array as an indirect parameter for the call, through a pointer, and just returns void.

  %2 = alloca [16 x i8], align 16
  call void asm "", "=*m,~{dirflag},~{fpsr},~{flags}"([16 x i8]* %2) #2, !srcloc !2

@pnkfelix pnkfelix added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 5, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jun 3, 2019

ICE is dependent on feature(asm) (cc #29722), which is not on the 2019 roadmap. Marking as P-medium until we get an overall plan for asm in Rust.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 3, 2019

(Although the fact that this can cause rustc itself to segfault, presumably via a problem internal to LLVM, does lead me to wonder if I should up the priority to P-high anyway.)

@pnkfelix pnkfelix added the P-medium Medium priority label Jun 3, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 12, 2020
Alexendoo added a commit to Alexendoo/cargo-bisect-rustc that referenced this issue Apr 20, 2020
This matches the definition [used in glacier], which includes exit status
101 without an accompanying diagnostic (such as rust-lang/rust#21599), and when
rustc is killed by a signal (rust-lang/rust#13368)

This also means no processing modes are capturing stdio, but I didn't
remove it as it may be desired for the regex features discussed in rust-lang#53

[used in glacier]: https://github.com/rust-lang/glacier/blob/77029d8e7f755bd95913d3c741738674d5ccadc3/src/lib.rs#L51-L56
@Amanieu
Copy link
Member

Amanieu commented May 22, 2020

This issue does not apply to the new asm! (RFC 2850) which has stricter checks on the types that can be used as asm operands.

The legacy llvm_asm! is deprecated and is no longer maintained.

@Amanieu Amanieu closed this as completed May 22, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 18, 2022
…, r=lowr

fix: reorder dyn bounds on render

Fixes rust-lang#13368

rust-lang#13192 changed the order of dyn bounds, violating the [contract](https://github.com/rust-lang/rust-analyzer/blob/3a69435af7a1e6273744085cb251adb2b9c30a03/crates/hir-ty/src/display.rs#L896-L901) with `write_bounds_like_dyn_trait()` on render. The projection bounds are expected to come right after the trait bound they are accompanied with.

Although the reordering procedure can be made a bit more efficient, I opted for relying only on the [invariants](https://github.com/rust-lang/rust-analyzer/blob/3a69435af7a1e6273744085cb251adb2b9c30a03/crates/hir-ty/src/lower.rs#L995-L998) currently documented in `lower_dyn_trait()`. It's not the hottest path and dyn bounds tend to be short so I believe it shouldn't hurt performance noticeably.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 24, 2024
Bump ui_test

This should give a bunch of ui improvements when lots of tests are running. Please lmk of any issues with it. Switching to `--quiet` should always avoid any issues, so there's a workaround if anything crops up. Also please check that this does not regress performance for you. It doesn't for me, but that doesn't mean much.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. 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