mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492. Major parts: - Renamed @_section to @section and @_used to @used - Removed the SymbolLinkageMarkers experimental feature - Added parsing support for the old underscored names with deprecation warnings - Updated all tests and examples to use the new attribute names - Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm) - Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules - Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %{python} %utils/split_file.py -o %t %s
|
|
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o
|
|
// RUN: %target-clang %t/a.o -o %t/a.out
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: OS=macosx
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
// BEGIN MyModule.swift
|
|
|
|
@used
|
|
@section("__DATA,__mysection")
|
|
let i_am_not_referenced = 42
|
|
|
|
// BEGIN Main.swift
|
|
|
|
import MyModule
|
|
|
|
@_silgen_name(raw: "section$start$__DATA$__mysection")
|
|
var mysection_start: Int
|
|
|
|
@_silgen_name(raw: "section$end$__DATA$__mysection")
|
|
var mysection_end: Int
|
|
|
|
@main
|
|
struct Main {
|
|
static func main() {
|
|
let start = UnsafeRawPointer(&mysection_start)
|
|
let end = UnsafeRawPointer(&mysection_end)
|
|
let size = end - start
|
|
let count = size / (Int.bitWidth / 8)
|
|
print("count: \(count)")
|
|
let linker_set = UnsafeBufferPointer(start: start.bindMemory(to: Int.self, capacity: count), count: count)
|
|
for i in 0 ..< linker_set.count {
|
|
print("mysection[\(i)]: \(linker_set[i])")
|
|
}
|
|
}
|
|
}
|
|
|
|
// CHECK-SIL: // i_am_not_referenced
|
|
// CHECK-SIL-NEXT: sil_global [serialized] [let] [used] [section "__DATA,__mysection"] @$e8MyModule19i_am_not_referencedSivp : $Int = {
|
|
|
|
// CHECK: count: 1
|
|
// CHECK: mysection[0]: 42
|