@@ -7234,9 +7234,11 @@ void EquatableFormatArgument::VerifyCompatible(
72347234
72357235 switch (ArgType.matchesArgType(S.Context, Other.ArgType)) {
72367236 case MK::Match:
7237- case MK::MatchPromotion:
72387237 break;
72397238
7239+ case MK::MatchPromotion:
7240+ // Per consensus reached at https://discourse.llvm.org/t/-/83076/12,
7241+ // MatchPromotion is treated as a failure by format_matches.
72407242 case MK::NoMatch:
72417243 case MK::NoMatchTypeConfusion:
72427244 case MK::NoMatchPromotionTypeConfusion:
@@ -8225,36 +8227,6 @@ class CheckScanfHandler : public CheckFormatHandler {
82258227 void HandleIncompleteScanList(const char *start, const char *end) override;
82268228};
82278229
8228- class DecomposeScanfHandler : public CheckScanfHandler {
8229- llvm::SmallVectorImpl<EquatableFormatArgument> &Specs;
8230- bool HadError;
8231-
8232- DecomposeScanfHandler(Sema &s, const FormatStringLiteral *fexpr,
8233- const Expr *origFormatExpr, Sema::FormatStringType type,
8234- unsigned firstDataArg, unsigned numDataArgs,
8235- const char *beg, Sema::FormatArgumentPassingKind APK,
8236- ArrayRef<const Expr *> Args, unsigned formatIdx,
8237- bool inFunctionCall, Sema::VariadicCallType CallType,
8238- llvm::SmallBitVector &CheckedVarArgs,
8239- UncoveredArgHandler &UncoveredArg,
8240- llvm::SmallVectorImpl<EquatableFormatArgument> &Specs)
8241- : CheckScanfHandler(s, fexpr, origFormatExpr, type, firstDataArg,
8242- numDataArgs, beg, APK, Args, formatIdx,
8243- inFunctionCall, CallType, CheckedVarArgs,
8244- UncoveredArg),
8245- Specs(Specs), HadError(false) {}
8246-
8247- public:
8248- static bool
8249- GetSpecifiers(Sema &S, const FormatStringLiteral *FSL,
8250- Sema::FormatStringType type, bool InFunctionCall,
8251- llvm::SmallVectorImpl<EquatableFormatArgument> &Args);
8252-
8253- bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
8254- const char *startSpecifier,
8255- unsigned specifierLen) override;
8256- };
8257-
82588230} // namespace
82598231
82608232void CheckScanfHandler::HandleIncompleteScanList(const char *start,
@@ -8401,53 +8373,6 @@ bool CheckScanfHandler::HandleScanfSpecifier(
84018373 return true;
84028374}
84038375
8404- bool DecomposeScanfHandler::GetSpecifiers(
8405- Sema &S, const FormatStringLiteral *FSL, Sema::FormatStringType Type,
8406- bool InFunctionCall, llvm::SmallVectorImpl<EquatableFormatArgument> &Args) {
8407- StringRef Data = FSL->getString();
8408- const char *Str = Data.data();
8409- llvm::SmallBitVector BV;
8410- UncoveredArgHandler UA;
8411- DecomposeScanfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, Str,
8412- Sema::FAPK_Elsewhere, {FSL->getFormatString()}, 0,
8413- InFunctionCall, Sema::VariadicDoesNotApply, BV, UA,
8414- Args);
8415-
8416- if (!analyze_format_string::ParseScanfString(H, Str, Str + Data.size(),
8417- S.getLangOpts(),
8418- S.Context.getTargetInfo()))
8419- H.DoneProcessing();
8420- if (H.HadError)
8421- return false;
8422-
8423- std::sort(
8424- Args.begin(), Args.end(),
8425- [](const EquatableFormatArgument &A, const EquatableFormatArgument &B) {
8426- return A.getPosition() < B.getPosition();
8427- });
8428- return true;
8429- }
8430-
8431- bool DecomposeScanfHandler::HandleScanfSpecifier(
8432- const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
8433- unsigned specifierLen) {
8434- if (!CheckScanfHandler::HandleScanfSpecifier(FS, startSpecifier,
8435- specifierLen)) {
8436- HadError = true;
8437- return false;
8438- }
8439-
8440- const auto &CS = FS.getConversionSpecifier();
8441- Specs.emplace_back(
8442- getSpecifierRange(startSpecifier, specifierLen),
8443- getLocationOfByte(CS.getStart()), FS.getLengthModifier().getKind(),
8444- CS.getCharacters(), FS.getArgType(S.Context),
8445- EquatableFormatArgument::FAR_Data, EquatableFormatArgument::SS_None,
8446- FS.usesPositionalArg() ? FS.getPositionalArgIndex() - 1 : Specs.size(),
8447- 0);
8448- return true;
8449- }
8450-
84518376static void CompareFormatSpecifiers(Sema &S, const StringLiteral *Ref,
84528377 ArrayRef<EquatableFormatArgument> RefArgs,
84538378 const StringLiteral *Fmt,
@@ -8556,26 +8481,13 @@ static void CheckFormatString(
85568481 }
85578482 }
85588483 } else if (Type == Sema::FST_Scanf) {
8559- if (ReferenceFormatString == nullptr) {
8560- CheckScanfHandler H(S, FExpr, OrigFormatExpr, Type, firstDataArg,
8561- numDataArgs, Str, APK, Args, format_idx,
8562- inFunctionCall, CallType, CheckedVarArgs,
8563- UncoveredArg);
8484+ CheckScanfHandler H(S, FExpr, OrigFormatExpr, Type, firstDataArg,
8485+ numDataArgs, Str, APK, Args, format_idx, inFunctionCall,
8486+ CallType, CheckedVarArgs, UncoveredArg);
85648487
8565- if (!analyze_format_string::ParseScanfString(
8566- H, Str, Str + StrLen, S.getLangOpts(), S.Context.getTargetInfo()))
8567- H.DoneProcessing();
8568- } else {
8569- llvm::SmallVector<EquatableFormatArgument, 9> RefArgs, FmtArgs;
8570- FormatStringLiteral RefLit = ReferenceFormatString;
8571- if (DecomposeScanfHandler::GetSpecifiers(S, &RefLit, Type, inFunctionCall,
8572- RefArgs) &&
8573- DecomposeScanfHandler::GetSpecifiers(S, FExpr, Type, inFunctionCall,
8574- FmtArgs)) {
8575- CompareFormatSpecifiers(S, ReferenceFormatString, RefArgs,
8576- FExpr->getFormatString(), FmtArgs);
8577- }
8578- }
8488+ if (!analyze_format_string::ParseScanfString(
8489+ H, Str, Str + StrLen, S.getLangOpts(), S.Context.getTargetInfo()))
8490+ H.DoneProcessing();
85798491 } // TODO: handle other formats
85808492}
85818493
0 commit comments