[clang] a291f00 - [WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial (#113377)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 24 14:23:32 PDT 2024
Author: Rashmi Mudduluru
Date: 2024-10-24T14:23:29-07:00
New Revision: a291f00edaeeea622a9e3e2c706e3bdb25f93f09
URL: https://github.com/llvm/llvm-project/commit/a291f00edaeeea622a9e3e2c706e3bdb25f93f09
DIFF: https://github.com/llvm/llvm-project/commit/a291f00edaeeea622a9e3e2c706e3bdb25f93f09.diff
LOG: [WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial (#113377)
TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recognized as trivial.
Added:
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index e043806eadd6ac..71440e6d08a1c9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -414,7 +414,8 @@ class TrivialFunctionAnalysisVisitor
Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
Name == "isWebThread" || Name == "isUIThread" ||
Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
- Name == "bitwise_cast" || Name.find("__builtin") == 0)
+ Name == "bitwise_cast" || Name.find("__builtin") == 0 ||
+ Name == "__libcpp_verbose_abort")
return true;
return IsFunctionTrivial(Callee);
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
new file mode 100644
index 00000000000000..ed28a64bba059c
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+void __libcpp_verbose_abort(const char *__format, ...);
+
+using size_t = __typeof(sizeof(int));
+namespace std{
+template <class T, size_t N>
+class array {
+ T elements[N];
+
+ public:
+ T& operator[](unsigned i) {
+ if (i >= N) {
+ __libcpp_verbose_abort("%s", "aborting");
+ }
+ return elements[i];
+ }
+};
+}
+
+class ArrayClass {
+public:
+ void ref() const;
+ void deref() const;
+ typedef std::array<std::array<double, 4>, 4> Matrix;
+ double e() { return matrix[3][0]; }
+ Matrix matrix;
+};
+
+class AnotherClass {
+ RefPtr<ArrayClass> matrix;
+ void test() {
+ double val = { matrix->e()};
+ }
+};
+
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 10da776f81575c..e1dacdd9e25b6d 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -238,6 +238,8 @@ class SomeType : public BaseType {
using BaseType::BaseType;
};
+void __libcpp_verbose_abort(const char *__format, ...);
+
class RefCounted {
public:
void ref() const;
@@ -361,6 +363,9 @@ class RefCounted {
void trivial62() { WTFReportBacktrace(); }
SomeType trivial63() { return SomeType(0); }
SomeType trivial64() { return SomeType(); }
+ void trivial65() {
+ __libcpp_verbose_abort("%s", "aborting");
+ }
static RefCounted& singleton() {
static RefCounted s_RefCounted;
@@ -544,6 +549,7 @@ class UnrelatedClass {
getFieldTrivial().trivial62(); // no-warning
getFieldTrivial().trivial63(); // no-warning
getFieldTrivial().trivial64(); // no-warning
+ getFieldTrivial().trivial65(); // no-warning
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
More information about the cfe-commits
mailing list