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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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()};
}
};

6 changes: 6 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading