Skip to content

Commit eb1052c

Browse files
authored
Merge pull request #3107 from swiftwasm/release/5.4
[pull] swiftwasm-release/5.4 from release/5.4
2 parents 76fca32 + f370868 commit eb1052c

File tree

16 files changed

+186
-33
lines changed

16 files changed

+186
-33
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,7 @@ WARNING(implicit_bridging_header_imported_from_module,none,
8080
"is deprecated and will be removed in a later version of Swift",
8181
(StringRef, Identifier))
8282

83+
ERROR(module_map_not_found, none, "module map file '%0' not found", (StringRef))
84+
8385
#define UNDEFINE_DIAGNOSTIC_MACROS
8486
#include "DefineDiagnosticMacros.h"

lib/ClangImporter/ClangImporter.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,38 @@ ClangImporter::createClangInvocation(ClangImporter *importer,
10301030
&tempDiagClient,
10311031
/*owned*/false);
10321032

1033-
return clang::createInvocationFromCommandLine(invocationArgs, tempClangDiags,
1034-
nullptr, false, CC1Args);
1033+
auto CI = clang::createInvocationFromCommandLine(
1034+
invocationArgs, tempClangDiags, nullptr, false, CC1Args);
1035+
1036+
if (!CI) {
1037+
return CI;
1038+
}
1039+
1040+
// FIXME: clang fails to generate a module if there is a `-fmodule-map-file`
1041+
// argument pointing to a missing file.
1042+
// Such missing module files occur frequently in SourceKit. If the files are
1043+
// missing, SourceKit fails to build SwiftShims (which wouldn't have required
1044+
// the missing module file), thus fails to load the stdlib and hence looses
1045+
// all semantic functionality.
1046+
// To work around this issue, drop all `-fmodule-map-file` arguments pointing
1047+
// to missing files and report the error that clang would throw manually.
1048+
// rdar://77516546 is tracking that the clang importer should be more
1049+
// resilient and provide a module even if there were building it.
1050+
auto VFS = clang::createVFSFromCompilerInvocation(
1051+
*CI, *tempClangDiags,
1052+
importer->Impl.SwiftContext.SourceMgr.getFileSystem());
1053+
std::vector<std::string> FilteredModuleMapFiles;
1054+
for (auto ModuleMapFile : CI->getFrontendOpts().ModuleMapFiles) {
1055+
if (VFS->exists(ModuleMapFile)) {
1056+
FilteredModuleMapFiles.push_back(ModuleMapFile);
1057+
} else {
1058+
importer->Impl.SwiftContext.Diags.diagnose(
1059+
SourceLoc(), diag::module_map_not_found, ModuleMapFile);
1060+
}
1061+
}
1062+
CI->getFrontendOpts().ModuleMapFiles = FilteredModuleMapFiles;
1063+
1064+
return CI;
10351065
}
10361066

10371067
std::unique_ptr<ClangImporter>

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,8 @@ bool IRGenModule::useDllStorage() { return ::useDllStorage(Triple); }
16321632

16331633
bool IRGenModule::shouldPrespecializeGenericMetadata() {
16341634
auto canPrespecializeTarget =
1635-
(Triple.isOSDarwin() || Triple.isTvOS() || Triple.isOSLinux());
1635+
(Triple.isOSDarwin() || Triple.isTvOS() ||
1636+
(Triple.isOSLinux() && !(Triple.isARM() && Triple.isArch32Bit())));
16361637
if (canPrespecializeTarget && isStandardLibrary()) {
16371638
return true;
16381639
}

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6622,8 +6622,10 @@ BraceStmt *Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
66226622
return nullptr;
66236623

66246624
BraceStmt *BS = Body.get();
6625+
// Reset the single expression body status.
6626+
AFD->setHasSingleExpressionBody(false);
66256627
AFD->setBodyParsed(BS);
6626-
6628+
66276629
if (Parser::shouldReturnSingleExpressionElement(BS->getElements())) {
66286630
auto Element = BS->getLastElement();
66296631
if (auto *stmt = Element.dyn_cast<Stmt *>()) {

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,21 +1213,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
12131213
DebugVars[ArgNo] = VarInfo->Name;
12141214
}
12151215
}
1216-
1217-
// Regular locations are allowed on all instructions.
1218-
if (LocKind == SILLocation::RegularKind)
1219-
return;
1220-
1221-
if (LocKind == SILLocation::ReturnKind ||
1222-
LocKind == SILLocation::ImplicitReturnKind)
1223-
require(InstKind == SILInstructionKind::BranchInst ||
1224-
InstKind == SILInstructionKind::ReturnInst ||
1225-
InstKind == SILInstructionKind::UnreachableInst,
1226-
"return locations are only allowed on branch and return instructions");
1227-
1228-
if (LocKind == SILLocation::ArtificialUnreachableKind)
1229-
require(InstKind == SILInstructionKind::UnreachableInst,
1230-
"artificial locations are only allowed on Unreachable instructions");
12311216
}
12321217

