-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. #91830
Merged
rniwa
merged 5 commits into
llvm:main
from
rniwa:treat-bitwise-cast-addressof-new-as-trivial
May 11, 2024
Merged
[analyzer] Treat bitwise_cast, std::addressof, and new as trivial in WebKit checkers. #91830
rniwa
merged 5 commits into
llvm:main
from
rniwa:treat-bitwise-cast-addressof-new-as-trivial
May 11, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
clang
Clang issues not falling into any other category
clang:static analyzer
labels
May 11, 2024
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesFull diff: https://github.com/llvm/llvm-project/pull/91830.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 3abfa4cbb295d..23d97819a8bcd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -351,7 +351,8 @@ class TrivialFunctionAnalysisVisitor
if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
Name == "WTFReportAssertionFailure" ||
- Name == "compilerFenceForCrash" || Name.find("__builtin") == 0)
+ Name == "compilerFenceForCrash" || Name == "bitwise_cast" ||
+ Name == "addressof" || Name.find("__builtin") == 0)
return true;
return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
@@ -428,6 +429,10 @@ class TrivialFunctionAnalysisVisitor
return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
}
+ bool VisitCXXNewExpr(const CXXNewExpr* NE) {
+ return VisitChildren(NE);
+ }
+
bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
return Visit(ICE->getSubExpr());
}
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 6ca7677511d73..197b2ee8a7359 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -47,6 +47,12 @@ void isIntegralOrPointerType(T, Types... types)
void WTFCrashWithInfoImpl(int line, const char* file, const char* function, int counter, unsigned long reason);
void WTFCrashWithInfo(int line, const char* file, const char* function, int counter);
+template<typename ToType, typename FromType>
+ToType bitwise_cast(FromType from);
+
+template<typename T>
+T* addressof(T& arg);
+
template<typename T>
ALWAYS_INLINE unsigned long wtfCrashArg(T* arg) { return reinterpret_cast<unsigned long>(arg); }
@@ -234,6 +240,11 @@ class RefCounted {
void trivial38() { v++; if (__builtin_expect(!!(number), 1)) (*number)++; }
int trivial39() { return -v; }
int trivial40() { return v << 2; }
+ unsigned trivial41() { v = ++s_v; return v; }
+ unsigned trivial42() { return bitwise_cast<unsigned long>(nullptr); }
+ Number* trivial43() { return addressof(*number); }
+ Number* trivial44() { return new Number(1); }
+ ComplexNumber* trivial45() { return new ComplexNumber(); }
static RefCounted& singleton() {
static RefCounted s_RefCounted;
@@ -312,13 +323,17 @@ class RefCounted {
void nonTrivial16() { complex++; }
ComplexNumber nonTrivial17() { return complex << 2; }
ComplexNumber nonTrivial18() { return +complex; }
+ ComplexNumber* nonTrivial19() { return new ComplexNumber(complex); }
+ static unsigned s_v;
unsigned v { 0 };
Number* number { nullptr };
ComplexNumber complex;
Enum enumValue { Enum::Value1 };
};
+unsigned RefCounted::s_v = 0;
+
RefCounted* refCountedObj();
void test()
@@ -377,6 +392,11 @@ class UnrelatedClass {
getFieldTrivial().trivial38(); // no-warning
getFieldTrivial().trivial39(); // no-warning
getFieldTrivial().trivial40(); // no-warning
+ getFieldTrivial().trivial41(); // no-warning
+ getFieldTrivial().trivial42(); // no-warning
+ getFieldTrivial().trivial43(); // no-warning
+ getFieldTrivial().trivial44(); // no-warning
+ getFieldTrivial().trivial45(); // no-warning
RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
@@ -419,6 +439,8 @@ class UnrelatedClass {
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
getFieldTrivial().nonTrivial18();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
+ getFieldTrivial().nonTrivial19();
+ // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}
};
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
haoNoQ
approved these changes
May 11, 2024
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!
haoNoQ
approved these changes
May 11, 2024
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
May 25, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Sep 6, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Sep 11, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Sep 18, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Sep 27, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Oct 30, 2024
…WebKit checkers. (llvm#91830)
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Feb 3, 2025
…WebKit checkers. (llvm#91830)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.