Skip to content

Commit

Permalink
[WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::…
Browse files Browse the repository at this point in the history
…operator[] as trivial (llvm#113377)

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing `std::array::operator[]` also not being recognized as trivial.
  • Loading branch information
t-rasmud authored Oct 24, 2024
1 parent 1184458 commit a291f00
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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
Expand Up @@ -238,6 +238,8 @@ class SomeType : public BaseType {
using BaseType::BaseType;
};

void __libcpp_verbose_abort(const char *__format, ...);

class RefCounted {
public:
void ref() const;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a291f00

Please sign in to comment.