[clang] [-Wunsafe-buffer-usage][NFC] Add testcase for not-unsafe pointer (PR #80076)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 30 15:08:17 PST 2024
https://github.com/jkorous-apple created https://github.com/llvm/llvm-project/pull/80076
None
>From dcc2b0c07681b57dbd5a82ce83f5166bb3b9ee09 Mon Sep 17 00:00:00 2001
From: Jan Korous <jkorous at apple.com>
Date: Wed, 24 Jan 2024 15:02:55 -0800
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Fix AST matcher of
UUCAddAssignGadget
We are not interested in nonpointers being added to.
---
clang/lib/Analysis/UnsafeBufferUsage.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 7df706beb2266..9046491c9e865 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1081,11 +1081,16 @@ class UUCAddAssignGadget : public FixableGadget {
}
static Matcher matcher() {
+ // clang-format off
return stmt(isInUnspecifiedUntypedContext(expr(ignoringImpCasts(
binaryOperator(hasOperatorName("+="),
- hasLHS(declRefExpr(toSupportedVariable())),
+ hasLHS(
+ declRefExpr(
+ hasPointerType(),
+ toSupportedVariable())),
hasRHS(expr().bind(OffsetTag)))
.bind(UUCAddAssignTag)))));
+ // clang-format on
}
virtual std::optional<FixItList> getFixits(const Strategy &S) const override;
>From 857fff202648b18eaf95acd6004508445fcbfc63 Mon Sep 17 00:00:00 2001
From: Jan Korous <jkorous at apple.com>
Date: Wed, 24 Jan 2024 17:28:07 -0800
Subject: [PATCH 2/2] [-Wunsafe-buffer-usage][NFC] Add testcase for not-unsafe
pointer
---
.../SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp
index 20d9d33195a6b..d1dd26795ba68 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp
@@ -85,6 +85,7 @@ void unsafe_method_invocation_single_param() {
void safe_method_invocation_single_param() {
int* p = new int[10];
+ // CHECK-NO: fix-it:"{{.*}}":{[[@LINE-1]]:{{.*}}-[[@LINE-1]]:{{.*}}}
foo(p);
}
More information about the cfe-commits
mailing list