Skip to content

Commit 336f3b4

Browse files
authored
Merge pull request #80962 from meg-gupta/cpfixoslogcrash
[6.2] Fix crash in OSLogOptimization
2 parents d04d8bc + d295bf9 commit 336f3b4

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ class StringSILInfo {
163163

164164
this->stringInitIntrinsic = callee;
165165

166-
MetatypeInst *stringMetatypeInst =
167-
dyn_cast<MetatypeInst>(inst->getOperand(4)->getDefiningInstruction());
168-
this->stringMetatype = stringMetatypeInst->getType();
166+
auto stringMetatype = inst->getOperand(4)->getType();
167+
assert(stringMetatype.isMetatype());
168+
this->stringMetatype = stringMetatype;
169169
}
170170

171171
bool isInitialized() { return stringInitIntrinsic != nullptr; }

test/SILOptimizer/OSLogMandatoryOptTest.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ bb0:
6666
return %13 : $()
6767
}
6868

69+
// CHECK-LABEL: @testConstantFoldingOfStructExtractMetatypeArg :
70+
// CHECK-DAG: [[STRINGUSE:%[0-9]+]] = function_ref @useFormatString
71+
// CHECK-DAG: {{%.*}} = apply [[STRINGUSE]]([[BORROW:%[0-9]+]])
72+
// CHECK-DAG: [[BORROW]] = begin_borrow [[STRINGCONST:%[0-9]+]]
73+
// CHECK-DAG: [[STRINGCONST]] = apply [[STRINGINIT:%[0-9]+]]([[LIT:%[0-9]+]], {{%.*}}, {{%.*}}, {{%.*}})
74+
// CHECK-DAG: [[STRINGINIT]] = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
75+
// CHECK-DAG: [[LIT]] = string_literal oslog "test message: %lld"
76+
// CHECK-DAG: destroy_value [[STRINGCONST]] : $String
77+
sil [ossa] @testConstantFoldingOfStructExtractMetatypeArg : $@convention(thin) (@thin String.Type) -> () {
78+
bb0(%0 : $@thin String.Type):
79+
%1 = string_literal utf8 "test message: %lld"
80+
%2 = integer_literal $Builtin.Word, 18
81+
%3 = integer_literal $Builtin.Int1, -1
82+
%4 = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
83+
%5 = apply %4(%1, %2, %3, %0) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
84+
%6 = function_ref @oslogMessageInit : $@convention(thin) (@owned String) -> @owned OSLogMessageStub
85+
%7 = apply %6(%5) : $@convention(thin) (@owned String) -> @owned OSLogMessageStub
86+
%8 = begin_borrow %7
87+
%9 = struct_extract %8, #OSLogMessageStub.interpolation
88+
%10 = struct_extract %9, #OSLogInterpolationStub.formatString
89+
%11 = function_ref @useFormatString : $@convention(thin) (@guaranteed String) -> ()
90+
%12 = apply %11(%10) : $@convention(thin) (@guaranteed String) -> ()
91+
end_borrow %8
92+
destroy_value %7
93+
%15 = tuple ()
94+
return %15
95+
}
96+
6997
/// A function that models the use of a string in some arbitrary way.
7098
sil @useFormatStringIndirect: $@convention(thin) (@in_guaranteed String) -> ()
7199

0 commit comments

Comments
 (0)