Skip to content

Commit 3698aa8

Browse files
committed
[OSLogOptimization][Tests] Make the OSLogMandatoryOptTest more liberal in admitting SIL changes.
This patch updates the OSLogMandatoryOptTest test suite so that it only checks whether an expected format string appears in the SIL, and omits checking that it is also passed to the _getGlobalStringTablePointer builtin. The latter property is anyway necessary for the code to compile. This is done to avoid hardcoding the begin_borrow and copy_value instructions that may be introduced when the format string is passed to the builtin. The begin_borrow instructions are omitted in release builds while they appear in debug builds. <rdar://problem/65251877>
1 parent 241c5d9 commit 3698aa8

File tree

1 file changed

+26
-92
lines changed

1 file changed

+26
-92
lines changed

test/SILOptimizer/OSLogMandatoryOptTest.swift

Lines changed: 26 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ func testSimpleInterpolation() {
1818
// CHECK-DAG is used here as it is easier to perform the checks backwards
1919
// from uses to the definitions.
2020

21-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
22-
// We need to wade through some borrows and copy values here.
23-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
24-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
25-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
26-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
27-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
28-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Minimum integer value: %ld"
21+
// Match the format string first.
22+
// CHECK: string_literal utf8 "Minimum integer value: %ld"
2923

3024
// Check if the size of the argument buffer is a constant.
3125

@@ -71,13 +65,8 @@ func testInterpolationWithFormatOptions() {
7165

7266
// Check if there is a call to _os_log_impl with a literal format string.
7367

74-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
75-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
76-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
77-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
78-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
79-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
80-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Maximum unsigned integer value: %lx"
68+
// Match the format string first.
69+
// CHECK: string_literal utf8 "Maximum unsigned integer value: %lx"
8170

8271
// Check if the size of the argument buffer is a constant.
8372

@@ -124,13 +113,8 @@ func testInterpolationWithFormatOptionsAndPrivacy() {
124113

125114
// Check if there is a call to _os_log_impl with a literal format string.
126115

127-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
128-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
129-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
130-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
131-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
132-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
133-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Private Identifier: %{private}lx"
116+
// Match the format string first.
117+
// CHECK: string_literal utf8 "Private Identifier: %{private}lx"
134118

135119
// Check if the size of the argument buffer is a constant.
136120

@@ -183,13 +167,8 @@ func testInterpolationWithMultipleArguments() {
183167

184168
// Check if there is a call to _os_log_impl with a literal format string.
185169

186-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
187-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
188-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
189-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
190-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
191-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
192-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Access prevented: process %{public}ld initiated by user: %{private}ld attempted resetting permissions to %lo"
170+
// Match the format string first.
171+
// CHECK: string_literal utf8 "Access prevented: process %{public}ld initiated by user: %{private}ld attempted resetting permissions to %lo"
193172

194173
// Check if the size of the argument buffer is a constant.
195174

@@ -240,13 +219,8 @@ func testLogMessageWithoutData() {
240219

241220
// Check if there is a call to _os_log_impl with a literal format string.
242221

243-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
244-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
245-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
246-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
247-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
248-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
249-
// CHECK-DAG: [[LIT]] = string_literal utf8 "A message with no data"
222+
// Match the format string first.
223+
// CHECK: string_literal utf8 "A message with no data"
250224

251225
// Check if the size of the argument buffer is a constant.
252226

@@ -284,37 +258,22 @@ func testLogMessageWithoutData() {
284258
// CHECK-LABEL: @${{.*}}testEscapingOfPercentsyy
285259
func testEscapingOfPercents() {
286260
_osLogTestHelper("Process failed after 99% completion")
287-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
288-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
289-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
290-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
291-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
292-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
293-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Process failed after 99%% completion"
261+
// Match the format string first.
262+
// CHECK: string_literal utf8 "Process failed after 99%% completion"
294263
}
295264

296265
// CHECK-LABEL: @${{.*}}testDoublePercentsyy
297266
func testDoublePercents() {
298267
_osLogTestHelper("Double percents: %%")
299-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
300-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
301-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
302-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
303-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
304-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
305-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Double percents: %%%%"
268+
// Match the format string first.
269+
// CHECK: string_literal utf8 "Double percents: %%%%"
306270
}
307271

308272
// CHECK-LABEL: @${{.*}}testSmallFormatStringsyy
309273
func testSmallFormatStrings() {
310274
_osLogTestHelper("a")
311-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
312-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
313-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
314-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
315-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
316-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
317-
// CHECK-DAG: [[LIT]] = string_literal utf8 "a"
275+
// Match the format string first.
276+
// CHECK: string_literal utf8 "a"
318277
}
319278

320279
/// A stress test that checks whether the optimizer handle messages with more
@@ -332,13 +291,8 @@ func testMessageWithTooManyArguments() {
332291

333292
// Check if there is a call to _os_log_impl with a literal format string.
334293

335-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
336-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
337-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
338-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
339-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
340-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
341-
// CHECK-DAG: [[LIT]] = string_literal utf8 "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld "
294+
// Match the format string first.
295+
// CHECK: string_literal utf8 "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld "
342296

343297
// Check if the size of the argument buffer is a constant.
344298

@@ -382,13 +336,8 @@ func testInt32Interpolation() {
382336

383337
// Check if there is a call to _os_log_impl with a literal format string.
384338

385-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
386-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
387-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
388-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
389-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
390-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
391-
// CHECK-DAG: [[LIT]] = string_literal utf8 "32-bit integer value: %d"
339+
// Match the format string first.
340+
// CHECK: string_literal utf8 "32-bit integer value: %d"
392341

393342
// Check if the size of the argument buffer is a constant.
394343

@@ -426,13 +375,8 @@ func testDynamicStringArguments() {
426375
// CHECK-DAG is used here as it is easier to perform the checks backwards
427376
// from uses to the definitions.
428377

429-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
430-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
431-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
432-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
433-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
434-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
435-
// CHECK-DAG: [[LIT]] = string_literal utf8 "concat: %{public}s interpolated: %{private}s"
378+
// Match the format string first.
379+
// CHECK: string_literal utf8 "concat: %{public}s interpolated: %{private}s"
436380

437381
// Check if the size of the argument buffer is a constant.
438382

@@ -484,13 +428,8 @@ func testNSObjectInterpolation() {
484428
// CHECK-DAG is used here as it is easier to perform the checks backwards
485429
// from uses to the definitions.
486430

487-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
488-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
489-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
490-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
491-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
492-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
493-
// CHECK-DAG: [[LIT]] = string_literal utf8 "NSArray: %{public}@ NSDictionary: %{private}@"
431+
// Match the format string first.
432+
// CHECK: string_literal utf8 "NSArray: %{public}@ NSDictionary: %{private}@"
494433

495434
// Check if the size of the argument buffer is a constant.
496435

@@ -537,13 +476,8 @@ func testDoubleInterpolation() {
537476
// CHECK-DAG is used here as it is easier to perform the checks backwards
538477
// from uses to the definitions.
539478

540-
// CHECK-DAG: builtin "globalStringTablePointer"([[STRING:%[0-9]+]] : $String)
541-
// CHECK-DAG: [[STRING]] = begin_borrow [[STRING2:%[0-9]+]]
542-
// CHECK-DAG: [[STRING2]] = copy_value [[STRING3:%[0-9]+]]
543-
// CHECK-DAG: [[STRING3]] = begin_borrow [[STRING4:%[0-9]+]]
544-
// CHECK-DAG: [[STRING4]] = apply [[STRING_INIT:%[0-9]+]]([[LIT:%[0-9]+]],
545-
// CHECK-DAG: [[STRING_INIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
546-
// CHECK-DAG: [[LIT]] = string_literal utf8 "Tau = %f"
479+
// Match the format string first.
480+
// CHECK: string_literal utf8 "Tau = %f"
547481

548482
// Check if the size of the argument buffer is a constant.
549483

0 commit comments

Comments
 (0)