From 6b76cfe6cb6a2073eec53dd203fc7e4bb8e0fc31 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 28 Feb 2019 00:55:09 +0000 Subject: [PATCH] Ensure that set constrained asm operands are not affected by truncation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355058 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 6 ++++-- test/Sema/inline-asm-validate-x86.c | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index d41f4c6462..7b9f9d9565 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -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; } diff --git a/test/Sema/inline-asm-validate-x86.c b/test/Sema/inline-asm-validate-x86.c index b238ab8a50..026216c92a 100644 --- a/test/Sema/inline-asm-validate-x86.c +++ b/test/Sema/inline-asm-validate-x86.c @@ -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; @@ -71,6 +72,9 @@ void L(int i, int j) { __asm__("xorl %0,%2" : "=r"(i) : "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 -- 2.40.0