Reporting errors in inline assembly

I want to report a problem with an inline assembly instruction from a code generator pass?

How can I do that with the proper diagnostic format and source location?

Right now we only get:

clang -c /d/g/clang-tests/gcc-4_2-testsuite/src/
fatal error: error in backend: Inline asm output regs must be last on the x87 stack

But gcc-4-2 can:

$ gcc-4.2 -c /d/g/clang-tests/gcc-4_2-testsuite/src/
/d/g/clang-tests/gcc-4_2-testsuite/src/ In function ‘foo’:
/d/g/clang-tests/gcc-4_2-testsuite/src/ error: output regs must be grouped at top of stack

Didn't we add support for source locations for the integrated assembler?


First of all, you need to capture location info in InlineAsm because debug info is not always available.

Yes, clang attaches a special !srcloc cookie to inline asm. This was originally added so the integrated assembler can report errors in bad inline assembly.

I added a MachineInstr::emitError() method that finds this cookie and uses it to report an error related to inline asm.

This method is now used by X86FloatingPoint.cpp to complain about bad x87 stack constraints, and the register allocators use it when inline asm causes them to run out of registers.

$ Release+Asserts/bin/clang -c pr30848.c
pr30848.c:5:12: error: output regs must be last on the x87 stack
  __asm__ ("" : "=u" (d)); /* { dg-error "output regs" } */
1 error generated.