@@ -108,6 +108,10 @@ using namespace Lowering;
108
108
template <typename ... T, typename ... U>
109
109
static void diagnose (ASTContext &Context, SourceLoc loc, Diag<T...> diag,
110
110
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.
111
115
Context.Diags .diagnose (loc, diag, std::forward<U>(args)...);
112
116
}
113
117
@@ -365,9 +369,8 @@ static bool diagnoseSpecialErrors(SILInstruction *unevaluableInst,
365
369
366
370
if (unknownReason.getKind () == UnknownReason::Trap) {
367
371
// We have an assertion failure or fatal error.
368
- const char *message = unknownReason.getTrapMessage ();
369
372
diagnose (ctx, sourceLoc, diag::oslog_constant_eval_trap,
370
- StringRef (message ));
373
+ unknownReason. getTrapMessage ( ));
371
374
return true ;
372
375
}
373
376
if (unknownReason.getKind () == UnknownReason::TooManyInstructions) {
@@ -1431,19 +1434,28 @@ suppressGlobalStringTablePointerError(SingleValueInstruction *oslogMessage) {
1431
1434
SmallVector<SILInstruction *, 8 > users;
1432
1435
getTransitiveUsers (oslogMessage, users);
1433
1436
1437
+ // Collect all globalStringTablePointer instructions.
1438
+ SmallVector<BuiltinInst *, 4 > globalStringTablePointerInsts;
1434
1439
for (SILInstruction *user : users) {
1435
1440
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) {
1440
1450
SILBuilderWithScope builder (bi);
1441
1451
StringLiteralInst *stringLiteral = builder.createStringLiteral (
1442
1452
bi->getLoc (), StringRef (" " ), StringLiteralInst::Encoding::UTF8);
1443
1453
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);
1446
1457
}
1458
+ deleter.cleanUpDeadInstructions ();
1447
1459
}
1448
1460
1449
1461
// / If the SILInstruction is an initialization of OSLogMessage, return the
0 commit comments