-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[WebKit Checkers] Treat offsetof as a trivial expression. #126996
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
Conversation
@llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) ChangesFull diff: https://github.com/llvm/llvm-project/pull/126996.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d40b4b4dbb560..b823e048a4d10 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) 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<typename T>
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
|
@llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesFull diff: https://github.com/llvm/llvm-project/pull/126996.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d40b4b4dbb560..b823e048a4d10 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) 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<typename T>
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
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the review! |
No description provided.