Skip to content

Commit c1ecef7

Browse files
Merge pull request #73191 from nate-chandler/rdar125265980
[IRGen] Deadends don't need dealloc_pack_metadata.
2 parents fae5d2c + da38fb5 commit c1ecef7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "swift/IRGen/Linking.h"
3535
#include "swift/SIL/ApplySite.h"
3636
#include "swift/SIL/BasicBlockDatastructures.h"
37+
#include "swift/SIL/BasicBlockUtils.h"
3738
#include "swift/SIL/Dominance.h"
3839
#include "swift/SIL/InstructionUtils.h"
3940
#include "swift/SIL/MemAccessUtils.h"
@@ -44,6 +45,7 @@
4445
#include "swift/SIL/SILLinkage.h"
4546
#include "swift/SIL/SILModule.h"
4647
#include "swift/SIL/SILType.h"
48+
#include "swift/SIL/SILValue.h"
4749
#include "swift/SIL/SILVisitor.h"
4850
#include "swift/SIL/TerminatorUtils.h"
4951
#include "clang/AST/ASTContext.h"
@@ -411,6 +413,9 @@ class IRGenSILFunction :
411413
/// metadata is emitted has some corresponding cleanup instructions.
412414
llvm::DenseMap<SILInstruction *, llvm::SmallVector<SILInstruction *, 2>>
413415
DynamicMetadataPackDeallocs;
416+
417+
// A cached dead-end blocks analysis.
418+
std::unique_ptr<DeadEndBlocks> DeadEnds;
414419
#endif
415420
/// For each instruction which did allocate pack metadata on-stack, the stack
416421
/// locations at which they were allocated.
@@ -685,6 +690,15 @@ class IRGenSILFunction :
685690
return Name;
686691
}
687692

693+
#ifndef NDEBUG
694+
DeadEndBlocks *getDeadEndBlocks() {
695+
if (!DeadEnds) {
696+
DeadEnds.reset(new DeadEndBlocks(CurSILFn));
697+
}
698+
return DeadEnds.get();
699+
}
700+
#endif
701+
688702
/// To make it unambiguous whether a `var` binding has been initialized,
689703
/// zero-initialize the shadow copy alloca. LLDB uses the first pointer-sized
690704
/// field to recognize to detect uninitialized variables. This can be
@@ -2744,8 +2758,9 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
27442758
#ifndef NDEBUG
27452759
if (!OutstandingStackPackAllocs.empty()) {
27462760
auto iter = DynamicMetadataPackDeallocs.find(&I);
2747-
if (iter == DynamicMetadataPackDeallocs.end() ||
2748-
iter->getSecond().size() == 0) {
2761+
if ((iter == DynamicMetadataPackDeallocs.end() ||
2762+
iter->getSecond().size() == 0) &&
2763+
!getDeadEndBlocks()->isDeadEnd(I.getParent())) {
27492764
llvm::errs()
27502765
<< "Instruction missing on-stack pack metadata cleanups!\n";
27512766
I.print(llvm::errs());

validation-test/IRGen/gh72536.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-emit-ir \
2+
// RUN: %s \
3+
// RUN: -disable-availability-checking
4+
5+
func foo<each S>(_ s: repeat each S) async {}
6+
await foo(true)
7+

0 commit comments

Comments
 (0)