This is an archive of the discontinued LLVM Phabricator instance.

Improve diagnostics for asm immediate constraints and downgrade from error to default-error
AbandonedPublic

Authored by joerg on Jan 16 2015, 6:36 AM.

Details

Summary

After r225244 clang verifies that inline asm constraints for immediate operands are used with ICE. This breaks existing code like pixman and tomcrypt as well as makes it impossible to create optimal output if either fixed or variable arguments can be supported. The backend has to be able to deal with the constraint check anyway and for all given cases it does. Therefore, downgrade the diagnostic from a hard error to an error-default warning. Correct use involving __builtin_constant_p can be annotated accordingly.

Diff Detail

Event Timeline

joerg updated this revision to Diff 18299.Jan 16 2015, 6:36 AM
joerg retitled this revision from to Improve diagnostics for asm immediate constraints and downgrade from error to default-error.
joerg updated this object.
joerg edited the test plan for this revision. (Show Details)
joerg added reviewers: compnerd, chandlerc, rnk.
joerg added a subscriber: Unknown Object (MLST).
rnk edited edge metadata.Jan 16 2015, 11:37 AM

I'm in favor of the diagnostic change, I wasn't aware of how bad it was.

Does anyone else mind this being a default error warning? I'd prefer a hard error. I don't understand your argument about this diagnostic making it impossible to get "optimal output". It is simply a matter of using a macro instead of an always_inline function.

compnerd edited edge metadata.Jan 16 2015, 11:41 AM

I like the new diagnostic message. I think we should get that committed (and merged for the 3.6 release). However, Im not sure I agree with the downgrading of the error in the case of the failure to validate the constant though.

Using a macro requires code changes. That's more work when dealing with 3rd party code, so I do prefer non-intrusive changes.

Also, using functions gives better typing in terms of documentation, so it seems reasonable to continue to support that.
For optimality I meant things like:

unsigned char inb (unsigned short int __port)
{
  unsigned char _v;

  if (__builtin_constant_p(__port) && __port < 256)
    __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));
  else
    __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"d" (__port));
  return _v;
}
joerg abandoned this revision.Jan 22 2015, 1:09 PM