Skip to content

Commit 9a5974f

Browse files
authored
Merge pull request #69958 from eeckstein/fix-init-static-globals
initializeStaticGlobalsPass: don't crash if there was a preceding error
2 parents 699b165 + bdde6d3 commit 9a5974f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/InitializeStaticGlobals.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ import SIL
4444
let initializeStaticGlobalsPass = FunctionPass(name: "initialize-static-globals") {
4545
(function: Function, context: FunctionPassContext) in
4646

47+
if context.hadError {
48+
// In case of a preceding error, there is no guarantee that the SIL is valid.
49+
return
50+
}
51+
4752
if !function.isGlobalInitOnceFunction {
4853
return
4954
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -parse-as-library -emit-sil %s -o /dev/null -verify
2+
3+
// Don't crash in the initializeStaticGlobalsPass when the global is not valid.
4+
5+
let f: @convention(c) () -> Void = { // expected-error {{a C function pointer cannot be formed from a closure that captures generic parameters}}
6+
func g<T>(_ x: T) {}
7+
}

0 commit comments

Comments
 (0)