[clang] f7e868f - Fix a bug that CXXConstructExpr wasn't recognized by tryToFindPtrOrigin (#119336)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 09:37:09 PST 2024
Author: Ryosuke Niwa
Date: 2024-12-12T09:37:04-08:00
New Revision: f7e868fe432da733f30379c01076f5f4c9792501
URL: https://github.com/llvm/llvm-project/commit/f7e868fe432da733f30379c01076f5f4c9792501
DIFF: https://github.com/llvm/llvm-project/commit/f7e868fe432da733f30379c01076f5f4c9792501.diff
LOG: Fix a bug that CXXConstructExpr wasn't recognized by tryToFindPtrOrigin (#119336)
Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was
recognized in tryToFindPtrOrigin.
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
clang/test/Analysis/Checkers/WebKit/call-args.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index b3cd594a0f3529..69b63240d2075e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -33,7 +33,7 @@ bool tryToFindPtrOrigin(
E = tempExpr->getSubExpr();
continue;
}
- if (auto *tempExpr = dyn_cast<CXXTemporaryObjectExpr>(E)) {
+ if (auto *tempExpr = dyn_cast<CXXConstructExpr>(E)) {
if (auto *C = tempExpr->getConstructor()) {
if (auto *Class = C->getParent(); Class && isSafePtr(Class))
return callback(E, true);
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index 94efddeaf66cd8..9920690746dafc 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -364,4 +364,15 @@ namespace call_with_explicit_temporary_obj {
Ref { *provide() }->method();
RefPtr { provide() }->method();
}
+ template <typename T>
+ void bar() {
+ Ref(*provide())->method();
+ RefPtr(provide())->method();
+ }
+ void baz() {
+ bar<int>();
+ }
+}
+
+namespace call_with_explicit_construct {
}
More information about the cfe-commits
mailing list