12331218
/// Check that the types of this value producer are all legal in the function

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,8 @@ static unsigned getElementCountRec(TypeExpansionContext context,
9393
}
9494

9595
static std::pair<SILType, bool>
96-
computeMemorySILType(MarkUninitializedInst *MemoryInst) {
96+
computeMemorySILType(MarkUninitializedInst *MUI, SILValue Address) {
9797
// Compute the type of the memory object.
98-
auto *MUI = MemoryInst;
99-
SILValue Address = MUI;
100-
if (auto *PBI = Address->getSingleUserOfType<ProjectBoxInst>()) {
101-
Address = PBI;
102-
}
10398
SILType MemorySILType = Address->getType().getObjectType();
10499

105100
// If this is a let variable we're initializing, remember this so we don't
@@ -118,7 +113,13 @@ DIMemoryObjectInfo::DIMemoryObjectInfo(MarkUninitializedInst *MI)
118113
: MemoryInst(MI) {
119114
auto &Module = MI->getModule();
120115

121-
std::tie(MemorySILType, IsLet) = computeMemorySILType(MemoryInst);
116+
SILValue Address = MemoryInst;
117+
if (auto PBI = MemoryInst->getSingleUserOfType<ProjectBoxInst>()) {
118+
IsBox = true;
119+
Address = PBI;
120+
}
121+
122+
std::tie(MemorySILType, IsLet) = computeMemorySILType(MI, Address);
122123

123124
// Compute the number of elements to track in this memory object.
124125
// If this is a 'self' in a delegating initializer, we only track one bit:

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class DIMemoryObjectInfo {
7272
/// non-empty.
7373
bool HasDummyElement = false;
7474

75+
/// True if this object has a single user of type ProjectBoxInst.
76+
bool IsBox = false;
77+
7578
public:
7679
DIMemoryObjectInfo(MarkUninitializedInst *MemoryInst);
7780

@@ -98,10 +101,11 @@ class DIMemoryObjectInfo {
98101
/// instruction. For alloc_box though it returns the project_box associated
99102
/// with the memory info.
100103
SingleValueInstruction *getUninitializedValue() const {
101-
if (auto *mui = dyn_cast<MarkUninitializedInst>(MemoryInst)) {
102-
if (auto *pbi = mui->getSingleUserOfType<ProjectBoxInst>()) {
103-
return pbi;
104-
}
104+
if (IsBox) {
105+
// TODO: consider just storing the ProjectBoxInst in this case.
106+
auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>();
107+
assert(pbi);
108+
return pbi;
105109
}
106110
return MemoryInst;
107111
}

lib/Serialization/Deserialization.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6197,8 +6197,26 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
61976197
// FIXME: We don't actually want to allocate an archetype here; we just
61986198
// want to get an access path within the protocol.
61996199
auto first = cast<AssociatedTypeDecl>(getDecl(*rawIDIter++));
6200-
auto second = getType(*rawIDIter++);
6201-
auto third = cast_or_null<TypeDecl>(getDecl(*rawIDIter++));
6200+
auto secondOrError = getTypeChecked(*rawIDIter++);
6201+
Type second;
6202+
if (secondOrError) {
6203+
second = *secondOrError;
6204+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6205+
second = ErrorType::get(getContext());
6206+
consumeError(secondOrError.takeError());
6207+
} else {
6208+
fatal(secondOrError.takeError());
6209+
}
6210+
auto thirdOrError = getDeclChecked(*rawIDIter++);
6211+
TypeDecl *third;
6212+
if (thirdOrError) {
6213+
third = cast_or_null<TypeDecl>(*thirdOrError);
6214+
} else if (getContext().LangOpts.EnableDeserializationRecovery) {
6215+
third = nullptr;
6216+
consumeError(thirdOrError.takeError());
6217+
} else {
6218+
fatal(thirdOrError.takeError());
6219+
}
62026220
if (third &&
62036221
isa<TypeAliasDecl>(third) &&
62046222
third->getModuleContext() != getAssociatedModule() &&

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char *
7070
SWIFT_READONLY
7171
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
7272
__swift_size_t n) {
73+
#if defined(__APPLE__)
74+
extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t);
75+
#else
7376
extern int memcmp(const void *, const void *, __swift_size_t);
77+
#endif
7478
return memcmp(s1, s2, n);
7579
}
7680

test/Runtime/protocol_conformance_collision.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func firstHashValue(_ x: P) -> Int {
4646
}
4747

4848
let osHasWorkaround: Bool
49-
if #available(macOS 11.3, iOS 14.5, tvOS 14.5, watchOS 7.4, *) {
49+
// These are deliberately not the standard 9999, as we don't want to hit the
50+
// special case where it's always available, and we don't want this check to be
51+
// rewritten in any find/replace operations.
52+
if #available(macOS 9998, iOS 9998, tvOS 9998, watchOS 9998, *) {
5053
osHasWorkaround = true
5154
} else {
5255
osHasWorkaround = false

0 commit comments

Comments
 (0)