@@ -7479,6 +7479,14 @@ void CheckPrintfHandler::handleInvalidMaskType(StringRef MaskType) {
74797479 S.Diag(getLocationOfByte(MaskType.data()), diag::err_invalid_mask_type_size);
74807480}
74817481
7482+ // Error out if struct or complex type argments are passed to os_log.
7483+ static bool isInvalidOSLogArgTypeForCodeGen(FormatStringType FSType,
7484+ QualType T) {
7485+ if (FSType != FormatStringType::OSLog)
7486+ return false;
7487+ return T->isRecordType() || T->isComplexType();
7488+ }
7489+
74827490bool CheckPrintfHandler::HandleAmount(
74837491 const analyze_format_string::OptionalAmount &Amt, unsigned k,
74847492 const char *startSpecifier, unsigned specifierLen) {
@@ -7511,11 +7519,14 @@ bool CheckPrintfHandler::HandleAmount(
75117519 assert(AT.isValid());
75127520
75137521 if (!AT.matchesType(S.Context, T)) {
7514- EmitFormatDiagnostic(S.PDiag(diag::warn_printf_asterisk_wrong_type)
7515- << k << AT.getRepresentativeTypeName(S.Context)
7516- << T << Arg->getSourceRange(),
7522+ unsigned DiagID = isInvalidOSLogArgTypeForCodeGen(FSType, T)
7523+ ? diag::err_printf_asterisk_wrong_type
7524+ : diag::warn_printf_asterisk_wrong_type;
7525+ EmitFormatDiagnostic(S.PDiag(DiagID)
7526+ << k << AT.getRepresentativeTypeName(S.Context)
7527+ << T << Arg->getSourceRange(),
75177528 getLocationOfByte(Amt.getStart()),
7518- /*IsStringLocation*/true,
7529+ /*IsStringLocation*/ true,
75197530 getSpecifierRange(startSpecifier, specifierLen));
75207531 // Don't do any more checking. We will just emit
75217532 // spurious errors.
@@ -8570,7 +8581,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
85708581 Diag = diag::warn_format_conversion_argument_type_mismatch_confusion;
85718582 break;
85728583 case ArgType::NoMatch:
8573- Diag = diag::warn_format_conversion_argument_type_mismatch;
8584+ Diag = isInvalidOSLogArgTypeForCodeGen(FSType, ExprTy)
8585+ ? diag::err_format_conversion_argument_type_mismatch
8586+ : diag::warn_format_conversion_argument_type_mismatch;
85748587 break;
85758588 }
85768589
0 commit comments