llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Sergei Barannikov (s-barannikov) <details> <summary>Changes</summary> `DecomposePrintfHandler::HandlePrintfSpecifier()` parses the format string and collects specifiers into `Specs`. In most cases the collected specifiers are in the execution encoding, but there were to places that used string literals in "host" encoding. Change them to use a part of the parsed `StringLiteral` instead so that `Specs` always contain text in the execution encoding. This is achieved by adding `getCharacters()` method to `OptionalAmount` class, following `ConversionSpecifier::getCharacters()`. This is to make #<!-- -->169803 smaller and is an NFC before that PR lands. --- Full diff: https://github.com/llvm/llvm-project/pull/195876.diff 2 Files Affected: - (modified) clang/include/clang/AST/FormatString.h (+4) - (modified) clang/lib/Sema/SemaChecking.cpp (+11-11) ``````````diff diff --git a/clang/include/clang/AST/FormatString.h b/clang/include/clang/AST/FormatString.h index 586d9f0f8feb0..a3382e1a1d007 100644 --- a/clang/include/clang/AST/FormatString.h +++ b/clang/include/clang/AST/FormatString.h @@ -396,6 +396,10 @@ class OptionalAmount { return length + UsesDotPrefix; } + StringRef getCharacters() const { + return StringRef(start - UsesDotPrefix, length + UsesDotPrefix); + } + ArgType getArgType(ASTContext &Ctx) const; void toString(raw_ostream &os) const; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 12f77d021eb0d..4706fa5d3cde0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -8707,16 +8707,16 @@ bool DecomposePrintfHandler::HandlePrintfSpecifier( const auto &FieldWidth = FS.getFieldWidth(); if (!FieldWidth.isInvalid() && FieldWidth.hasDataArgument()) { FieldWidthIndex = Specs.size(); - Specs.emplace_back(getSpecifierRange(startSpecifier, specifierLen), - getLocationOfByte(FieldWidth.getStart()), - analyze_format_string::LengthModifier::None, "*", - FieldWidth.getArgType(S.Context), - EquatableFormatArgument::FAR_FieldWidth, - EquatableFormatArgument::SS_None, - FieldWidth.usesPositionalArg() - ? FieldWidth.getPositionalArgIndex() - 1 - : FieldWidthIndex, - 0); + Specs.emplace_back( + getSpecifierRange(startSpecifier, specifierLen), + getLocationOfByte(FieldWidth.getStart()), + analyze_format_string::LengthModifier::None, FieldWidth.getCharacters(), + FieldWidth.getArgType(S.Context), + EquatableFormatArgument::FAR_FieldWidth, + EquatableFormatArgument::SS_None, + FieldWidth.usesPositionalArg() ? FieldWidth.getPositionalArgIndex() - 1 + : FieldWidthIndex, + 0); } // precision? const auto &Precision = FS.getPrecision(); @@ -8725,7 +8725,7 @@ bool DecomposePrintfHandler::HandlePrintfSpecifier( Specs.emplace_back( getSpecifierRange(startSpecifier, specifierLen), getLocationOfByte(Precision.getStart()), - analyze_format_string::LengthModifier::None, ".*", + analyze_format_string::LengthModifier::None, Precision.getCharacters(), Precision.getArgType(S.Context), EquatableFormatArgument::FAR_Precision, EquatableFormatArgument::SS_None, Precision.usesPositionalArg() ? Precision.getPositionalArgIndex() - 1 `````````` </details> https://github.com/llvm/llvm-project/pull/195876 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
