Skip to content

[WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial #113377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

t-rasmud
Copy link
Contributor

TFA wasn't recognizing __libcpp_verbose_abort as trivial causing std::array::operator[] also not being recongnized as trivial.

@t-rasmud t-rasmud requested a review from rniwa October 22, 2024 20:17
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Oct 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Rashmi Mudduluru (t-rasmud)

Changes

TFA wasn't recognizing __libcpp_verbose_abort as trivial causing std::array::operator[] also not being recongnized as trivial.


Full diff: https://github.com/llvm/llvm-project/pull/113377.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+2-1)
  • (added) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp (+33)
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() };
+    }
+};

Unverified

The signing certificate or its chain could not be verified.
…operator[] as trivial

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recongnized as trivial.
@t-rasmud t-rasmud merged commit a291f00 into llvm:main Oct 24, 2024
8 checks passed
@frobtech frobtech mentioned this pull request Oct 25, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…operator[] as trivial (llvm#113377)

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recognized as trivial.
rniwa pushed a commit to rniwa/llvm-project that referenced this pull request Feb 3, 2025
…operator[] as trivial (llvm#113377)

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recognized as trivial.
devincoughlin pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 25, 2025
…operator[] as trivial (llvm#113377)

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recognized as trivial.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants