Skip to content

Commit fe7c1ca

Browse files
committed
Clang importer: Global vars imported as static member properties are final.
1 parent 1056a9b commit fe7c1ca

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,11 @@ namespace {
27972797
Impl.importSourceLoc(decl->getLocation()),
27982798
name, type, dc);
27992799

2800+
// If imported as member, the member should be final.
2801+
if (dc->getAsClassOrClassExtensionContext())
2802+
result->getAttrs().add(new (Impl.SwiftContext)
2803+
FinalAttr(/*IsImplicit=*/true));
2804+
28002805
if (!decl->hasExternalStorage())
28012806
Impl.registerExternalDecl(result);
28022807

test/IDE/Inputs/custom-modules/ImportAsMemberC.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ extern const CCPowerSupplyRef kCCPowerSupplySemiModular
2929

3030
#pragma clang arc_cf_code_audited end
3131

32+
extern const double kCCPowerSupplyDefaultPower
33+
__attribute__((swift_name("CCPowerSupply.defaultPower")));
34+
35+
extern const _Nonnull CCPowerSupplyRef kCCPowerSupplyAC
36+
__attribute__((swift_name("CCPowerSupply.AC")));
37+
38+
extern const _Nullable CCPowerSupplyRef kCCPowerSupplyDC
39+
__attribute__((swift_name("CCPowerSupply.DC")));

test/IDE/import_as_member_cf.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// PRINTC: extension CCPowerSupply {
88
// PRINTC-NEXT: /*not inherited*/ init(watts watts: Double)
99
// PRINTC-NEXT: class let semiModular: CCPowerSupply!
10+
// PRINTC-NEXT: class let defaultPower: Double
11+
// PRINTC-NEXT: class let AC: CCPowerSupply
12+
// PRINTC-NEXT: class let DC: CCPowerSupply?
1013
// PRINTC-NEXT: }
1114

1215
// PRINTC: extension CCRefrigerator {

test/Interpreter/SDK/CGImportAsMember.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// REQUIRES: executable_test
33
// REQUIRES: OS=macosx
44

5-
// XFAIL:
6-
75
import Foundation
86
import CoreGraphics
97

test/SILGen/cf_members.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,12 @@ public func importAsProtocol(_ x: IAMProto_t) {
251251
// CHECK: function_ref @setSomeValue : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0, Int32) -> Int32
252252
x.someValue = y
253253
}
254+
255+
// CHECK-LABEL: sil @_TF10cf_members28importGlobalVarsAsProperties
256+
public func importGlobalVarsAsProperties()
257+
-> (Double, CCPowerSupply, CCPowerSupply?) {
258+
// CHECK: global_addr @kCCPowerSupplyDC
259+
// CHECK: global_addr @kCCPowerSupplyAC
260+
// CHECK: global_addr @kCCPowerSupplyDefaultPower
261+
return (CCPowerSupply.defaultPower, CCPowerSupply.AC, CCPowerSupply.DC)
262+
}

test/SILGen/import_as_member_cf.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// RUN: %target-swift-frontend -emit-silgen -I %S/../IDE/Inputs/custom-modules %s 2>&1 | FileCheck --check-prefix=SIL %s
22
// REQUIRES: objc_interop
33

4-
// XFAIL:
5-
64
import ImportAsMember.C
75

86
// SIL-LABEL: sil {{.*}}readSemiModularPowerSupply{{.*}}

0 commit comments

Comments
 (0)