Skip to content

Commit 2bfbadc

Browse files
committedOct 25, 2017
[inlineasm] Fix crash when number of matched input constraint operands overflows signed char
In a case when number of output constraint operands that has matched input operands doesn't fit to signed char, TargetLowering::ParseConstraints() can try to access ConstraintOperands (that is std::vector) with negative index. Reviewers: rampitec, arsenm Differential Review: https://reviews.llvm.org/D39125 llvm-svn: 316574
1 parent c537795 commit 2bfbadc

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
 

‎llvm/include/llvm/IR/InlineAsm.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class InlineAsm final : public Value {
101101
/// input constraint is required to match it (e.g. "0"). The value is the
102102
/// constraint number that matches this one (for example, if this is
103103
/// constraint #0 and constraint #4 has the value "0", this will be 4).
104-
signed char MatchingInput = -1;
104+
int MatchingInput = -1;
105105

106106
/// Code - The constraint code, either the register name (in braces) or the
107107
/// constraint letter/number.
@@ -128,7 +128,7 @@ class InlineAsm final : public Value {
128128
/// input constraint is required to match it (e.g. "0"). The value is the
129129
/// constraint number that matches this one (for example, if this is
130130
/// constraint #0 and constraint #4 has the value "0", this will be 4).
131-
signed char MatchingInput = -1;
131+
int MatchingInput = -1;
132132

133133
/// hasMatchingInput - Return true if this is an output constraint that has
134134
/// a matching input constraint.

‎llvm/lib/IR/InlineAsm.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
163163
return true;
164164
// Note that operand #n has a matching input.
165165
scInfo.MatchingInput = ConstraintsSoFar.size();
166+
assert(scInfo.MatchingInput >= 0);
166167
} else {
167168
if (ConstraintsSoFar[N].hasMatchingInput() &&
168169
(size_t)ConstraintsSoFar[N].MatchingInput !=
169170
ConstraintsSoFar.size())
170171
return true;
171172
// Note that operand #n has a matching input.
172173
ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size();
174+
assert(ConstraintsSoFar[N].MatchingInput >= 0);
173175
}
174176
} else if (*I == '|') {
175177
multipleAlternativeIndex++;
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck %s
2+
3+
; CHECK: ;;#ASMSTART
4+
; CHECK-NEXT: s_nop 0
5+
; CHECK-NEXT: ;;#ASMEND
6+
7+
define void @foo(i32* %ptr) {
8+
%tmp = tail call { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } asm "s_nop 0", "=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,=v,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65"(i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2)
9+
%tmp2 = extractvalue { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 } %tmp, 0
10+
store i32 %tmp2, i32* %ptr, align 4
11+
ret void
12+
}

0 commit comments

Comments
 (0)
Please sign in to comment.