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.
This commit is contained in:
Erik Eckstein
2022-11-02 19:13:10 +01:00
parent ab2fe452f9
commit 0ada6ec5bd
2 changed files with 12 additions and 0 deletions

View File

@@ -128,6 +128,14 @@ extension Function {
default:
break
}
if isProgramTerminationPoint {
// 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.
return SideEffects.GlobalEffects(memory: SideEffects.Memory(read: true))
}
var result = SideEffects.GlobalEffects.worstEffects
switch effectAttribute {
case .none:

View File

@@ -121,6 +121,10 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
}
}
/// True if the callee function is annotated with @_semantics("programtermination_point").
/// This means that the function terminates the program.
public var isProgramTerminationPoint: Bool { hasSemanticsAttribute("programtermination_point") }
/// Kinds of effect attributes which can be defined for a Swift function.
public enum EffectAttribute {
/// No effect attribute is specified.