@@ -108,6 +108,10 @@ using namespace Lowering;
108108template <typename ... T, typename ... U>
109109static void diagnose (ASTContext &Context, SourceLoc loc, Diag<T...> diag,
110110 U &&... args) {
111+ // The lifetime of StringRef arguments will be extended as necessary by this
112+ // utility. The copy happens in onTentativeDiagnosticFlush at the bottom of
113+ // DiagnosticEngine.cpp, which is called when the destructor of the
114+ // InFlightDiagnostic returned by diagnose runs.
111115 Context.Diags .diagnose (loc, diag, std::forward<U>(args)...);
112116}
113117
@@ -365,9 +369,8 @@ static bool diagnoseSpecialErrors(SILInstruction *unevaluableInst,
365369
366370 if (unknownReason.getKind () == UnknownReason::Trap) {
367371 // We have an assertion failure or fatal error.
368- const char *message = unknownReason.getTrapMessage ();
369372 diagnose (ctx, sourceLoc, diag::oslog_constant_eval_trap,
370- StringRef (message ));
373+ unknownReason. getTrapMessage ( ));
371374 return true ;
372375 }
373376 if (unknownReason.getKind () == UnknownReason::TooManyInstructions) {
@@ -1431,19 +1434,28 @@ suppressGlobalStringTablePointerError(SingleValueInstruction *oslogMessage) {
14311434 SmallVector<SILInstruction *, 8 > users;
14321435 getTransitiveUsers (oslogMessage, users);
14331436
1437+ // Collect all globalStringTablePointer instructions.
1438+ SmallVector<BuiltinInst *, 4 > globalStringTablePointerInsts;
14341439 for (SILInstruction *user : users) {
14351440 BuiltinInst *bi = dyn_cast<BuiltinInst>(user);
1436- if (!bi ||
1437- bi->getBuiltinInfo ().ID != BuiltinValueKind::GlobalStringTablePointer)
1438- continue ;
1439- // Replace this builtin by a string_literal instruction for an empty string.
1441+ if (bi &&
1442+ bi->getBuiltinInfo ().ID == BuiltinValueKind::GlobalStringTablePointer)
1443+ globalStringTablePointerInsts.push_back (bi);
1444+ }
1445+
1446+ // Replace the globalStringTablePointer builtins by a string_literal
1447+ // instruction for an empty string and clean up dead code.
1448+ InstructionDeleter deleter;
1449+ for (BuiltinInst *bi : globalStringTablePointerInsts) {
14401450 SILBuilderWithScope builder (bi);
14411451 StringLiteralInst *stringLiteral = builder.createStringLiteral (
14421452 bi->getLoc (), StringRef (" " ), StringLiteralInst::Encoding::UTF8);
14431453 bi->replaceAllUsesWith (stringLiteral);
1444- // Here, the bulitin instruction is dead, so clean it up.
1445- eliminateDeadInstruction (bi);
1454+ // The bulitin instruction is likely dead. But since we are iterating over
1455+ // many instructions, do the cleanup at the end.
1456+ deleter.trackIfDead (bi);
14461457 }
1458+ deleter.cleanUpDeadInstructions ();
14471459}
14481460
14491461// / If the SILInstruction is an initialization of OSLogMessage, return the
0 commit comments