@@ -7479,6 +7479,14 @@ void CheckPrintfHandler::handleInvalidMaskType(StringRef MaskType) {
7479
7479
S.Diag(getLocationOfByte(MaskType.data()), diag::err_invalid_mask_type_size);
7480
7480
}
7481
7481
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
+
7482
7490
bool CheckPrintfHandler::HandleAmount(
7483
7491
const analyze_format_string::OptionalAmount &Amt, unsigned k,
7484
7492
const char *startSpecifier, unsigned specifierLen) {
@@ -7511,11 +7519,14 @@ bool CheckPrintfHandler::HandleAmount(
7511
7519
assert(AT.isValid());
7512
7520
7513
7521
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(),
7517
7528
getLocationOfByte(Amt.getStart()),
7518
- /*IsStringLocation*/true,
7529
+ /*IsStringLocation*/ true,
7519
7530
getSpecifierRange(startSpecifier, specifierLen));
7520
7531
// Don't do any more checking. We will just emit
7521
7532
// spurious errors.
@@ -8570,7 +8581,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
8570
8581
Diag = diag::warn_format_conversion_argument_type_mismatch_confusion;
8571
8582
break;
8572
8583
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;
8574
8587
break;
8575
8588
}
8576
8589
0 commit comments