Skip to content

Commit 8f9f5ff

Browse files
committed
[alpha.webkit.UncountedCallArgsChecker] Allow a variable declaration in a trivial function.
1 parent d9f9775 commit 8f9f5ff

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,11 @@ class TrivialFunctionAnalysisVisitor
309309
return true;
310310
if (isa<EnumConstantDecl>(decl))
311311
return true;
312-
if (auto *VD = dyn_cast<VarDecl>(decl))
313-
return VD->hasConstantInitialization() && VD->getEvaluatedValue();
312+
if (auto *VD = dyn_cast<VarDecl>(decl)) {
313+
if (VD->hasConstantInitialization() && VD->getEvaluatedValue())
314+
return true;
315+
return Visit(VD->getInit());
316+
}
314317
}
315318
return false;
316319
}

clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class RefCounted {
199199
bool trivial23() const { return OptionSet<Flags>::fromRaw(v).contains(Flags::Flag1); }
200200
int trivial24() const { ASSERT(v); return v; }
201201
unsigned trivial25() const { return __c11_atomic_load((volatile _Atomic(unsigned) *)&v, __ATOMIC_RELAXED); }
202+
bool trivial26() { bool hasValue = v; return !hasValue; }
202203

203204
static RefCounted& singleton() {
204205
static RefCounted s_RefCounted;
@@ -262,6 +263,15 @@ class RefCounted {
262263
return __c11_atomic_load((volatile _Atomic(unsigned) *)another(), __ATOMIC_RELAXED);
263264
}
264265

266+
void nonTrivial11() {
267+
Number num(0.3);
268+
}
269+
270+
bool nonTrivial12() {
271+
bool val = otherFunction();
272+
return val;
273+
}
274+
265275
unsigned v { 0 };
266276
Number* number { nullptr };
267277
Enum enumValue { Enum::Value1 };
@@ -309,6 +319,7 @@ class UnrelatedClass {
309319
getFieldTrivial().trivial23(); // no-warning
310320
getFieldTrivial().trivial24(); // no-warning
311321
getFieldTrivial().trivial25(); // no-warning
322+
getFieldTrivial().trivial26(); // no-warning
312323
RefCounted::singleton().trivial18(); // no-warning
313324
RefCounted::singleton().someFunction(); // no-warning
314325

@@ -334,6 +345,10 @@ class UnrelatedClass {
334345
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
335346
getFieldTrivial().nonTrivial10();
336347
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
348+
getFieldTrivial().nonTrivial11();
349+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
350+
getFieldTrivial().nonTrivial12();
351+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
337352
}
338353
};
339354

0 commit comments

Comments
 (0)