r355058 - Ensure that set constrained asm operands are not affected by truncation.

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 27 16:55:09 PST 2019


Author: joerg
Date: Wed Feb 27 16:55:09 2019
New Revision: 355058

URL: http://llvm.org/viewvc/llvm-project?rev=355058&view=rev
Log:
Ensure that set constrained asm operands are not affected by truncation.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/test/Sema/inline-asm-validate-x86.c

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=355058&r1=355057&r2=355058&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Feb 27 16:55:09 2019
@@ -857,8 +857,10 @@ public:
     }
     bool isValidAsmImmediate(const llvm::APInt &Value) const {
       if (!ImmSet.empty())
-        return ImmSet.count(Value.getZExtValue()) != 0;
-      return !ImmRange.isConstrained || (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
+        return Value.isSignedIntN(32) &&
+               ImmSet.count(Value.getZExtValue()) != 0;
+      return !ImmRange.isConstrained ||
+             (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
     }
 
     void setIsReadWrite() { Flags |= CI_ReadWrite; }

Modified: cfe/trunk/test/Sema/inline-asm-validate-x86.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/inline-asm-validate-x86.c?rev=355058&r1=355057&r2=355058&view=diff
==============================================================================
--- cfe/trunk/test/Sema/inline-asm-validate-x86.c (original)
+++ cfe/trunk/test/Sema/inline-asm-validate-x86.c Wed Feb 27 16:55:09 2019
@@ -56,6 +56,7 @@ void L(int i, int j) {
   static const int Invalid1 = 1;
   static const int Invalid2 = 42;
   static const int Invalid3 = 0;
+  static const long long Invalid4 = 0x1000000ff;
   static const int Valid1 = 0xff;
   static const int Valid2 = 0xffff;
   static const int Valid3 = 0xffffffff;
@@ -73,6 +74,9 @@ void L(int i, int j) {
           : "0"(i), "L"(Invalid3)); // expected-error{{value '0' out of range for constraint 'L'}}
   __asm__("xorl %0,%2"
           : "=r"(i)
+          : "0"(i), "L"(Invalid4)); // expected-error{{value '4294967551' out of range for constraint 'L'}}
+  __asm__("xorl %0,%2"
+          : "=r"(i)
           : "0"(i), "L"(Valid1)); // expected-no-error
   __asm__("xorl %0,%2"
           : "=r"(i)




More information about the cfe-commits mailing list