[clang] [WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial (PR #113377)
Rashmi Mudduluru via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 22 13:18:00 PDT 2024
https://github.com/t-rasmud created https://github.com/llvm/llvm-project/pull/113377
TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recongnized as trivial.
>From 9e21b0f2f0968a5f8810c797913318884dcc8c7b Mon Sep 17 00:00:00 2001
From: Rashmi Mudduluru <r_mudduluru at apple.com>
Date: Tue, 22 Oct 2024 13:16:30 -0700
Subject: [PATCH] [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.
---
.../Checkers/WebKit/PtrTypesSemantics.cpp | 3 +-
.../WebKit/uncounted-obj-arg-std-array.cpp | 33 +++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
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..43c76c0b0793a8
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+using size_t = __typeof(sizeof(int));
+namespace std{
+template <class T, size_t N>
+class array {
+ T elements[N];
+
+ public:
+ T& operator[](unsigned i) { return elements[i]; }
+ constexpr const T* data() const noexcept {
+ return elements;
+ }
+
+};
+}
+
+class ArrayClass {
+public:
+ typedef std::array<std::array<double, 4>, 4> Matrix;
+ double e() { return matrix[3][0]; }
+ Matrix matrix;
+};
+
+class AnotherClass {
+ Ref<ArrayClass> matrix;
+ void test() {
+ double val[] = { matrix->e(), matrix->e() };
+ }
+};
More information about the cfe-commits
mailing list