Skip to content

Commit f9fe603

Browse files
committed
[TextAPI] Support more constructors for PackedVersions
TBD files now record minimum deplyoment versions and tapi interfaces with apple system linker by a packed version encoding. Support mapping between that and `VersionTuple`s.
1 parent e9ed1aa commit f9fe603

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

llvm/include/llvm/TextAPI/PackedVersion.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_TEXTAPI_PACKEDVERSION_H
1414
#define LLVM_TEXTAPI_PACKEDVERSION_H
1515

16+
#include "llvm/Support/VersionTuple.h"
1617
#include <cstdint>
1718
#include <string>
1819
#include <utility>
@@ -28,10 +29,19 @@ class PackedVersion {
2829

2930
public:
3031
constexpr PackedVersion() = default;
31-
explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
32+
constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
3233
PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
3334
: Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
3435

36+
PackedVersion(VersionTuple VT) {
37+
unsigned Minor = 0, Subminor = 0;
38+
if (auto VTMinor = VT.getMinor())
39+
Minor = *VTMinor;
40+
if (auto VTSub = VT.getSubminor())
41+
Subminor = *VTSub;
42+
*this = PackedVersion(VT.getMajor(), Minor, Subminor);
43+
}
44+
3545
bool empty() const { return Version == 0; }
3646

3747
/// Retrieve the major version number.

llvm/lib/TextAPI/PackedVersion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool PackedVersion::parse32(StringRef Str) {
2828
SmallVector<StringRef, 3> Parts;
2929
SplitString(Str, Parts, ".");
3030

31-
if (Parts.size() > 3)
31+
if (Parts.size() > 3 || Parts.empty())
3232
return false;
3333

3434
unsigned long long Num;
@@ -63,7 +63,7 @@ std::pair<bool, bool> PackedVersion::parse64(StringRef Str) {
6363
SmallVector<StringRef, 5> Parts;
6464
SplitString(Str, Parts, ".");
6565

66-
if (Parts.size() > 5)
66+
if (Parts.size() > 5 || Parts.empty())
6767
return std::make_pair(false, Truncated);
6868

6969
unsigned long long Num;

llvm/unittests/TextAPI/TextStubV5Tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,18 @@ TEST(TBDv5, ReadFile) {
197197
Target(AK_arm64, PLATFORM_MACOS, VersionTuple(11, 0, 0)),
198198
Target(AK_arm64, PLATFORM_MACCATALYST, VersionTuple(14, 0)),
199199
};
200+
std::set<Target> FileTargets{File->targets().begin(), File->targets().end()};
200201
EXPECT_EQ(mapToPlatformSet(AllTargets), File->getPlatforms());
201202
EXPECT_EQ(mapToArchitectureSet(AllTargets), File->getArchitectures());
203+
EXPECT_EQ(FileTargets.size(), AllTargets.size());
204+
for (const auto &Targ : AllTargets) {
205+
auto FileTarg = FileTargets.find(Targ);
206+
EXPECT_FALSE(FileTarg == FileTargets.end());
207+
EXPECT_EQ(*FileTarg, Targ);
208+
PackedVersion MD = Targ.MinDeployment;
209+
PackedVersion FileMD = FileTarg->MinDeployment;
210+
EXPECT_EQ(MD, FileMD);
211+
}
202212

203213
EXPECT_EQ(PackedVersion(1, 2, 0), File->getCurrentVersion());
204214
EXPECT_EQ(PackedVersion(1, 1, 0), File->getCompatibilityVersion());

0 commit comments

Comments
 (0)