Skip to content

Commit 4b28ffe

Browse files
committed
enforce block sizes to be multiples
Created using spr 1.3.4
1 parent 1d54ac1 commit 4b28ffe

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,25 @@ bool HeatmapBlockSpecParser::parse(cl::Option &O, StringRef ArgName,
124124

125125
SmallVector<StringRef> Sizes;
126126
Arg.split(Sizes, ',');
127+
unsigned PreviousSize = 0;
127128
for (StringRef Size : Sizes) {
129+
StringRef OrigSize = Size;
128130
unsigned &SizeVal = Val.emplace_back(0);
129-
if (!Size.consumeInteger(10, SizeVal)) {
130-
if (std::optional<unsigned> ShiftAmt = parseSuffix(Size)) {
131-
SizeVal <<= *ShiftAmt;
132-
continue;
133-
}
131+
if (Size.consumeInteger(10, SizeVal)) {
132+
O.error("'" + OrigSize + "' value can't be parsed as an integer");
133+
return true;
134134
}
135-
O.error("'" + Size + "' value invalid for size argument");
136-
return true;
137-
}
138-
if (!llvm::is_sorted(Val)) {
139-
O.error("'" + Arg + "' value must be sorted");
140-
return true;
135+
if (std::optional<unsigned> ShiftAmt = parseSuffix(Size)) {
136+
SizeVal <<= *ShiftAmt;
137+
} else {
138+
O.error("'" + Size + "' value can't be parsed as a suffix");
139+
return true;
140+
}
141+
if (SizeVal <= PreviousSize || (PreviousSize && SizeVal % PreviousSize)) {
142+
O.error("'" + OrigSize + "' must be a multiple of previous value");
143+
return true;
144+
}
145+
PreviousSize = SizeVal;
141146
}
142147
return false;
143148
}

0 commit comments

Comments
 (0)