[llvm] r347836 - [TextAPI] Switch back to a custom Platform enum.
Juergen Ributzka via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 28 21:56:03 PST 2018
Author: ributzka
Date: Wed Nov 28 21:56:03 2018
New Revision: 347836
URL: http://llvm.org/viewvc/llvm-project?rev=347836&view=rev
Log:
[TextAPI] Switch back to a custom Platform enum.
Moving to PlatformType from BinaryFormat had some UB fallout when handing
unknown platforms or malformed input files.
This should fix the sanitizer bots.
Modified:
llvm/trunk/include/llvm/TextAPI/MachO/InterfaceFile.h
llvm/trunk/lib/TextAPI/MachO/TextStub.cpp
llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp
llvm/trunk/lib/TextAPI/MachO/TextStubCommon.h
llvm/trunk/unittests/TextAPI/TextStubV1Tests.cpp
llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp
Modified: llvm/trunk/include/llvm/TextAPI/MachO/InterfaceFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TextAPI/MachO/InterfaceFile.h?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TextAPI/MachO/InterfaceFile.h (original)
+++ llvm/trunk/include/llvm/TextAPI/MachO/InterfaceFile.h Wed Nov 28 21:56:03 2018
@@ -34,6 +34,16 @@
namespace llvm {
namespace MachO {
+/// Defines the list of MachO platforms.
+enum class PlatformKind : unsigned {
+ unknown,
+ macOS = MachO::PLATFORM_MACOS,
+ iOS = MachO::PLATFORM_IOS,
+ tvOS = MachO::PLATFORM_TVOS,
+ watchOS = MachO::PLATFORM_WATCHOS,
+ bridgeOS = MachO::PLATFORM_BRIDGEOS,
+};
+
/// Defines a list of Objective-C constraints.
enum class ObjCConstraintType : unsigned {
/// No constraint.
@@ -164,10 +174,10 @@ public:
FileType getFileType() const { return FileKind; }
/// Set the platform.
- void setPlatform(PlatformType Platform_) { Platform = Platform_; }
+ void setPlatform(PlatformKind Platform_) { Platform = Platform_; }
/// Get the platform.
- PlatformType getPlatform() const { return Platform; }
+ PlatformKind getPlatform() const { return Platform; }
/// Specify the set of supported architectures by this file.
void setArchitectures(ArchitectureSet Architectures_) {
@@ -406,7 +416,7 @@ private:
std::string Path;
FileType FileKind;
- PlatformType Platform;
+ PlatformKind Platform;
ArchitectureSet Architectures;
std::string InstallName;
PackedVersion CurrentVersion;
Modified: llvm/trunk/lib/TextAPI/MachO/TextStub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/TextStub.cpp?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/TextStub.cpp (original)
+++ llvm/trunk/lib/TextAPI/MachO/TextStub.cpp Wed Nov 28 21:56:03 2018
@@ -515,11 +515,11 @@ template <> struct MappingTraits<const I
std::vector<Architecture> Architectures;
std::vector<UUID> UUIDs;
- PlatformType Platform;
+ PlatformKind Platform{PlatformKind::unknown};
StringRef InstallName;
PackedVersion CurrentVersion;
PackedVersion CompatibilityVersion;
- SwiftVersion SwiftABIVersion;
+ SwiftVersion SwiftABIVersion{0};
ObjCConstraintType ObjCConstraint{ObjCConstraintType::None};
TBDFlags Flags{TBDFlags::None};
StringRef ParentUmbrella;
Modified: llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp (original)
+++ llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp Wed Nov 28 21:56:03 2018
@@ -43,43 +43,44 @@ void ScalarEnumerationTraits<ObjCConstra
IO.enumCase(Constraint, "gc", ObjCConstraintType::GC);
}
-void ScalarTraits<PlatformType>::output(const PlatformType &Value, void *,
+void ScalarTraits<PlatformKind>::output(const PlatformKind &Value, void *,
raw_ostream &OS) {
switch (Value) {
- case PLATFORM_MACOS:
+ default:
+ llvm_unreachable("unexpected platform");
+ break;
+ case PlatformKind::macOS:
OS << "macosx";
break;
- case PLATFORM_IOS:
+ case PlatformKind::iOS:
OS << "ios";
break;
- case PLATFORM_WATCHOS:
+ case PlatformKind::watchOS:
OS << "watchos";
break;
- case PLATFORM_TVOS:
+ case PlatformKind::tvOS:
OS << "tvos";
break;
- case PLATFORM_BRIDGEOS:
+ case PlatformKind::bridgeOS:
OS << "bridgeos";
break;
}
}
-StringRef ScalarTraits<PlatformType>::input(StringRef Scalar, void *,
- PlatformType &Value) {
- int Result = StringSwitch<unsigned>(Scalar)
- .Case("macosx", PLATFORM_MACOS)
- .Case("ios", PLATFORM_IOS)
- .Case("watchos", PLATFORM_WATCHOS)
- .Case("tvos", PLATFORM_TVOS)
- .Case("bridgeos", PLATFORM_BRIDGEOS)
- .Default(0);
+StringRef ScalarTraits<PlatformKind>::input(StringRef Scalar, void *,
+ PlatformKind &Value) {
+ Value = StringSwitch<PlatformKind>(Scalar)
+ .Case("macosx", PlatformKind::macOS)
+ .Case("ios", PlatformKind::iOS)
+ .Case("watchos", PlatformKind::watchOS)
+ .Case("tvos", PlatformKind::tvOS)
+ .Case("bridgeos", PlatformKind::bridgeOS)
+ .Default(PlatformKind::unknown);
- if (!Result)
+ if (Value == PlatformKind::unknown)
return "unknown platform";
-
- Value = static_cast<PlatformType>(Result);
return {};
}
-QuotingType ScalarTraits<PlatformType>::mustQuote(StringRef) {
+QuotingType ScalarTraits<PlatformKind>::mustQuote(StringRef) {
return QuotingType::None;
}
Modified: llvm/trunk/lib/TextAPI/MachO/TextStubCommon.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/TextStubCommon.h?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/TextStubCommon.h (original)
+++ llvm/trunk/lib/TextAPI/MachO/TextStubCommon.h Wed Nov 28 21:56:03 2018
@@ -43,9 +43,9 @@ template <> struct ScalarEnumerationTrai
static void enumeration(IO &, MachO::ObjCConstraintType &);
};
-template <> struct ScalarTraits<MachO::PlatformType> {
- static void output(const MachO::PlatformType &, void *, raw_ostream &);
- static StringRef input(StringRef, void *, MachO::PlatformType &);
+template <> struct ScalarTraits<MachO::PlatformKind> {
+ static void output(const MachO::PlatformKind &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, MachO::PlatformKind &);
static QuotingType mustQuote(StringRef);
};
Modified: llvm/trunk/unittests/TextAPI/TextStubV1Tests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/TextAPI/TextStubV1Tests.cpp?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/unittests/TextAPI/TextStubV1Tests.cpp (original)
+++ llvm/trunk/unittests/TextAPI/TextStubV1Tests.cpp Wed Nov 28 21:56:03 2018
@@ -90,7 +90,7 @@ TEST(TBDv1, ReadFile) {
auto Archs = Architecture::armv7 | Architecture::armv7s |
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
EXPECT_EQ(PackedVersion(2, 3, 4), File->getCurrentVersion());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
@@ -136,7 +136,7 @@ TEST(TBDv1, ReadFile2) {
auto Archs = Architecture::armv7 | Architecture::armv7s |
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
@@ -177,7 +177,7 @@ TEST(TBDv1, WriteFile) {
File.setInstallName("/usr/lib/libfoo.dylib");
File.setFileType(FileType::TBD_V1);
File.setArchitectures(Architecture::i386 | Architecture::x86_64);
- File.setPlatform(PLATFORM_MACOS);
+ File.setPlatform(PlatformKind::macOS);
File.setCurrentVersion(PackedVersion(1, 2, 3));
File.setSwiftABIVersion(5);
File.setObjCConstraint(ObjCConstraintType::Retain_Release);
@@ -213,7 +213,7 @@ TEST(TBDv1, Platform_macOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType());
- EXPECT_EQ(PLATFORM_MACOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::macOS, File->getPlatform());
}
TEST(TBDv1, Platform_iOS) {
@@ -228,7 +228,7 @@ TEST(TBDv1, Platform_iOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
}
TEST(TBDv1, Platform_watchOS) {
@@ -243,7 +243,7 @@ TEST(TBDv1, Platform_watchOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType());
- EXPECT_EQ(PLATFORM_WATCHOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::watchOS, File->getPlatform());
}
TEST(TBDv1, Platform_tvOS) {
@@ -258,7 +258,7 @@ TEST(TBDv1, Platform_tvOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType());
- EXPECT_EQ(PLATFORM_TVOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::tvOS, File->getPlatform());
}
TEST(TBDv1, Platform_bridgeOS) {
@@ -274,7 +274,7 @@ TEST(TBDv1, Platform_bridgeOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V1, File->getFileType());
- EXPECT_EQ(PLATFORM_BRIDGEOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::bridgeOS, File->getPlatform());
}
TEST(TBDv1, Swift_1_0) {
Modified: llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp?rev=347836&r1=347835&r2=347836&view=diff
==============================================================================
--- llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp (original)
+++ llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp Wed Nov 28 21:56:03 2018
@@ -92,7 +92,7 @@ TEST(TBDv2, ReadFile) {
auto Archs = Architecture::armv7 | Architecture::armv7s |
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
EXPECT_EQ(PackedVersion(2, 3, 4), File->getCurrentVersion());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
@@ -160,7 +160,7 @@ TEST(TBDv2, ReadFile2) {
auto Archs = Architecture::armv7 | Architecture::armv7s |
Architecture::armv7k | Architecture::arm64;
EXPECT_EQ(Archs, File->getArchitectures());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());
EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
@@ -200,7 +200,7 @@ TEST(TBDv2, WriteFile) {
File.setInstallName("/usr/lib/libfoo.dylib");
File.setFileType(FileType::TBD_V2);
File.setArchitectures(Architecture::i386 | Architecture::x86_64);
- File.setPlatform(PLATFORM_MACOS);
+ File.setPlatform(PlatformKind::macOS);
File.setCurrentVersion(PackedVersion(1, 2, 3));
File.setTwoLevelNamespace();
File.setApplicationExtensionSafe();
@@ -238,7 +238,7 @@ TEST(TBDv2, Platform_macOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType());
- EXPECT_EQ(PLATFORM_MACOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::macOS, File->getPlatform());
}
TEST(TBDv2, Platform_iOS) {
@@ -253,7 +253,7 @@ TEST(TBDv2, Platform_iOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType());
- EXPECT_EQ(PLATFORM_IOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
}
TEST(TBDv2, Platform_watchOS) {
@@ -268,7 +268,7 @@ TEST(TBDv2, Platform_watchOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType());
- EXPECT_EQ(PLATFORM_WATCHOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::watchOS, File->getPlatform());
}
TEST(TBDv2, Platform_tvOS) {
@@ -283,7 +283,7 @@ TEST(TBDv2, Platform_tvOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType());
- EXPECT_EQ(PLATFORM_TVOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::tvOS, File->getPlatform());
}
TEST(TBDv2, Platform_bridgeOS) {
@@ -299,7 +299,7 @@ TEST(TBDv2, Platform_bridgeOS) {
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V2, File->getFileType());
- EXPECT_EQ(PLATFORM_BRIDGEOS, File->getPlatform());
+ EXPECT_EQ(PlatformKind::bridgeOS, File->getPlatform());
}
TEST(TBDv2, Swift_1_0) {
More information about the llvm-commits
mailing list