Skip to content

Commit d2a1361

Browse files
Merge pull request #14302 from aschwaighofer/irgen_swift_getFunctionTypeMetadata_readonly
IRGen: swift_getFunctionTypeMetadata is ReadOnly
2 parents 6108c88 + 6495bc3 commit d2a1361

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ FUNCTION(GetFunctionMetadata, swift_getFunctionTypeMetadata, C_CC,
746746
TypeMetadataPtrTy->getPointerTo(0),
747747
Int32Ty->getPointerTo(0),
748748
TypeMetadataPtrTy),
749-
ATTRS(NoUnwind))
749+
ATTRS(NoUnwind, ReadOnly))
750750

751751
// Metadata *swift_getFunctionTypeMetadata0(unsigned long flags,
752752
// const Metadata *resultMetadata);

test/Interpreter/closures.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ func f() -> Bool? { return nil }
8282
let c = { b = true }
8383
_ = (b, c)
8484
})()
85+
86+
// This used to crash at one point in optimized mode because we had the wrong
87+
// memory effects on swift_getFunctionTypeMetadata.
88+
func crash() {
89+
let f: (Int, Int, Int, Int) -> Int = { _, _, _, _ in 21 }
90+
let fs = [f, f]
91+
// CHECK: fs: [(Function), (Function)]
92+
print("fs: \(fs)")
93+
}
94+
crash()

0 commit comments

Comments
 (0)