-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Allow attributes @_used and @_section on static variables and member functions #69192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kubamracek
merged 4 commits into
swiftlang:main
from
kubamracek:attr-section-on-static-vars
Oct 22, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f2cd8e0
Allow attributes @_used and @_section on static variables and member …
kubamracek 25cad6f
Diagnose more invalid uses of @_section/@_used
kubamracek 5f037ef
Update tests and test expectations on IRGen/section.swift + IRGen/sec…
kubamracek 9e58514
[embedded] Change empty ';' into a return, reformat and expand tests
kubamracek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %S/section.swift -S -parse-as-library | %FileCheck %s --check-prefix=ASM --check-prefix ASM-%target-os | ||
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %S/section.swift -S -parse-as-library | %FileCheck %s | ||
// REQUIRES: swift_in_compiler | ||
// UNSUPPORTED: CPU=wasm32 | ||
|
||
// ASM: .section{{.*}}__TEXT,__mysection | ||
// ASM-NOT: .section | ||
// ASM: $s7section3fooyyF: | ||
// ASM-linux-gnu: .section{{.*}}__TEXT,__mysection | ||
// ASM-linux-android: .section{{.*}}__TEXT,__mysection | ||
// ASM-linux-androideabi: .section{{.*}}__TEXT,__mysection | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g0Sivp: | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g1Si_Sitvp: | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g2Sbvp: | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g3Sbvp: | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g4SpySiGSgvp: | ||
// ASM-NOT: .section | ||
// ASM: $s7section2g5SpySiGSgvp: | ||
// CHECK: .section{{.*}}__TEXT,__mysection | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section3fooyyF: | ||
|
||
// CHECK: .section{{.*}}__TEXT,__mysection | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section8MyStructV3fooyyF: | ||
|
||
// CHECK: .section{{.*}}__DATA,__mysection | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g0Sivp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g1Si_Sitvp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g2Sbvp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g3Sbvp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g4SpySiGSgvp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section2g5SpySiGSgvp: | ||
// CHECK-NOT: .section | ||
// CHECK: $s7section8MyStructV7static0SivpZ: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-sil %s -o /dev/null -verify | ||
|
||
// REQUIRES: swift_in_compiler | ||
|
||
@_used @_section("__TEXT,__mysection") var g0: Int = 1 // ok | ||
|
||
struct MyStruct { | ||
@_used @_section("__TEXT,__mysection") static var static0: Int = 1 // ok | ||
} | ||
|
||
struct MyStruct2 { | ||
@_section("__TEXT,__mysection") var member0: Int = 1 // expected-error {{properties with attribute '_section' must be static}} | ||
|
||
@_section("__TEXT,__mysection") static var static1: Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}} | ||
} | ||
|
||
struct MyStruct3<T> { | ||
static var member1: Int = 1 // expected-error {{static stored properties not supported in generic types}} | ||
|
||
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}} | ||
} | ||
|
||
struct MyStruct4<T> { | ||
struct InnerStruct { | ||
static var member2: Int = 1 // expected-error {{static stored properties not supported in generic types}} | ||
|
||
@_section("__TEXT,__mysection") static var member3: Int = 1 // expected-error {{static stored properties not supported in generic types}} | ||
// expected-error@-1 {{attribute '_section' cannot be used in a generic context}} | ||
|
||
@_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute '_section' cannot be used in a generic context}} | ||
} | ||
} | ||
|
||
@_section("__TEXT,__mysection") // expected-error {{'@_section' attribute cannot be applied to this declaration}} | ||
struct SomeStruct {} | ||
|
||
@_section("") var g1: Int = 1 // expected-error {{@_section section name cannot be empty}} | ||
|
||
func function() { | ||
@_section("__TEXT,__mysection") var l0: Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}} | ||
l0 += 1 | ||
_ = l0 | ||
|
||
@_used var l1: Int = 1 // expected-error {{attribute '_used' can only be used in a non-local scope}} | ||
l1 += 1 | ||
_ = l1 | ||
} | ||
|
||
func function_with_type() { | ||
class MyClass { | ||
@_section("__TEXT,__mysection") static var member: Int = 1 // ok | ||
} | ||
|
||
do { | ||
class MyClass { | ||
@_section("__TEXT,__mysection") static var member: Int = 1 // ok | ||
} | ||
} | ||
} | ||
|
||
func function_with_type_generic<T>() -> T { | ||
class MyClass { // expected-error {{type 'MyClass' cannot be nested in generic function}} | ||
@_section("__TEXT,__mysection") static var member: Int = 1 // expected-error {{static stored properties not supported in generic types}} | ||
// expected-error@-1 {{attribute '_section' cannot be used in a generic context}} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.