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

Unknown inline asm constraints cause LLVM assertion failures #16337

Closed
main-- opened this issue Aug 7, 2014 · 6 comments
Closed

Unknown inline asm constraints cause LLVM assertion failures #16337

main-- opened this issue Aug 7, 2014 · 6 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`)

Comments

@main--
Copy link
Contributor

main-- commented Aug 7, 2014

#![feature(asm)]

fn main() {
    let x = 42u;
    unsafe { asm!("" :: "g"(x)); }
}
rustc: /build/buildd/rust-nightly-201408070406~8fe73f1~trusty/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6668: void llvm::SelectionDAGBuilder::visitInlineAsm(llvm::ImmutableCallSite): Assertion `(OpInfo.ConstraintType == TargetLowering::C_RegisterClass || OpInfo.ConstraintType == TargetLowering::C_Register) && "Unknown constraint type!"' failed.
Aborted (core dumped)

This is caused by any constraints that rustc can't handle (even something obviously invalid like ö). But shouldn't g work?

@huonw
Copy link
Member

huonw commented Aug 7, 2014

As you can see (and as implied by the feature gate) Inline asm! is very experimental: we currently essentially pass all the input directly to LLVM, including the constraints, so if LLVM doesn't support g then we don't either (for reference: those docs are for GCC).

@main--
Copy link
Contributor Author

main-- commented Aug 8, 2014

I didn't expect 100% bug-free inline asm, but I was told to report all LLVM assertion failures, so that's what I did.

And my experience with clang was always that LLVM has no/little docs but it doesn't matter because you can just use the GCC docs and everything will work. Apparently just clang emulates gcc and not LLVM, so this doesn't apply to rust. Sorry about that.

But are there even any LLVM docs about inline asm? Google always leads me to the GCC docs.

@pczarn
Copy link
Contributor

pczarn commented Aug 8, 2014

In GCC constraints, g is equivalent to rmi. Inline asm! doesn't currently bother with constraints unsupported by LLVM.

@huonw
Copy link
Member

huonw commented Aug 8, 2014

@main-- sorry for confusion, my comment was just addressing your question "But shouldn't g work?".

But are there even any LLVM docs about inline asm? Google always leads me to the GCC docs.

I don't think there are any. AIUI, the only docs is the source, but I don't personally know where in LLVM it is implemented (it's annoyed me in the past too).

@sanxiyn sanxiyn added the A-inline-assembly Area: Inline assembly (`asm!(…)`) label Jan 25, 2015
@steveklabnik
Copy link
Member

The inline asm docs explicitly link to the LLVM docs, and say that we use something "like GCC" but not the same as gcc.

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!(…)`)
Projects
None yet
Development

No branches or pull requests

6 participants