[PATCH] Improve diagnostics for asm immediate constraints and downgrade from error to default-error

Reid Kleckner rnk at google.com
Fri Jan 16 11:54:34 PST 2015


On Fri, Jan 16, 2015 at 11:48 AM, Joerg Sonnenberger <joerg at netbsd.org>
wrote:

> Also, using functions gives better typing in terms of documentation, so it
> seems reasonable to continue to support that.
>

I agree, it would be nice if there were a better way to write these types
of wrappers, but we don't have one.


> 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;
>   }
>

This code is still invalid and the backend will still reject this code at
-O0. Diagnosing it earlier is better.

If C had language rules for things like "this must be an ICE at compile
time", then we could do something nice here, but it doesn't. C++ has such
rules, and we can write this:
template <int __port>
unsigned char inb() {
  unsigned char __v;
  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));
  return __v;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150116/d83bba8c/attachment.html>


More information about the cfe-commits mailing list