@@ -7673,6 +7673,14 @@ void CheckPrintfHandler::handleInvalidMaskType(StringRef MaskType) {
7673
7673
S.Diag(getLocationOfByte(MaskType.data()), diag::err_invalid_mask_type_size);
7674
7674
}
7675
7675
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
+
7676
7684
bool CheckPrintfHandler::HandleAmount(
7677
7685
const analyze_format_string::OptionalAmount &Amt, unsigned k,
7678
7686
const char *startSpecifier, unsigned specifierLen) {
@@ -7705,11 +7713,14 @@ bool CheckPrintfHandler::HandleAmount(
7705
7713
assert(AT.isValid());
7706
7714
7707
7715
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(),
7711
7722
getLocationOfByte(Amt.getStart()),
7712
- /*IsStringLocation*/true,
7723
+ /*IsStringLocation*/ true,
7713
7724
getSpecifierRange(startSpecifier, specifierLen));
7714
7725
// Don't do any more checking. We will just emit
7715
7726
// spurious errors.
@@ -8764,7 +8775,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
8764
8775
Diag = diag::warn_format_conversion_argument_type_mismatch_confusion;
8765
8776
break;
8766
8777
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;
8768
8781
break;
8769
8782
}
8770
8783
0 commit comments