Skip to content

Commit 1a640d4

Browse files
committed
Sema: Targeted fix for LLDB REPL issue
LLDB changes accessiblity of declarations after type checking, which is not a good idea because it is likely to break invariants. Indeed, the validateFixedLayoutAttribute() / hasFixedLayout() logic was not prepared for this possibility. This is a targeted fix to address the immediate breakage. A better fix would be to change LLDB, and also to change Sema to store the global -enable-resilience flag state in a bit in the serialized module, instead of sticking it on every declaration. Fixes <rdar://problem/23545959>.
1 parent 88ca1e5 commit 1a640d4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,10 @@ bool NominalTypeDecl::hasFixedLayout() const {
18571857
return true;
18581858
}
18591859

1860+
// Objective-C enums always have a fixed layout.
1861+
if (isa<EnumDecl>(this) && isObjC())
1862+
return true;
1863+
18601864
// Otherwise, access via indirect "resilient" interfaces.
18611865
return false;
18621866
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6957,18 +6957,17 @@ static void validateFixedLayoutAttribute(TypeChecker &TC,
69576957
NominalTypeDecl *D) {
69586958
DeclAttributes &Attrs = D->getAttrs();
69596959

6960-
if (Attrs.hasAttribute<FixedLayoutAttr>())
6960+
// FIXME: Add a per-module serialized HasFixedLayout flag, instead of
6961+
// giving every decl this attribute.
6962+
6963+
if (Attrs.hasAttribute<FixedLayoutAttr>() ||
6964+
TC.Context.LangOpts.EnableResilience)
69616965
return;
69626966

69636967
// Since -enable-resilience should not change how we call into
69646968
// existing compiled modules, make all value types @_fixed_layout
69656969
// when the frontend is not run with the -enable-resilience flag.
6966-
if (!TC.Context.LangOpts.EnableResilience &&
6967-
D->getFormalAccess() == Accessibility::Public)
6968-
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
6969-
// @objc enums are always @_fixed_layout.
6970-
else if (isa<EnumDecl>(D) && D->isObjC())
6971-
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
6970+
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
69726971
}
69736972

69746973
static void validateAttributes(TypeChecker &TC, Decl *D) {

test/Serialization/alignment.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// RUN: %target-swift-frontend %s -emit-module -parse-as-library -o %t
44
// RUN: %target-sil-opt -enable-sil-verify-all %t/alignment.swiftmodule -o - | FileCheck %s
55

6-
//CHECK: @_alignment(16) struct Foo {
7-
@_alignment(16) struct Foo {}
6+
//CHECK: @_alignment(16) @_fixed_layout struct Foo {
7+
@_alignment(16) @_fixed_layout struct Foo {}
88

99
func foo(x: Foo) {}
1010

0 commit comments

Comments
 (0)