Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0374a38

Browse files
committedOct 24, 2024··
[WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial
TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recongnized as trivial.
1 parent 395093e commit 0374a38

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
 

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ class TrivialFunctionAnalysisVisitor
414414
Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
415415
Name == "isWebThread" || Name == "isUIThread" ||
416416
Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
417-
Name == "bitwise_cast" || Name.find("__builtin") == 0)
417+
Name == "bitwise_cast" || Name.find("__builtin") == 0 ||
418+
Name == "__libcpp_verbose_abort")
418419
return true;
419420

420421
return IsFunctionTrivial(Callee);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
#include "mock-types.h"
5+
6+
void __libcpp_verbose_abort(const char *__format, ...);
7+
8+
using size_t = __typeof(sizeof(int));
9+
namespace std{
10+
template <class T, size_t N>
11+
class array {
12+
T elements[N];
13+
14+
public:
15+
T& operator[](unsigned i) {
16+
if (i >= N) {
17+
__libcpp_verbose_abort("%s", "aborting");
18+
}
19+
return elements[i];
20+
}
21+
};
22+
}
23+
24+
class ArrayClass {
25+
public:
26+
void ref() const;
27+
void deref() const;
28+
typedef std::array<std::array<double, 4>, 4> Matrix;
29+
double e() { return matrix[3][0]; }
30+
Matrix matrix;
31+
};
32+
33+
class AnotherClass {
34+
RefPtr<ArrayClass> matrix;
35+
void test() {
36+
double val = { matrix->e()};
37+
}
38+
};
39+

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

+6
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ class SomeType : public BaseType {
238238
using BaseType::BaseType;
239239
};
240240

241+
void __libcpp_verbose_abort(const char *__format, ...);
242+
241243
class RefCounted {
242244
public:
243245
void ref() const;
@@ -361,6 +363,9 @@ class RefCounted {
361363
void trivial62() { WTFReportBacktrace(); }
362364
SomeType trivial63() { return SomeType(0); }
363365
SomeType trivial64() { return SomeType(); }
366+
void trivial65() {
367+
__libcpp_verbose_abort("%s", "aborting");
368+
}
364369

365370
static RefCounted& singleton() {
366371
static RefCounted s_RefCounted;
@@ -544,6 +549,7 @@ class UnrelatedClass {
544549
getFieldTrivial().trivial62(); // no-warning
545550
getFieldTrivial().trivial63(); // no-warning
546551
getFieldTrivial().trivial64(); // no-warning
552+
getFieldTrivial().trivial65(); // no-warning
547553

548554
RefCounted::singleton().trivial18(); // no-warning
549555
RefCounted::singleton().someFunction(); // no-warning

0 commit comments

Comments
 (0)
Please sign in to comment.