File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,9 @@ class [[nodiscard]] ConstantRange {
277
277
// / Return true if all values in this range are non-negative.
278
278
bool isAllNonNegative () const ;
279
279
280
+ // / Return true if all values in this range are positive.
281
+ bool isAllPositive () const ;
282
+
280
283
// / Return the largest unsigned value contained in the ConstantRange.
281
284
APInt getUnsignedMax () const ;
282
285
Original file line number Diff line number Diff line change @@ -440,6 +440,16 @@ bool ConstantRange::isAllNonNegative() const {
440
440
return !isSignWrappedSet () && Lower.isNonNegative ();
441
441
}
442
442
443
+ bool ConstantRange::isAllPositive () const {
444
+ // Empty set is all positive, full set is not.
445
+ if (isEmptySet ())
446
+ return true ;
447
+ if (isFullSet ())
448
+ return false ;
449
+
450
+ return !isSignWrappedSet () && Lower.isStrictlyPositive ();
451
+ }
452
+
443
453
APInt ConstantRange::getUnsignedMax () const {
444
454
if (isFullSet () || isUpperWrapped ())
445
455
return APInt::getMaxValue (getBitWidth ());
Original file line number Diff line number Diff line change @@ -2398,23 +2398,31 @@ TEST_F(ConstantRangeTest, Negative) {
2398
2398
// they are also covered by the exhaustive test below.
2399
2399
EXPECT_TRUE (Empty.isAllNegative ());
2400
2400
EXPECT_TRUE (Empty.isAllNonNegative ());
2401
+ EXPECT_TRUE (Empty.isAllPositive ());
2401
2402
EXPECT_FALSE (Full.isAllNegative ());
2402
2403
EXPECT_FALSE (Full.isAllNonNegative ());
2404
+ EXPECT_FALSE (Full.isAllPositive ());
2403
2405
2404
2406
EnumerateInterestingConstantRanges ([](const ConstantRange &CR) {
2405
2407
bool AllNegative = true ;
2406
2408
bool AllNonNegative = true ;
2409
+ bool AllPositive = true ;
2407
2410
ForeachNumInConstantRange (CR, [&](const APInt &N) {
2408
2411
if (!N.isNegative ())
2409
2412
AllNegative = false ;
2410
2413
if (!N.isNonNegative ())
2411
2414
AllNonNegative = false ;
2415
+ if (!N.isStrictlyPositive ())
2416
+ AllPositive = false ;
2412
2417
});
2413
- assert ((CR.isEmptySet () || !AllNegative || !AllNonNegative) &&
2414
- " Only empty set can be both all negative and all non-negative" );
2418
+ assert (
2419
+ (CR.isEmptySet () || !AllNegative || !AllNonNegative || !AllPositive) &&
2420
+ " Only empty set can be all negative, all non-negative, and all "
2421
+ " positive" );
2415
2422
2416
2423
EXPECT_EQ (AllNegative, CR.isAllNegative ());
2417
2424
EXPECT_EQ (AllNonNegative, CR.isAllNonNegative ());
2425
+ EXPECT_EQ (AllPositive, CR.isAllPositive ());
2418
2426
});
2419
2427
}
2420
2428
You can’t perform that action at this time.
0 commit comments