Skip to content

Commit c7922b2

Browse files
authored
Merge pull request #79774 from mikeash/bigger-empty-va-list-storage
[Stdlib] Make alignedStorageForEmptyVaLists bigger.
2 parents 654d542 + 70e1931 commit c7922b2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

stdlib/public/core/VarArgs.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,14 @@ final internal class __VaListBuilder {
723723
internal var retainer = [CVarArg]()
724724
#endif
725725

726-
internal static var alignedStorageForEmptyVaLists: Double = 0
726+
// Some code will call a variadic function without passing variadic parameters
727+
// where the function will still attempt to read variadic parameters. For
728+
// example, calling printf with an arbitrary string as the format string. This
729+
// is inherently unsound, but we'll try to be nice to such code by giving it
730+
// 64 bytes of zeroes in that case.
731+
internal static var alignedStorageForEmptyVaLists:
732+
(Double, Double, Double, Double, Double, Double, Double, Double)
733+
= (0, 0, 0, 0, 0, 0, 0, 0)
727734
}
728735

729736
#endif

test/stdlib/VarArgs.swift

+14
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ func test_varArgs6() {
172172
}
173173
test_varArgs6()
174174

175+
func test_varArgs7() {
176+
#if canImport(Darwin) && arch(arm64)
177+
// Test a workaround for format specifiers and no arguments. We supply eight
178+
// words of zeroed memory to give this predictable behavior.
179+
my_printf("No parameters: %ld %ld %ld %ld %ld %ld %ld %ld\n")
180+
#else
181+
// va_list is more complicated on other targets so that behavior is not the
182+
// same, skip the test by doing a fake print of the expected output.
183+
my_printf("No parameters: 0 0 0 0 0 0 0 0\n")
184+
#endif
185+
// CHECK: No parameters: 0 0 0 0 0 0 0 0
186+
}
187+
test_varArgs7()
188+
175189

176190
// CHECK: done.
177191
my_printf("done.")

0 commit comments

Comments
 (0)