Skip to content

Commit 18f60bc

Browse files
authored
[WebKit Checkers] Treat offsetof as a trivial expression. (#126996)
1 parent 344058d commit 18f60bc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ class TrivialFunctionAnalysisVisitor
503503
return true;
504504
}
505505

506+
bool VisitOffsetOfExpr(const OffsetOfExpr *OE) {
507+
// offsetof(T, D) is considered trivial.
508+
return true;
509+
}
510+
506511
bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
507512
if (!checkArguments(MCE))
508513
return false;

clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ T&& forward(T& arg);
7777
template<typename T>
7878
T&& move( T&& t );
7979

80+
#define offsetof(t, d) __builtin_offsetof(t, d)
81+
8082
} // namespace std
8183

8284
bool isMainThread();
@@ -373,6 +375,7 @@ class RefCounted {
373375
double y;
374376
};
375377
void trivial68() { point pt = { 1.0 }; }
378+
unsigned trivial69() { return offsetof(RefCounted, children); }
376379

377380
static RefCounted& singleton() {
378381
static RefCounted s_RefCounted;
@@ -560,6 +563,7 @@ class UnrelatedClass {
560563
getFieldTrivial().trivial66()->trivial6(); // no-warning
561564
getFieldTrivial().trivial67()->trivial6(); // no-warning
562565
getFieldTrivial().trivial68(); // no-warning
566+
getFieldTrivial().trivial69(); // no-warning
563567

564568
RefCounted::singleton().trivial18(); // no-warning
565569
RefCounted::singleton().someFunction(); // no-warning

0 commit comments

Comments
 (0)