diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index d40b4b4dbb560..42597583ff178 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -503,6 +503,11 @@ class TrivialFunctionAnalysisVisitor return true; } + bool VisitOffsetOfExpr(const OffsetOfExpr *OE) { + // offsetof(T, D) is considered trivial. + return true; + } + bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) { if (!checkArguments(MCE)) return false; diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index ffeecbf87c451..cf403851b74fd 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -77,6 +77,8 @@ T&& forward(T& arg); template T&& move( T&& t ); +#define offsetof(t, d) __builtin_offsetof(t, d) + } // namespace std bool isMainThread(); @@ -373,6 +375,7 @@ class RefCounted { double y; }; void trivial68() { point pt = { 1.0 }; } + unsigned trivial69() { return offsetof(RefCounted, children); } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -560,6 +563,7 @@ class UnrelatedClass { getFieldTrivial().trivial66()->trivial6(); // no-warning getFieldTrivial().trivial67()->trivial6(); // no-warning getFieldTrivial().trivial68(); // no-warning + getFieldTrivial().trivial69(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning