r217994 - [X86, inline-asm] Check that the input size is correct for constraints R, q, Q,

Eric Christopher echristo at gmail.com
Wed Sep 17 16:54:16 PDT 2014


Looks good. Thanks!

-eric

2014-09-17 16:35 GMT-07:00 Akira Hatanaka <ahatanaka at apple.com>:

> Author: ahatanak
> Date: Wed Sep 17 18:35:14 2014
> New Revision: 217994
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217994&view=rev
> Log:
> [X86, inline-asm] Check that the input size is correct for constraints R,
> q, Q,
> S, D, A, y, x, f, t, and u.
>
> This is a follow-up patch for r167717.
>
> rdar://problem/11846140
> rdar://problem/17476970
>
> Modified:
>     cfe/trunk/lib/Basic/Targets.cpp
>     cfe/trunk/test/CodeGen/x86_32-inline-asm.c
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=217994&r1=217993&r2=217994&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Sep 17 18:35:14 2014
> @@ -1899,6 +1899,9 @@ public:
>    }
>    bool validateAsmConstraint(const char *&Name,
>                                       TargetInfo::ConstraintInfo &info)
> const override;
> +
> +  bool validateInputSize(StringRef Constraint, unsigned Size) const
> override;
> +
>    std::string convertConstraint(const char *&Constraint) const override;
>    const char *getClobbers() const override {
>      return "~{dirflag},~{fpsr},~{flags}";
> @@ -3049,6 +3052,21 @@ X86TargetInfo::validateAsmConstraint(con
>    }
>  }
>
> +bool X86TargetInfo::validateInputSize(StringRef Constraint,
> +                                      unsigned Size) const {
> +  switch (Constraint[0]) {
> +  default: break;
> +  case 'y':
> +    return Size <= 64;
> +  case 'x':
> +  case 'f':
> +  case 't':
> +  case 'u':
> +    return Size <= 128;
> +  }
> +
> +  return true;
> +}
>
>  std::string
>  X86TargetInfo::convertConstraint(const char *&Constraint) const {
> @@ -3109,14 +3127,21 @@ public:
>                           unsigned Size) const override {
>      switch (Constraint[0]) {
>      default: break;
> +    case 'R':
> +    case 'q':
> +    case 'Q':
>      case 'a':
>      case 'b':
>      case 'c':
>      case 'd':
> +    case 'S':
> +    case 'D':
>        return Size <= 32;
> +    case 'A':
> +      return Size <= 64;
>      }
>
> -    return true;
> +    return X86TargetInfo::validateInputSize(Constraint, Size);
>    }
>  };
>  } // end anonymous namespace
>
> Modified: cfe/trunk/test/CodeGen/x86_32-inline-asm.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-inline-asm.c?rev=217994&r1=217993&r2=217994&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGen/x86_32-inline-asm.c (original)
> +++ cfe/trunk/test/CodeGen/x86_32-inline-asm.c Wed Sep 17 18:35:14 2014
> @@ -1,5 +1,8 @@
>  // RUN: %clang_cc1 -triple i386-apple-darwin9 -verify %s
> +
>  // <rdar://problem/12415959>
> +// rdar://problem/11846140
> +// rdar://problem/17476970
>
>  typedef unsigned int u_int32_t;
>  typedef u_int32_t uint32_t;
> @@ -7,6 +10,12 @@ typedef u_int32_t uint32_t;
>  typedef unsigned long long u_int64_t;
>  typedef u_int64_t uint64_t;
>
> +typedef float __m128 __attribute__ ((vector_size (16)));
> +typedef float __m256 __attribute__ ((vector_size (32)));
> +
> +__m128 val128;
> +__m256 val256;
> +
>  int func1() {
>    // Error out if size is > 32-bits.
>    uint32_t msr = 0x8b;
> @@ -21,4 +30,17 @@ int func1() {
>    unsigned char data;
>    unsigned int port;
>    __asm__ volatile("outb %0, %w1" : : "a" (data), "Nd" (port)); // No
> error expected.
> +
> +  __asm__ volatile("outb %0, %w1" : : "R" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'R'}}
> +  __asm__ volatile("outb %0, %w1" : : "q" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'q'}}
> +  __asm__ volatile("outb %0, %w1" : : "Q" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'Q'}}
> +  __asm__ volatile("outb %0, %w1" : : "b" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'b'}}
> +  __asm__ volatile("outb %0, %w1" : : "c" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'c'}}
> +  __asm__ volatile("outb %0, %w1" : : "d" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'd'}}
> +  __asm__ volatile("outb %0, %w1" : : "S" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'S'}}
> +  __asm__ volatile("outb %0, %w1" : : "D" (val), "Nd" (port)); //
> expected-error {{invalid input size for constraint 'D'}}
> +  __asm__ volatile("foo1 %0" : : "A" (val128)); // expected-error
> {{invalid input size for constraint 'A'}}
> +  __asm__ volatile("foo1 %0" : : "f" (val256)); // expected-error
> {{invalid input size for constraint 'f'}}
> +  __asm__ volatile("foo1 %0" : : "t" (val256)); // expected-error
> {{invalid input size for constraint 't'}}
> +  __asm__ volatile("foo1 %0" : : "u" (val256)); // expected-error
> {{invalid input size for constraint 'u'}}
>  }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140917/bb1edcad/attachment.html>


More information about the cfe-commits mailing list