@@ -7673,6 +7673,14 @@ void CheckPrintfHandler::handleInvalidMaskType(StringRef MaskType) {
76737673 S.Diag(getLocationOfByte(MaskType.data()), diag::err_invalid_mask_type_size);
76747674}
76757675
7676+ // Error out if struct or complex type argments are passed to os_log.
7677+ static bool isInvalidOSLogArgTypeForCodeGen(FormatStringType FSType,
7678+ QualType T) {
7679+ if (FSType != FormatStringType::OSLog)
7680+ return false;
7681+ return T->isRecordType() || T->isComplexType();
7682+ }
7683+
76767684bool CheckPrintfHandler::HandleAmount(
76777685 const analyze_format_string::OptionalAmount &Amt, unsigned k,
76787686 const char *startSpecifier, unsigned specifierLen) {
@@ -7705,11 +7713,14 @@ bool CheckPrintfHandler::HandleAmount(
77057713 assert(AT.isValid());
77067714
77077715 if (!AT.matchesType(S.Context, T)) {
7708- EmitFormatDiagnostic(S.PDiag(diag::warn_printf_asterisk_wrong_type)
7709- << k << AT.getRepresentativeTypeName(S.Context)
7710- << T << Arg->getSourceRange(),
7716+ unsigned DiagID = isInvalidOSLogArgTypeForCodeGen(FSType, T)
7717+ ? diag::err_printf_asterisk_wrong_type
7718+ : diag::warn_printf_asterisk_wrong_type;
7719+ EmitFormatDiagnostic(S.PDiag(DiagID)
7720+ << k << AT.getRepresentativeTypeName(S.Context)
7721+ << T << Arg->getSourceRange(),
77117722 getLocationOfByte(Amt.getStart()),
7712- /*IsStringLocation*/true,
7723+ /*IsStringLocation*/ true,
77137724 getSpecifierRange(startSpecifier, specifierLen));
77147725 // Don't do any more checking. We will just emit
77157726 // spurious errors.
@@ -8764,7 +8775,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
87648775 Diag = diag::warn_format_conversion_argument_type_mismatch_confusion;
87658776 break;
87668777 case ArgType::NoMatch:
8767- Diag = diag::warn_format_conversion_argument_type_mismatch;
8778+ Diag = isInvalidOSLogArgTypeForCodeGen(FSType, ExprTy)
8779+ ? diag::err_format_conversion_argument_type_mismatch
8780+ : diag::warn_format_conversion_argument_type_mismatch;
87688781 break;
87698782 }
87708783
0 commit comments