Skip to content

Commit 9e58514

Browse files
committed
[embedded] Change empty ';' into a return, reformat and expand tests
1 parent 5f037ef commit 9e58514

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,8 +2109,9 @@ void AttributeChecker::visitSectionAttr(SectionAttr *attr) {
21092109
diagnose(attr->getLocation(), diag::section_empty_name);
21102110

21112111
if (D->getDeclContext()->isLocalContext())
2112-
; // Already diagnosed in Parse, don't diagnose again
2113-
else if (D->getDeclContext()->isGenericContext())
2112+
return; // already diagnosed
2113+
2114+
if (D->getDeclContext()->isGenericContext())
21142115
diagnose(attr->getLocation(), diag::attr_only_at_non_generic_scope,
21152116
attr->getAttrName());
21162117
else if (auto *VarD = dyn_cast<VarDecl>(D)) {

test/IRGen/section_errors.swift

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@
22

33
// REQUIRES: swift_in_compiler
44

5-
@_used @_section("__TEXT,__mysection") var g0: Int = 1
5+
@_used @_section("__TEXT,__mysection") var g0: Int = 1 // ok
66

77
struct MyStruct {
8-
@_used @_section("__TEXT,__mysection") static var static0: Int = 1
8+
@_used @_section("__TEXT,__mysection") static var static0: Int = 1 // ok
99
}
1010

1111
struct MyStruct2 {
12-
@_section("__TEXT,__mysection") var member0: Int = 1 // expected-error {{properties with attribute '_section' must be static}}
12+
@_section("__TEXT,__mysection") var member0: Int = 1 // expected-error {{properties with attribute '_section' must be static}}
1313

14-
@_section("__TEXT,__mysection") static var member0: Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}}
14+
@_section("__TEXT,__mysection") static var static1: Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}}
1515
}
1616

1717
struct MyStruct3<T> {
18-
static var member0: Int = 1 // expected-error {{static stored properties not supported in generic types}}
18+
static var member1: Int = 1 // expected-error {{static stored properties not supported in generic types}}
1919

20-
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}}
20+
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}}
2121
}
2222

2323
struct MyStruct4<T> {
24-
struct InnerStruct {
25-
static var member0: Int = 1 // expected-error {{static stored properties not supported in generic types}}
24+
struct InnerStruct {
25+
static var member2: Int = 1 // expected-error {{static stored properties not supported in generic types}}
2626

27-
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}}
28-
}
27+
@_section("__TEXT,__mysection") static var member3: Int = 1 // expected-error {{static stored properties not supported in generic types}}
28+
// expected-error@-1 {{attribute '_section' cannot be used in a generic context}}
29+
30+
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}}
31+
}
2932
}
3033

3134
@_section("__TEXT,__mysection") // expected-error {{'@_section' attribute cannot be applied to this declaration}}
@@ -34,11 +37,30 @@ struct SomeStruct {}
3437
@_section("") var g1: Int = 1 // expected-error {{@_section section name cannot be empty}}
3538

3639
func function() {
37-
@_section("__TEXT,__mysection") var l0: Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}}
38-
l0 += 1
39-
_ = l0
40+
@_section("__TEXT,__mysection") var l0: Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}}
41+
l0 += 1
42+
_ = l0
43+
44+
@_used var l1: Int = 1 // expected-error {{attribute '_used' can only be used in a non-local scope}}
45+
l1 += 1
46+
_ = l1
47+
}
48+
49+
func function_with_type() {
50+
class MyClass {
51+
@_section("__TEXT,__mysection") static var member: Int = 1 // ok
52+
}
53+
54+
do {
55+
class MyClass {
56+
@_section("__TEXT,__mysection") static var member: Int = 1 // ok
57+
}
58+
}
59+
}
4060

41-
@_used var l1: Int = 1 // expected-error {{attribute '_used' can only be used in a non-local scope}}
42-
l1 += 1
43-
_ = l1
61+
func function_with_type_generic<T>() -> T {
62+
class MyClass { // expected-error {{type 'MyClass' cannot be nested in generic function}}
63+
@_section("__TEXT,__mysection") static var member: Int = 1 // expected-error {{static stored properties not supported in generic types}}
64+
// expected-error@-1 {{attribute '_section' cannot be used in a generic context}}
65+
}
4466
}

0 commit comments

Comments
 (0)