@@ -100,24 +100,23 @@ getAllMovedPlatformVersions(Decl *D) {
100100 return Results;
101101}
102102
103- static StringRef getLinkerPlatformName (uint8_t Id) {
103+ static StringRef getLinkerPlatformName (LinkerPlatformId Id) {
104104 switch (Id) {
105- #define LD_PLATFORM (Name, Id ) case Id : return #Name;
105+ #define LD_PLATFORM (Name, Id ) case LinkerPlatformId::Name : return #Name;
106106#include " ldPlatformKinds.def"
107- default :
108- llvm_unreachable (" unrecognized platform id" );
109107 }
108+ llvm_unreachable (" unrecognized platform id" );
110109}
111110
112- static std::optional<uint8_t > getLinkerPlatformId (StringRef Platform) {
113- return llvm::StringSwitch<std::optional<uint8_t >>(Platform)
114- #define LD_PLATFORM (Name, Id ) .Case(#Name, Id )
111+ static std::optional<LinkerPlatformId > getLinkerPlatformId (StringRef Platform) {
112+ return llvm::StringSwitch<std::optional<LinkerPlatformId >>(Platform)
113+ #define LD_PLATFORM (Name, Id ) .Case(#Name, LinkerPlatformId::Name )
115114#include " ldPlatformKinds.def"
116115 .Default (std::nullopt );
117116}
118117
119118StringRef InstallNameStore::getInstallName (LinkerPlatformId Id) const {
120- auto It = PlatformInstallName.find (( uint8_t ) Id);
119+ auto It = PlatformInstallName.find (Id);
121120 if (It == PlatformInstallName.end ())
122121 return InstallName;
123122 else
@@ -129,8 +128,9 @@ static std::string getScalaNodeText(Node *N) {
129128 return cast<ScalarNode>(N)->getValue (Buffer).str ();
130129}
131130
132- static std::set<int8_t > getSequenceNodePlatformList (ASTContext &Ctx, Node *N) {
133- std::set<int8_t > Results;
131+ static std::set<LinkerPlatformId> getSequenceNodePlatformList (ASTContext &Ctx,
132+ Node *N) {
133+ std::set<LinkerPlatformId> Results;
134134 for (auto &E: *cast<SequenceNode>(N)) {
135135 auto Platform = getScalaNodeText (&E);
136136 auto Id = getLinkerPlatformId (Platform);
@@ -158,7 +158,7 @@ parseEntry(ASTContext &Ctx,
158158 auto *MN = cast<MappingNode>(&*It);
159159 std::string ModuleName;
160160 std::string InstallName;
161- std::optional<std::set<int8_t >> Platforms;
161+ std::optional<std::set<LinkerPlatformId >> Platforms;
162162 for (auto &Pair: *MN) {
163163 auto Key = getScalaNodeText (Pair.getKey ());
164164 auto * Value = Pair.getValue ();
@@ -233,7 +233,12 @@ TBDGenVisitor::parsePreviousModuleInstallNameMap() {
233233}
234234
235235static LinkerPlatformId
236- getLinkerPlatformId (OriginallyDefinedInAttr::ActiveVersion Ver) {
236+ getLinkerPlatformId (OriginallyDefinedInAttr::ActiveVersion Ver,
237+ ASTContext &Ctx) {
238+ auto target =
239+ Ver.ForTargetVariant ? Ctx.LangOpts .TargetVariant : Ctx.LangOpts .Target ;
240+ bool isSimulator = target ? target->isSimulatorEnvironment () : false ;
241+
237242 switch (Ver.Platform ) {
238243 case swift::PlatformKind::none:
239244 llvm_unreachable (" cannot find platform kind" );
@@ -243,16 +248,16 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
243248 llvm_unreachable (" not used for this platform" );
244249 case swift::PlatformKind::iOS:
245250 case swift::PlatformKind::iOSApplicationExtension:
246- return Ver.IsSimulator ? LinkerPlatformId::iOS_sim:
247- LinkerPlatformId::iOS;
251+ if (target && target->isMacCatalystEnvironment ())
252+ return LinkerPlatformId::macCatalyst;
253+ return isSimulator ? LinkerPlatformId::iOS_sim : LinkerPlatformId::iOS;
248254 case swift::PlatformKind::tvOS:
249255 case swift::PlatformKind::tvOSApplicationExtension:
250- return Ver.IsSimulator ? LinkerPlatformId::tvOS_sim:
251- LinkerPlatformId::tvOS;
256+ return isSimulator ? LinkerPlatformId::tvOS_sim : LinkerPlatformId::tvOS;
252257 case swift::PlatformKind::watchOS:
253258 case swift::PlatformKind::watchOSApplicationExtension:
254- return Ver. IsSimulator ? LinkerPlatformId::watchOS_sim:
255- LinkerPlatformId::watchOS;
259+ return isSimulator ? LinkerPlatformId::watchOS_sim
260+ : LinkerPlatformId::watchOS;
256261 case swift::PlatformKind::macOS:
257262 case swift::PlatformKind::macOSApplicationExtension:
258263 return LinkerPlatformId::macOS;
@@ -264,8 +269,9 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
264269}
265270
266271static StringRef
267- getLinkerPlatformName (OriginallyDefinedInAttr::ActiveVersion Ver) {
268- return getLinkerPlatformName ((uint8_t )getLinkerPlatformId (Ver));
272+ getLinkerPlatformName (OriginallyDefinedInAttr::ActiveVersion Ver,
273+ ASTContext &Ctx) {
274+ return getLinkerPlatformName (getLinkerPlatformId (Ver, Ctx));
269275}
270276
271277// / Find the most relevant introducing version of the decl stack we have visited
@@ -313,17 +319,17 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
313319 // so we don't need the linker directives.
314320 if (*IntroVer >= Ver.Version )
315321 continue ;
316- auto PlatformNumber = getLinkerPlatformId (Ver);
322+ auto PlatformNumber = getLinkerPlatformId (Ver, Ctx );
317323 auto It = previousInstallNameMap->find (Ver.ModuleName .str ());
318324 if (It == previousInstallNameMap->end ()) {
319325 Ctx.Diags .diagnose (SourceLoc (), diag::cannot_find_install_name,
320- Ver.ModuleName , getLinkerPlatformName (Ver));
326+ Ver.ModuleName , getLinkerPlatformName (Ver, Ctx ));
321327 continue ;
322328 }
323329 auto InstallName = It->second .getInstallName (PlatformNumber);
324330 if (InstallName.empty ()) {
325331 Ctx.Diags .diagnose (SourceLoc (), diag::cannot_find_install_name,
326- Ver.ModuleName , getLinkerPlatformName (Ver));
332+ Ver.ModuleName , getLinkerPlatformName (Ver, Ctx ));
327333 continue ;
328334 }
329335 llvm::SmallString<64 > Buffer;
@@ -333,7 +339,7 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
333339 OS << " $ld$previous$" ;
334340 OS << InstallName << " $" ;
335341 OS << ComptibleVersion << " $" ;
336- OS << std::to_string (( uint8_t ) PlatformNumber) << " $" ;
342+ OS << std::to_string (static_cast < uint8_t >( PlatformNumber) ) << " $" ;
337343 static auto getMinor = [](std::optional<unsigned > Minor) {
338344 return Minor.has_value () ? *Minor : 0 ;
339345 };
0 commit comments