[clang] Fix a bug that CXXConstructExpr wasn't recognized by tryToFindPtrOrigin (PR #119336)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 11 23:04:04 PST 2024
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/119336
>From a3c97276a15af0324b4436d85fa06e22650dfb57 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Mon, 9 Dec 2024 23:03:46 -0800
Subject: [PATCH 1/2] Fix a bug that CXXConstructExpr wasn't recognized by
tryToFindPtrOrigin
Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was recognized in tryToFindPtrOrigin.
---
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 2 +-
clang/test/Analysis/Checkers/WebKit/call-args.cpp | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
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..d4420c59b41ca8 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 {
}
>From f06d71df6047cd533c9768f427cca39ba3426884 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Wed, 11 Dec 2024 23:03:41 -0800
Subject: [PATCH 2/2] Fix test cases for main.
---
clang/test/Analysis/Checkers/WebKit/call-args.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index d4420c59b41ca8..9920690746dafc 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -366,8 +366,8 @@ namespace call_with_explicit_temporary_obj {
}
template <typename T>
void bar() {
- Ref { *provide() }->method();
- RefPtr { provide() }->method();
+ Ref(*provide())->method();
+ RefPtr(provide())->method();
}
void baz() {
bar<int>();
More information about the cfe-commits
mailing list