[llvm-branch-commits] [cfe-branch] r355673 - Merging r354937:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Mar 8 01:09:28 PST 2019
Author: hans
Date: Fri Mar 8 01:09:28 2019
New Revision: 355673
URL: http://llvm.org/viewvc/llvm-project?rev=355673&view=rev
Log:
Merging r354937:
------------------------------------------------------------------------
r354937 | joerg | 2019-02-27 01:40:59 +0100 (Wed, 27 Feb 2019) | 9 lines
Fix inline assembler constraint validation
The current constraint logic is both too lax and too strict. It fails
for input outside the [INT_MIN..INT_MAX] range, but it also implicitly
accepts 0 as value when it should not. Adjust logic to handle both
correctly.
Differential Revision: https://reviews.llvm.org/D58649
------------------------------------------------------------------------
Modified:
cfe/branches/release_80/ (props changed)
cfe/branches/release_80/include/clang/Basic/TargetInfo.h
cfe/branches/release_80/test/Sema/inline-asm-validate-x86.c
Propchange: cfe/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 8 01:09:28 2019
@@ -1,4 +1,4 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:351334,351340,351344,351360,351457,351459,351531,351579-351580,352040,352079,352099,352102,352105,352156,352221-352222,352229,352307,352323,352463,352539,352610,352672,352822,353142,353393,353402,353411,353431,353493,353495,353656,353943,353976,354035,354074,354147,354351,354721,354723,354968
+/cfe/trunk:351334,351340,351344,351360,351457,351459,351531,351579-351580,352040,352079,352099,352102,352105,352156,352221-352222,352229,352307,352323,352463,352539,352610,352672,352822,353142,353393,353402,353411,353431,353493,353495,353656,353943,353976,354035,354074,354147,354351,354721,354723,354937,354968
/cfe/trunk/test:170344
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/release_80/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/include/clang/Basic/TargetInfo.h?rev=355673&r1=355672&r2=355673&view=diff
==============================================================================
--- cfe/branches/release_80/include/clang/Basic/TargetInfo.h (original)
+++ cfe/branches/release_80/include/clang/Basic/TargetInfo.h Fri Mar 8 01:09:28 2019
@@ -807,6 +807,7 @@ public:
struct {
int Min;
int Max;
+ bool isConstrained;
} ImmRange;
llvm::SmallSet<int, 4> ImmSet;
@@ -817,6 +818,7 @@ public:
: Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
Name(Name.str()) {
ImmRange.Min = ImmRange.Max = 0;
+ ImmRange.isConstrained = false;
}
const std::string &getConstraintStr() const { return ConstraintStr; }
@@ -845,8 +847,9 @@ public:
return (Flags & CI_ImmediateConstant) != 0;
}
bool isValidAsmImmediate(const llvm::APInt &Value) const {
- return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) ||
- ImmSet.count(Value.getZExtValue()) != 0;
+ if (!ImmSet.empty())
+ return ImmSet.count(Value.getZExtValue()) != 0;
+ return !ImmRange.isConstrained || (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
}
void setIsReadWrite() { Flags |= CI_ReadWrite; }
@@ -858,6 +861,7 @@ public:
Flags |= CI_ImmediateConstant;
ImmRange.Min = Min;
ImmRange.Max = Max;
+ ImmRange.isConstrained = true;
}
void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
Flags |= CI_ImmediateConstant;
@@ -870,8 +874,6 @@ public:
}
void setRequiresImmediate() {
Flags |= CI_ImmediateConstant;
- ImmRange.Min = INT_MIN;
- ImmRange.Max = INT_MAX;
}
/// Indicate that this is an input operand that is tied to
Modified: cfe/branches/release_80/test/Sema/inline-asm-validate-x86.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/test/Sema/inline-asm-validate-x86.c?rev=355673&r1=355672&r2=355673&view=diff
==============================================================================
--- cfe/branches/release_80/test/Sema/inline-asm-validate-x86.c (original)
+++ cfe/branches/release_80/test/Sema/inline-asm-validate-x86.c Fri Mar 8 01:09:28 2019
@@ -55,6 +55,7 @@ void K(int i, int j) {
void L(int i, int j) {
static const int Invalid1 = 1;
static const int Invalid2 = 42;
+ static const int Invalid3 = 0;
static const int Valid1 = 0xff;
static const int Valid2 = 0xffff;
static const int Valid3 = 0xffffffff;
@@ -69,6 +70,9 @@ void L(int i, int j) {
: "0"(i), "L"(Invalid2)); // expected-error{{value '42' out of range for constraint 'L'}}
__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"(Valid1)); // expected-no-error
__asm__("xorl %0,%2"
: "=r"(i)
More information about the llvm-branch-commits
mailing list