Skip to content

Commit 3d7df83

Browse files
authored
Merge pull request swiftlang#65647 from eeckstein/fix-enum-stack-protection
clang importer: don't trigger stack protection when accessing an imported enum
2 parents 14665f9 + 782b777 commit 3d7df83

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ synthesizeUnionFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
877877
newValueRef->setType(newValueDecl->getInterfaceType());
878878

879879
auto addressofFn =
880-
cast<FuncDecl>(getBuiltinValueDecl(ctx, ctx.getIdentifier("addressof")));
880+
cast<FuncDecl>(getBuiltinValueDecl(ctx, ctx.getIdentifier("unprotectedAddressOf")));
881881
ConcreteDeclRef addressofFnRef(
882882
addressofFn, SubstitutionMap::get(addressofFn->getGenericSignature(),
883883
{inoutSelfDecl->getInterfaceType()},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
struct S {
3+
int a;
4+
union {
5+
int b;
6+
int c;
7+
};
8+
};
9+
10+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/enum-stack-protection.h %s -Onone -module-name=test -emit-sil | %FileCheck %s
2+
3+
// Check that accessing an imported enum doesn't trigger stack protection.
4+
5+
// CHECK-LABEL: sil @$s4test6testityyF : $@convention(thin) () -> () {
6+
// CHECK: address_to_pointer %{{[0-9]+}}
7+
// CHECK: address_to_pointer %{{[0-9]+}}
8+
// CHECK: } // end sil function '$s4test6testityyF'
9+
public func testit() {
10+
var s = S()
11+
s.a = 1
12+
s.b = 2
13+
s.c = 3
14+
useit(s)
15+
}
16+
17+
@inline(never)
18+
public func useit(_ s: S) {
19+
}
20+

0 commit comments

Comments
 (0)