Skip to content

Compiler crashes on inline asssembly #54376

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

Closed
joshlf opened this issue Sep 20, 2018 · 6 comments
Closed

Compiler crashes on inline asssembly #54376

joshlf opened this issue Sep 20, 2018 · 6 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@joshlf
Copy link
Contributor

joshlf commented Sep 20, 2018

When compiling the following program:

#![feature(asm)]

fn main() {
    unsafe { asm!("callq $0" : : "0"(foo)) };
}

extern "C" {
    fn foo(a: usize);
}

I get the following failure:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: rustc_codegen_llvm::llvm::diagnostic::Diagnostic::unpack
  11: rustc_codegen_llvm::back::write::diagnostic_handler
  12: _ZN4llvm17DiagnosticHandler17handleDiagnosticsERKNS_14DiagnosticInfoE
  13: _ZN4llvm11LLVMContext8diagnoseERKNS_14DiagnosticInfoE
  14: _ZN4llvm11LLVMContext9emitErrorEjRKNS_5TwineE
  15: _ZNK4llvm10AsmPrinter13EmitInlineAsmEPKNS_12MachineInstrE
  16: _ZN4llvm10AsmPrinter16EmitFunctionBodyEv
  17: _ZN4llvm13X86AsmPrinter20runOnMachineFunctionERNS_15MachineFunctionE
  18: _ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE
  19: _ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE
  20: _ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE
  21: _ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE
  22: LLVMRustWriteOutputFile
  23: rustc_codegen_llvm::back::write::write_output_file
  24: rustc_codegen_llvm::back::write::codegen::{{closure}}
  25: rustc::util::common::time_ext
  26: rustc_codegen_llvm::back::write::codegen
  27: rustc_codegen_llvm::back::write::execute_work_item
query stack during panic:
end of query stack
error: aborting due to worker thread failure

error: aborting due to previous error

Playground link

$ rustc --version
rustc 1.30.0-nightly (90d36fb59 2018-09-13)
@paoloteti
Copy link
Contributor

Your asm code is wrong. You need an immediate value or %eax with callq. This is the root-casue and you may experice the same issue with probably any asm (malformed) code. In a sense this is a well-known issue.

@joshlf
Copy link
Contributor Author

joshlf commented Sep 20, 2018

Your asm code is wrong. You need an immediate value or %eax with callq. This is the root-casue and you may experice the same issue with probably any asm (malformed) code. In a sense this is a well-known issue.

I figured it was invalid, but the compiler still shouldn't crash :)

@paoloteti
Copy link
Contributor

Yes! My remarks was "is a well-known issue". So most likely is a duplicate.

@joshlf
Copy link
Contributor Author

joshlf commented Sep 20, 2018

It doesn't look like a duplicate of any of the existing inline assembly ICEs; this is the only issue I've found which manifests as an unwrap on a None value.

@estebank estebank added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Sep 20, 2018
@levex
Copy link
Contributor

levex commented Sep 26, 2018

This will be fixed by #54568, which checks whether the constraints make sense for the inline assembly.

$ rustc +stage1 54376.rs
error[E0668]: malformed inline assembly
 --> 54376.rs:4:14
  |
4 |     unsafe { asm!("callq $0" : : "0"(foo)) };
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0668`.

Although, it looks like the error message isn't particularly helpful at this point.

@varkor
Copy link
Member

varkor commented Oct 8, 2018

Fixed by #54568.

@varkor varkor closed this as completed Oct 8, 2018
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!(…)`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants