Skip to content

Commit d1023c8

Browse files
fix out-of-bounds accesses; make LIT CHECK's of the test case stable
1 parent 07a10a2 commit d1023c8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,
7676
const SPIRV::SymbolicOperand *EnumValueInCategory =
7777
SPIRV::lookupSymbolicOperandByCategory(Category);
7878

79+
auto TableEnd = ArrayRef(SPIRV::SymbolicOperands).end();
7980
while (EnumValueInCategory && EnumValueInCategory->Category == Category) {
8081
if ((EnumValueInCategory->Value != 0) &&
8182
(Value & EnumValueInCategory->Value)) {
8283
Name += Separator + EnumValueInCategory->Mnemonic.str();
8384
Separator = "|";
8485
}
85-
++EnumValueInCategory;
86+
if (++EnumValueInCategory == TableEnd)
87+
break;
8688
}
8789

8890
return Name;
@@ -123,8 +125,7 @@ getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,
123125
Capability->Value == Value) {
124126
Capabilities.push_back(
125127
static_cast<SPIRV::Capability::Capability>(Capability->ReqCapability));
126-
++Capability;
127-
if (Capability == TableEnd)
128+
if (++Capability == TableEnd)
128129
break;
129130
}
130131

@@ -138,16 +139,15 @@ getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension) {
138139
Extension, SPIRV::OperandCategory::CapabilityOperand);
139140

140141
CapabilityList Capabilities;
142+
auto TableEnd = ArrayRef(SPIRV::ExtensionEntries).end();
141143
while (Entry &&
142144
Entry->Category == SPIRV::OperandCategory::CapabilityOperand) {
143145
// Some capabilities' codes might go not in order.
144-
if (Entry->ReqExtension != Extension) {
145-
++Entry;
146-
continue;
147-
}
148-
Capabilities.push_back(
149-
static_cast<SPIRV::Capability::Capability>(Entry->Value));
150-
++Entry;
146+
if (Entry->ReqExtension == Extension)
147+
Capabilities.push_back(
148+
static_cast<SPIRV::Capability::Capability>(Entry->Value));
149+
if (++Entry == TableEnd)
150+
break;
151151
}
152152

153153
return Capabilities;
@@ -160,11 +160,13 @@ getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,
160160
SPIRV::lookupExtensionByCategoryAndValue(Category, Value);
161161

162162
ExtensionList Extensions;
163+
auto TableEnd = ArrayRef(SPIRV::ExtensionEntries).end();
163164
while (Extension && Extension->Category == Category &&
164165
Extension->Value == Value) {
165166
Extensions.push_back(
166167
static_cast<SPIRV::Extension::Extension>(Extension->ReqExtension));
167-
++Extension;
168+
if (++Extension == TableEnd)
169+
break;
168170
}
169171

170172
return Extensions;

llvm/test/CodeGen/SPIRV/transcoding/spirv-event-null.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ declare dso_local spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyjPU
7171
; CHECK: %[[#BarArg2:]] = OpFunctionParameter %[[#TyPtrSV4_CW]]
7272
; CHECK: %[[#EventVarBar:]] = OpVariable %[[#TyStructPtr]] Function
7373
; CHECK: %[[#EventVarBarCasted2:]] = OpBitcast %[[#TyEventPtr]] %[[#EventVarBar]]
74-
; CHECK: %[[#BarArg2Casted:]] = OpBitcast %[[#TyPtrV4_CW]] %[[#BarArg2]]
75-
; CHECK: %[[#SrcBar:]] = OpInBoundsPtrAccessChain %[[#TyPtrV4_CW]] %[[#BarArg2Casted]] %[[#]]
76-
; CHECK: %[[#ResBar:]] = OpGroupAsyncCopy %[[#TyEvent]] %[[#]] %[[#BarArg1]] %[[#SrcBar]] %[[#]] %[[#]] %[[#ConstEvent]]
74+
; CHECK: %[[#ResBar:]] = OpGroupAsyncCopy %[[#TyEvent]] %[[#]] %[[#BarArg1]] %[[#]] %[[#]] %[[#]] %[[#ConstEvent]]
7775
; CHECK: %[[#EventVarBarCasted:]] = OpBitcast %[[#TyEventPtr]] %[[#EventVarBar]]
7876
; CHECK: OpStore %[[#EventVarBarCasted]] %[[#ResBar]]
7977
; CHECK: %[[#EventVarBarGen:]] = OpPtrCastToGeneric %[[#TyEventPtrGen]] %[[#EventVarBarCasted2]]

0 commit comments

Comments
 (0)