From: Seth Cantrell Date: Wed, 4 Mar 2015 05:58:08 +0000 (+0000) Subject: AT.isValid() should come before AT.matchesType() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cb60abfa2b035a713482f3d01b9c2f5f5373b26;p=clang AT.isValid() should come before AT.matchesType() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231213 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 72cb6003f5..6b569b6375 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4036,41 +4036,47 @@ bool CheckScanfHandler::HandleScanfSpecifier( return true; const analyze_format_string::ArgType &AT = FS.getArgType(S.Context); + + if (!AT.isValid()) { + return true; + } + analyze_format_string::ArgType::MatchKind match = AT.matchesType(S.Context, Ex->getType()); - if (AT.isValid() && match != analyze_format_string::ArgType::Match) { - ScanfSpecifier fixedFS = FS; - bool success = - fixedFS.fixType(Ex->getType(), Ex->IgnoreImpCasts()->getType(), - S.getLangOpts(), S.Context); + if (match == analyze_format_string::ArgType::Match) { + return true; + } - unsigned diag = diag::warn_format_conversion_argument_type_mismatch; - if (match == analyze_format_string::ArgType::NoMatchPedantic) { - diag = diag::warn_format_conversion_argument_type_mismatch_pedantic; - } + ScanfSpecifier fixedFS = FS; + bool success = fixedFS.fixType(Ex->getType(), Ex->IgnoreImpCasts()->getType(), + S.getLangOpts(), S.Context); - if (success) { - // Get the fix string from the fixed format specifier. - SmallString<128> buf; - llvm::raw_svector_ostream os(buf); - fixedFS.toString(os); + unsigned diag = diag::warn_format_conversion_argument_type_mismatch; + if (match == analyze_format_string::ArgType::NoMatchPedantic) { + diag = diag::warn_format_conversion_argument_type_mismatch_pedantic; + } - EmitFormatDiagnostic( - S.PDiag(diag) << AT.getRepresentativeTypeName(S.Context) - << Ex->getType() << false << Ex->getSourceRange(), - Ex->getLocStart(), - /*IsStringLocation*/ false, - getSpecifierRange(startSpecifier, specifierLen), - FixItHint::CreateReplacement( - getSpecifierRange(startSpecifier, specifierLen), os.str())); - } else { - EmitFormatDiagnostic( - S.PDiag(diag) << AT.getRepresentativeTypeName(S.Context) - << Ex->getType() << false << Ex->getSourceRange(), - Ex->getLocStart(), - /*IsStringLocation*/ false, - getSpecifierRange(startSpecifier, specifierLen)); - } + if (success) { + // Get the fix string from the fixed format specifier. + SmallString<128> buf; + llvm::raw_svector_ostream os(buf); + fixedFS.toString(os); + + EmitFormatDiagnostic( + S.PDiag(diag) << AT.getRepresentativeTypeName(S.Context) + << Ex->getType() << false << Ex->getSourceRange(), + Ex->getLocStart(), + /*IsStringLocation*/ false, + getSpecifierRange(startSpecifier, specifierLen), + FixItHint::CreateReplacement( + getSpecifierRange(startSpecifier, specifierLen), os.str())); + } else { + EmitFormatDiagnostic(S.PDiag(diag) + << AT.getRepresentativeTypeName(S.Context) + << Ex->getType() << false << Ex->getSourceRange(), + Ex->getLocStart(), + /*IsStringLocation*/ false, + getSpecifierRange(startSpecifier, specifierLen)); } return true;