[clang] [-Wunsafe-buffer-usage][NFC] Factor out FixitUtil (PR #135100)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 9 16:16:41 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Analysis/Support/FixitUtil.h clang/lib/Analysis/FixitUtil.cpp clang/lib/Analysis/UnsafeBufferUsage.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Analysis/Support/FixitUtil.h b/clang/include/clang/Analysis/Support/FixitUtil.h
index 1c52fe037..085c2255f 100644
--- a/clang/include/clang/Analysis/Support/FixitUtil.h
+++ b/clang/include/clang/Analysis/Support/FixitUtil.h
@@ -13,9 +13,8 @@
#include "clang/AST/Expr.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
-#include <string>
#include <optional>
-
+#include <string>
namespace clang {
@@ -38,25 +37,23 @@ getPointee2TypeText(const DeclaratorDecl *VD, const SourceManager &SM,
SourceLocation getBeginLocOfNestedIdentifier(const DeclaratorDecl *D);
// Returns the literal text in `SourceRange SR`, if `SR` is a valid range.
-std::optional<StringRef> getRangeText(SourceRange SR,
- const SourceManager &SM,
- const LangOptions &LangOpts);
+std::optional<StringRef> getRangeText(SourceRange SR, const SourceManager &SM,
+ const LangOptions &LangOpts);
// Returns the literal text of the identifier of the given variable declaration.
-std::optional<StringRef>
-getVarDeclIdentifierText(const DeclaratorDecl *VD, const SourceManager &SM,
- const LangOptions &LangOpts);
+std::optional<StringRef> getVarDeclIdentifierText(const DeclaratorDecl *VD,
+ const SourceManager &SM,
+ const LangOptions &LangOpts);
// Return text representation of an `Expr`.
-std::optional<StringRef> getExprText(const Expr *E,
- const SourceManager &SM,
- const LangOptions &LangOpts);
+std::optional<StringRef> getExprText(const Expr *E, const SourceManager &SM,
+ const LangOptions &LangOpts);
// Return the source location just past the last character of the AST `Node`.
template <typename NodeTy>
std::optional<SourceLocation> getPastLoc(const NodeTy *Node,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
SourceLocation Loc =
Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
if (Loc.isValid())
diff --git a/clang/lib/Analysis/FixitUtil.cpp b/clang/lib/Analysis/FixitUtil.cpp
index 8cef55189..4ac3f3acd 100644
--- a/clang/lib/Analysis/FixitUtil.cpp
+++ b/clang/lib/Analysis/FixitUtil.cpp
@@ -20,8 +20,8 @@ using namespace ast_matchers;
// output parameter `QualifiersToAppend`.
std::optional<std::string>
clang::getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM,
- const LangOptions &LangOpts,
- std::optional<Qualifiers> *QualifiersToAppend) {
+ const LangOptions &LangOpts,
+ std::optional<Qualifiers> *QualifiersToAppend) {
QualType Ty = VD->getType();
QualType PteTy;
@@ -183,21 +183,22 @@ SourceLocation clang::getBeginLocOfNestedIdentifier(const DeclaratorDecl *D) {
// Returns the literal text in `SourceRange SR`, if `SR` is a valid range.
std::optional<StringRef> clang::getRangeText(SourceRange SR,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
-bool Invalid = false;
-CharSourceRange CSR = CharSourceRange::getCharRange(SR);
-StringRef Text = Lexer::getSourceText(CSR, SM, LangOpts, &Invalid);
-
-if (!Invalid)
-return Text;
-return std::nullopt;
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ bool Invalid = false;
+ CharSourceRange CSR = CharSourceRange::getCharRange(SR);
+ StringRef Text = Lexer::getSourceText(CSR, SM, LangOpts, &Invalid);
+
+ if (!Invalid)
+ return Text;
+ return std::nullopt;
}
// Returns the literal text of the identifier of the given variable declaration.
std::optional<StringRef>
-clang::getVarDeclIdentifierText(const DeclaratorDecl *VD, const SourceManager &SM,
- const LangOptions &LangOpts) {
+clang::getVarDeclIdentifierText(const DeclaratorDecl *VD,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
SourceLocation ParmIdentBeginLoc = getBeginLocOfNestedIdentifier(VD);
SourceLocation ParmIdentEndLoc =
Lexer::getLocForEndOfToken(getVarDeclIdentifierLoc(VD), 0, SM, LangOpts);
@@ -214,16 +215,16 @@ clang::getVarDeclIdentifierText(const DeclaratorDecl *VD, const SourceManager &S
// Return text representation of an `Expr`.
std::optional<StringRef> clang::getExprText(const Expr *E,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
-std::optional<SourceLocation> LastCharLoc = getPastLoc(E, SM, LangOpts);
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ std::optional<SourceLocation> LastCharLoc = getPastLoc(E, SM, LangOpts);
-if (LastCharLoc)
-return Lexer::getSourceText(
-CharSourceRange::getCharRange(E->getBeginLoc(), *LastCharLoc), SM,
-LangOpts);
+ if (LastCharLoc)
+ return Lexer::getSourceText(
+ CharSourceRange::getCharRange(E->getBeginLoc(), *LastCharLoc), SM,
+ LangOpts);
-return std::nullopt;
+ return std::nullopt;
}
// Returns the begin location of the identifier of the given variable
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index a935e9067..0dbb68372 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
-#include "clang/Analysis/Support/FixitUtil.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTTypeTraits.h"
@@ -22,6 +21,7 @@
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Type.h"
#include "clang/ASTMatchers/LowLevelHelpers.h"
+#include "clang/Analysis/Support/FixitUtil.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
``````````
</details>
https://github.com/llvm/llvm-project/pull/135100
More information about the cfe-commits
mailing list