Skip to content

Commit 843f122

Browse files
authored
Triple: Add isMacOSVersionGE Triple utils (#167450)
The existing function is LT but most of the uses are better expressed as GE
1 parent 1eaff19 commit 843f122

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,29 @@ class Triple {
554554
return getOSVersion() < VersionTuple(Major, Minor, Micro);
555555
}
556556

557+
bool isOSVersionGE(unsigned Major, unsigned Minor = 0,
558+
unsigned Micro = 0) const {
559+
return !isOSVersionLT(Major, Minor, Micro);
560+
}
561+
557562
bool isOSVersionLT(const Triple &Other) const {
558563
return getOSVersion() < Other.getOSVersion();
559564
}
560565

566+
bool isOSVersionGE(const Triple &Other) const {
567+
return getOSVersion() >= Other.getOSVersion();
568+
}
569+
561570
/// Comparison function for checking OS X version compatibility, which handles
562571
/// supporting skewed version numbering schemes used by the "darwin" triples.
563572
LLVM_ABI bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
564573
unsigned Micro = 0) const;
565574

575+
bool isMacOSXVersionGE(unsigned Major, unsigned Minor = 0,
576+
unsigned Micro = 0) const {
577+
return !isMacOSXVersionLT(Major, Minor, Micro);
578+
}
579+
566580
/// Is this a Mac OS X triple. For legacy reasons, we support both "darwin"
567581
/// and "osx" as OS X triples.
568582
bool isMacOSX() const {

llvm/unittests/TargetParser/TripleTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,17 @@ TEST(TripleTest, isMacOSVersionLT) {
26302630
EXPECT_FALSE(T.isMacOSXVersionLT(10, 15, 0));
26312631
}
26322632

2633+
TEST(TripleTest, isMacOSVersionGE) {
2634+
Triple T = Triple("x86_64-apple-macos11");
2635+
EXPECT_FALSE(T.isMacOSXVersionGE(11, 1, 0));
2636+
EXPECT_TRUE(T.isMacOSXVersionGE(10, 15, 0));
2637+
2638+
T = Triple("x86_64-apple-darwin20");
2639+
EXPECT_FALSE(T.isMacOSXVersionGE(11, 1, 0));
2640+
EXPECT_TRUE(T.isMacOSXVersionGE(11, 0, 0));
2641+
EXPECT_TRUE(T.isMacOSXVersionGE(10, 15, 0));
2642+
}
2643+
26332644
TEST(TripleTest, CanonicalizeOSVersion) {
26342645
EXPECT_EQ(VersionTuple(10, 15, 4),
26352646
Triple::getCanonicalVersionForOS(Triple::MacOSX,

0 commit comments

Comments
 (0)