Skip to content

Commit 327fa92

Browse files
Merge pull request #73236 from nate-chandler/cherrypick/release/6.0/rdar125265980
6.0: [IRGen] Deadends don't need dealloc_pack_metadata.
2 parents 6406030 + bb7f654 commit 327fa92

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "GenKeyPath.h"
19-
#include "swift/AST/ExtInfo.h"
2019
#include "swift/AST/ASTContext.h"
2120
#include "swift/AST/ASTMangler.h"
2221
#include "swift/AST/DiagnosticsIRGen.h"
22+
#include "swift/AST/ExtInfo.h"
2323
#include "swift/AST/GenericEnvironment.h"
2424
#include "swift/AST/IRGenOptions.h"
2525
#include "swift/AST/ParameterList.h"
@@ -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"
@@ -410,6 +412,9 @@ class IRGenSILFunction :
410412
/// metadata is emitted has some corresponding cleanup instructions.
411413
llvm::DenseMap<SILInstruction *, llvm::SmallVector<SILInstruction *, 2>>
412414
DynamicMetadataPackDeallocs;
415+
416+
// A cached dead-end blocks analysis.
417+
std::unique_ptr<DeadEndBlocks> DeadEnds;
413418
#endif
414419
/// For each instruction which did allocate pack metadata on-stack, the stack
415420
/// locations at which they were allocated.
@@ -680,6 +685,15 @@ class IRGenSILFunction :
680685
return Name;
681686
}
682687

688+
#ifndef NDEBUG
689+
DeadEndBlocks *getDeadEndBlocks() {
690+
if (!DeadEnds) {
691+
DeadEnds.reset(new DeadEndBlocks(CurSILFn));
692+
}
693+
return DeadEnds.get();
694+
}
695+
#endif
696+
683697
/// To make it unambiguous whether a `var` binding has been initialized,
684698
/// zero-initialize the shadow copy alloca. LLDB uses the first pointer-sized
685699
/// field to recognize to detect uninitialized variables. This can be
@@ -2736,8 +2750,9 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
27362750
#ifndef NDEBUG
27372751
if (!OutstandingStackPackAllocs.empty()) {
27382752
auto iter = DynamicMetadataPackDeallocs.find(&I);
2739-
if (iter == DynamicMetadataPackDeallocs.end() ||
2740-
iter->getSecond().size() == 0) {
2753+
if ((iter == DynamicMetadataPackDeallocs.end() ||
2754+
iter->getSecond().size() == 0) &&
2755+
!getDeadEndBlocks()->isDeadEnd(I.getParent())) {
27412756
llvm::errs()
27422757
<< "Instruction missing on-stack pack metadata cleanups!\n";
27432758
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)