Skip to content

Commit 0ada6ec

Browse files
committed
SIL SideEffects: handle program termination point functions
We can ignore any memory writes in a program termination point, because it's not relevant for the caller. But we need to consider memory reads, otherwise preceeding memory writes would be eliminated by dead-store-elimination in the caller. E.g. String initialization for error strings which are printed by the program termination point. Regarding ownership: a program termination point must not touch any reference counted objects.
1 parent ab2fe45 commit 0ada6ec

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ extension Function {
128128
default:
129129
break
130130
}
131+
if isProgramTerminationPoint {
132+
// We can ignore any memory writes in a program termination point, because it's not relevant
133+
// for the caller. But we need to consider memory reads, otherwise preceeding memory writes
134+
// would be eliminated by dead-store-elimination in the caller. E.g. String initialization
135+
// for error strings which are printed by the program termination point.
136+
// Regarding ownership: a program termination point must not touch any reference counted objects.
137+
return SideEffects.GlobalEffects(memory: SideEffects.Memory(read: true))
138+
}
131139
var result = SideEffects.GlobalEffects.worstEffects
132140
switch effectAttribute {
133141
case .none:

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
121121
}
122122
}
123123

124+
/// True if the callee function is annotated with @_semantics("programtermination_point").
125+
/// This means that the function terminates the program.
126+
public var isProgramTerminationPoint: Bool { hasSemanticsAttribute("programtermination_point") }
127+
124128
/// Kinds of effect attributes which can be defined for a Swift function.
125129
public enum EffectAttribute {
126130
/// No effect attribute is specified.

0 commit comments

Comments
 (0)