ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Better error message when inline asm constraints fail

Open jacob-carlborg opened this issue 2 years ago • 2 comments

Currently when an inline assembly constraints are wrong, the compiler outputs the same error message regardless of what's wrong: inline asm constraints are invalid. It would be nice if the compiler could actually print what was wrong. It took me quite a while before I figured out that whitespaces are not allowed in constraints, especially since the x86-64 inline assembly example [1] does contain whitespaces in the constraints. It's especially confusing since it seems to be possible to have whitespace between outputs and inputs and between inputs, but not before or between clobbers.

[1] https://wiki.dlang.org/LDC_inline_assembly_expressions#Examples_2

jacob-carlborg avatar May 18 '22 06:05 jacob-carlborg

AFAICT, LLVM's functionality is limited in this regard. We use llvm::InlineAsm::Verify() to verify the constraints string, and that returns a bool. ;)

That said, we encourage using GCC-style inline asm instead of the older LDC-inline-asm expressions (except for one-liners with an output, where the expression requires less boilerplate). Each constraint is separate there, so whitespaces inbetween constraints not a thing.

kinke avatar May 18 '22 10:05 kinke

AFAICT, LLVM's functionality is limited in this regard. We use llvm::InlineAsm::Verify() to verify the constraints string, and that returns a bool. ;)

That's unfortunate 😞.

That said, we encourage using GCC-style inline asm instead of the older LDC-inline-asm expressions (except for one-liners with an output, where the expression requires less boilerplate). Each constraint is separate there, so whitespaces inbetween constraints not a thing.

Aha, I see. I didn't know about that, thanks.

jacob-carlborg avatar May 18 '22 18:05 jacob-carlborg

This has changed with LLVM15 and is fixed by https://github.com/ldc-developers/ldc/pull/4168 LLVM15 support is still in development but should be useable very soon.

thewilsonator avatar Sep 15 '22 11:09 thewilsonator