Skip to content

Commit 1100ab8

Browse files
committed
[embedded] In -assert-config Debug, print errors in assertions, preconditions, fatalErrors
1 parent a0c1027 commit 1100ab8

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

lib/SIL/IR/Linker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F,
102102
bool setToSerializable) {
103103
SILLinkage linkage = F->getLinkage();
104104
assert((!setToSerializable || F->hasValidLinkageForFragileRef() ||
105-
hasSharedVisibility(linkage)) &&
105+
hasSharedVisibility(linkage) || Mod.getOptions().EmbeddedSwift) &&
106106
"called function has wrong linkage for serialized function");
107107

108108
if (!F->isExternalDeclaration()) {
@@ -422,7 +422,7 @@ void SILLinkerVisitor::visitMetatypeInst(MetatypeInst *MI) {
422422
}
423423

424424
void SILLinkerVisitor::visitGlobalAddrInst(GlobalAddrInst *GAI) {
425-
if (!Mod.getASTContext().LangOpts.hasFeature(Feature::Embedded))
425+
if (!Mod.getOptions().EmbeddedSwift)
426426
return;
427427

428428
SILGlobalVariable *G = GAI->getReferencedGlobal();
@@ -448,7 +448,7 @@ void SILLinkerVisitor::process() {
448448
Fn->setSerialized(IsSerialized_t::IsNotSerialized);
449449
}
450450

451-
if (Fn->getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded) &&
451+
if (Fn->getModule().getOptions().EmbeddedSwift &&
452452
Fn->getModule().getASTContext().LangOpts.DebuggerSupport) {
453453
// LLDB requires that functions with bodies are not external.
454454
Fn->setLinkage(stripExternalFromLinkage(Fn->getLinkage()));

lib/SIL/IR/Linker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, void> {
146146
/// Is the current mode link all? Link all implies we should try and link
147147
/// everything, not just transparent/shared functions.
148148
bool isLinkAll() const {
149-
return Mode == LinkingMode::LinkAll ||
150-
Mod.getASTContext().LangOpts.hasFeature(Feature::Embedded);
149+
return Mode == LinkingMode::LinkAll || Mod.getOptions().EmbeddedSwift;
151150
}
152151

153152
void linkInVTable(ClassDecl *D);

stdlib/public/core/AssertCommon.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ internal func _assertionFailure(
110110
}
111111
}
112112
}
113+
#else
114+
_embeddedReportFatalErrorInFile(prefix: prefix, message: message, file: file,
115+
line: line)
113116
#endif
114117
Builtin.int_trap()
115118
}
@@ -183,6 +186,8 @@ internal func _assertionFailure(
183186
_ prefix: StaticString, _ message: StaticString,
184187
flags: UInt32
185188
) -> Never {
189+
_embeddedReportFatalError(prefix: prefix, message: message)
190+
186191
Builtin.int_trap()
187192
}
188193
#endif

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,19 @@ func arc4random_buf(buf: UnsafeMutableRawPointer, nbytes: Int)
338338
public func swift_stdlib_random(_ buf: UnsafeMutableRawPointer, _ nbytes: Int) {
339339
arc4random_buf(buf: buf, nbytes: nbytes)
340340
}
341+
342+
@usableFromInline
343+
func _embeddedReportFatalError(prefix: StaticString, message: StaticString) {
344+
print(prefix, terminator: "")
345+
if message.utf8CodeUnitCount > 0 { print(": ", terminator: "") }
346+
print(message)
347+
}
348+
349+
@usableFromInline
350+
func _embeddedReportFatalErrorInFile(prefix: StaticString, message: StaticString, file: StaticString, line: UInt) {
351+
print(file, terminator: ":")
352+
print(line, terminator: ": ")
353+
print(prefix, terminator: "")
354+
if message.utf8CodeUnitCount > 0 { print(": ", terminator: "") }
355+
print(message)
356+
}

0 commit comments

Comments
 (0)