Skip to content

Commit 70c54bb

Browse files
authored
Merge pull request #74551 from kubamracek/embedded-static-objects
[embedded] Enable read-only static array promotion in embedded mode
2 parents 991e7fd + 62d7167 commit 70c54bb

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Diff for: lib/IRGen/IRGenModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ bool IRGenModule::canMakeStaticObjectReadOnly(SILType objectType) {
20912091

20922092
// TODO: Support constant static arrays on other platforms, too.
20932093
// See also the comment in GlobalObjects.cpp.
2094-
if (!Triple.isOSDarwin())
2094+
if (!Triple.isOSDarwin() && !Context.LangOpts.hasFeature(Feature::Embedded))
20952095
return false;
20962096

20972097
auto *clDecl = objectType.getClassOrBoundGenericClass();

Diff for: test/embedded/static-object-non-darwin.swift

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-frontend -target armv7em-none-none-eabi -parse-as-library -module-name main -O -emit-ir %s -enable-experimental-feature Embedded -Xllvm -link-embedded-runtime=0 | %FileCheck %s
2+
// RUN: %target-swift-frontend -target armv7em-none-none-eabi -parse-as-library -module-name main -Osize -emit-ir %s -enable-experimental-feature Embedded -Xllvm -link-embedded-runtime=0 | %FileCheck %s
3+
4+
// REQUIRES: swift_in_compiler
5+
// REQUIRES: optimized_stdlib
6+
// REQUIRES: OS=macosx || OS=linux-gnu
7+
// REQUIRES: CODEGENERATOR=ARM
8+
// REQUIRES: embedded_stdlib_cross_compiling
9+
10+
let pots = [41,52,99,1,4,4]
11+
12+
public enum ValidState {
13+
case yes
14+
case no
15+
case undefined
16+
}
17+
18+
public func checkPot(i: UInt8, testValue: UInt8) -> ValidState {
19+
guard i < pots.count else { return .undefined }
20+
return pots[Int(i)] < testValue ? .yes : .no
21+
}
22+
23+
// CHECK: @"$s4main4pots_Wz" = {{.*}}global i32 0
24+
// CHECK: @"$ss20__StaticArrayStorageCN" = {{.*}}global ptr null
25+
// CHECK: @"$s4main4pots_WZTv_r" = {{.*}}constant %Ts23_ContiguousArrayStorageCySiG_tailelems0 {{.*}}@"$ss20__StaticArrayStorageCN"
26+
// CHECK: @"$s4main4potsSaySiGvp" = {{.*}}constant %TSa {{.*}}@"$s4main4pots_WZTv_r"

0 commit comments

Comments
 (0)