Skip to content

Commit 93ce8e1

Browse files
authored
Fix Android build failure in InferIntRangeCommon (#96154)
As of today, Android's libcxx is missing C++17's std::function's CTAD added in e1eabcd. This leads to InferIntRangeCommon.cpp to fail to compile. This commit makes the template parameter of std::function in that function explicit, therefore avoiding CTAD. While LLVM/MLIR's requirement is C++17, the rest of the code builds fine so hopefully this is acceptable.
1 parent b608b22 commit 93ce8e1

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using namespace mlir;
3535
/// constants and returns std::nullopt on overflow.
3636
using ConstArithFn =
3737
function_ref<std::optional<APInt>(const APInt &, const APInt &)>;
38+
using ConstArithStdFn =
39+
std::function<std::optional<APInt>(const APInt &, const APInt &)>;
3840

3941
/// Compute op(minLeft, minRight) and op(maxLeft, maxRight) if possible,
4042
/// If either computation overflows, make the result unbounded.
@@ -182,16 +184,16 @@ mlir::intrange::inferAdd(ArrayRef<ConstantIntRanges> argRanges,
182184
OverflowFlags ovfFlags) {
183185
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];
184186

185-
std::function uadd = [=](const APInt &a,
186-
const APInt &b) -> std::optional<APInt> {
187+
ConstArithStdFn uadd = [=](const APInt &a,
188+
const APInt &b) -> std::optional<APInt> {
187189
bool overflowed = false;
188190
APInt result = any(ovfFlags & OverflowFlags::Nuw)
189191
? a.uadd_sat(b)
190192
: a.uadd_ov(b, overflowed);
191193
return overflowed ? std::optional<APInt>() : result;
192194
};
193-
std::function sadd = [=](const APInt &a,
194-
const APInt &b) -> std::optional<APInt> {
195+
ConstArithStdFn sadd = [=](const APInt &a,
196+
const APInt &b) -> std::optional<APInt> {
195197
bool overflowed = false;
196198
APInt result = any(ovfFlags & OverflowFlags::Nsw)
197199
? a.sadd_sat(b)
@@ -215,16 +217,16 @@ mlir::intrange::inferSub(ArrayRef<ConstantIntRanges> argRanges,
215217
OverflowFlags ovfFlags) {
216218
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];
217219

218-
std::function usub = [=](const APInt &a,
219-
const APInt &b) -> std::optional<APInt> {
220+
ConstArithStdFn usub = [=](const APInt &a,
221+
const APInt &b) -> std::optional<APInt> {
220222
bool overflowed = false;
221223
APInt result = any(ovfFlags & OverflowFlags::Nuw)
222224
? a.usub_sat(b)
223225
: a.usub_ov(b, overflowed);
224226
return overflowed ? std::optional<APInt>() : result;
225227
};
226-
std::function ssub = [=](const APInt &a,
227-
const APInt &b) -> std::optional<APInt> {
228+
ConstArithStdFn ssub = [=](const APInt &a,
229+
const APInt &b) -> std::optional<APInt> {
228230
bool overflowed = false;
229231
APInt result = any(ovfFlags & OverflowFlags::Nsw)
230232
? a.ssub_sat(b)
@@ -247,16 +249,16 @@ mlir::intrange::inferMul(ArrayRef<ConstantIntRanges> argRanges,
247249
OverflowFlags ovfFlags) {
248250
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];
249251

250-
std::function umul = [=](const APInt &a,
251-
const APInt &b) -> std::optional<APInt> {
252+
ConstArithStdFn umul = [=](const APInt &a,
253+
const APInt &b) -> std::optional<APInt> {
252254
bool overflowed = false;
253255
APInt result = any(ovfFlags & OverflowFlags::Nuw)
254256
? a.umul_sat(b)
255257
: a.umul_ov(b, overflowed);
256258
return overflowed ? std::optional<APInt>() : result;
257259
};
258-
std::function smul = [=](const APInt &a,
259-
const APInt &b) -> std::optional<APInt> {
260+
ConstArithStdFn smul = [=](const APInt &a,
261+
const APInt &b) -> std::optional<APInt> {
260262
bool overflowed = false;
261263
APInt result = any(ovfFlags & OverflowFlags::Nsw)
262264
? a.smul_sat(b)
@@ -565,16 +567,16 @@ mlir::intrange::inferShl(ArrayRef<ConstantIntRanges> argRanges,
565567

566568
// The signed/unsigned overflow behavior of shl by `rhs` matches a mul with
567569
// 2^rhs.
568-
std::function ushl = [=](const APInt &l,
569-
const APInt &r) -> std::optional<APInt> {
570+
ConstArithStdFn ushl = [=](const APInt &l,
571+
const APInt &r) -> std::optional<APInt> {
570572
bool overflowed = false;
571573
APInt result = any(ovfFlags & OverflowFlags::Nuw)
572574
? l.ushl_sat(r)
573575
: l.ushl_ov(r, overflowed);
574576
return overflowed ? std::optional<APInt>() : result;
575577
};
576-
std::function sshl = [=](const APInt &l,
577-
const APInt &r) -> std::optional<APInt> {
578+
ConstArithStdFn sshl = [=](const APInt &l,
579+
const APInt &r) -> std::optional<APInt> {
578580
bool overflowed = false;
579581
APInt result = any(ovfFlags & OverflowFlags::Nsw)
580582
? l.sshl_sat(r)

0 commit comments

Comments
 (0)