Skip to content

Commit e6aae2a

Browse files
authored
[analyzer] Handle structured bindings in alpha.webkit.UncountedCallArgsChecker (#129424)
Simply add awareness of BindingDecl to the logic for identifying local assignments.
1 parent cf00ac8 commit e6aae2a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ bool tryToFindPtrOrigin(
140140
bool isASafeCallArg(const Expr *E) {
141141
assert(E);
142142
if (auto *Ref = dyn_cast<DeclRefExpr>(E)) {
143-
if (auto *D = dyn_cast_or_null<VarDecl>(Ref->getFoundDecl())) {
143+
auto *FoundDecl = Ref->getFoundDecl();
144+
if (auto *D = dyn_cast_or_null<VarDecl>(FoundDecl)) {
144145
if (isa<ParmVarDecl>(D) || D->isLocalVarDecl())
145146
return true;
147+
} else if (auto *BD = dyn_cast_or_null<BindingDecl>(FoundDecl)) {
148+
VarDecl *VD = BD->getHoldingVar();
149+
if (VD && (isa<ParmVarDecl>(VD) || VD->isLocalVarDecl()))
150+
return true;
146151
}
147152
}
148153
if (isConstOwnerPtrMemberExpr(E))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s -std=c++2c
2+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncheckedLocalVarsChecker -verify %s -std=c++2c
3+
4+
// expected-no-diagnostics
5+
6+
#include "mock-types.h"
7+
8+
class Node {
9+
public:
10+
Node* nextSibling() const;
11+
12+
void ref() const;
13+
void deref() const;
14+
};
15+
16+
template <class A, class B> struct pair {
17+
A a;
18+
B b;
19+
template <unsigned I> requires ( I == 0 ) A& get();
20+
template <unsigned I> requires ( I == 1 ) B& get();
21+
};
22+
23+
namespace std {
24+
template <class> struct tuple_size;
25+
template <unsigned, class> struct tuple_element;
26+
template <class A, class B> struct tuple_size<::pair<A, B>> { static constexpr int value = 2; };
27+
template <class A, class B> struct tuple_element<0, ::pair<A, B>> { using type = A; };
28+
template <class A, class B> struct tuple_element<1, ::pair<A, B>> { using type = B; };
29+
}
30+
31+
pair<RefPtr<Node>, RefPtr<Node>> &getPair();
32+
33+
static void testUnpackedAssignment() {
34+
auto [a, b] = getPair();
35+
a->nextSibling();
36+
}

0 commit comments

Comments
 (0)