Skip to content

Commit f84f48e

Browse files
committed
[silgen] Make SwitchCaseFullExpr use an ArgumentScope instead of just a Scope.
Otherwise, if we move in a formal access cleanup value into switch emission using a cleanup cloner, we will improperly have a formal access cleanup that will be invalidated by a normal Scope which violates SILGen invariants. Also in a certain sense the bindings performed by SILGenPattern that do this type of forwarding are arguments in a certain sense so it seems reasonable to do this. <rdar://problem/70736924>
1 parent cafd293 commit f84f48e

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

lib/SILGen/ArgumentScope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class ArgumentScope {
6161
formalEvalScope.verify();
6262
}
6363

64+
bool isValid() const { return normalScope.isValid(); }
65+
6466
private:
6567
void popImpl() {
6668
// We must always pop the formal eval scope before the normal scope since

lib/SILGen/SwitchEnumBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ using namespace Lowering;
2222
//===----------------------------------------------------------------------===//
2323

2424
SwitchCaseFullExpr::SwitchCaseFullExpr(SILGenFunction &SGF, CleanupLocation loc)
25-
: SGF(SGF), scope(SGF.Cleanups, loc), loc(loc), branchDest() {}
25+
: SGF(SGF), scope(SGF, loc), loc(loc), branchDest() {}
2626

2727
SwitchCaseFullExpr::SwitchCaseFullExpr(SILGenFunction &SGF, CleanupLocation loc,
2828
SwitchCaseBranchDest branchDest)
29-
: SGF(SGF), scope(SGF.Cleanups, loc), loc(loc), branchDest(branchDest) {}
29+
: SGF(SGF), scope(SGF, loc), loc(loc), branchDest(branchDest) {}
3030

3131
void SwitchCaseFullExpr::exitAndBranch(SILLocation loc,
3232
ArrayRef<SILValue> branchArgs) {

lib/SILGen/SwitchEnumBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SILGEN_SWITCHENUMBUILDER_H
1414
#define SWIFT_SILGEN_SWITCHENUMBUILDER_H
1515

16+
#include "ArgumentScope.h"
1617
#include "Scope.h"
1718

1819
namespace swift {
@@ -52,7 +53,7 @@ struct SwitchCaseBranchDest {
5253
/// This scope is also exposed to the debug info.
5354
class SwitchCaseFullExpr {
5455
SILGenFunction &SGF;
55-
Scope scope;
56+
ArgumentScope scope;
5657
CleanupLocation loc;
5758
SwitchCaseBranchDest branchDest;
5859

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
@import Foundation;
3+
4+
@interface ObjCKlass : NSObject
5+
6+
@property(nonatomic, copy, nullable) NSURL *outputURL;
7+
8+
@end

test/SILGen/objc_bridging_url.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-silgen -import-objc-header %S/Inputs/objc_bridging_nsurl.h %s
3+
4+
// REQUIRES: objc_interop
5+
6+
// Make sure we do not crash on this
7+
8+
protocol P {
9+
var outputURL : URL? { get set }
10+
}
11+
12+
extension ObjCKlass : P {}

0 commit comments

Comments
 (0)