Skip to content

Conversation

@rniwa
Copy link
Contributor

@rniwa rniwa commented Dec 10, 2024

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was recognized in tryToFindPtrOrigin.

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was recognized in tryToFindPtrOrigin.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Dec 10, 2024
@rniwa rniwa requested a review from t-rasmud December 10, 2024 07:07
@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2024

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

Changes

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was recognized in tryToFindPtrOrigin.


Full diff: https://github.com/llvm/llvm-project/pull/119336.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+1-1)
  • (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+11)
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 {
 }

@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)

Changes

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was recognized in tryToFindPtrOrigin.


Full diff: https://github.com/llvm/llvm-project/pull/119336.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+1-1)
  • (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+11)
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 {
 }

Copy link
Contributor

@t-rasmud t-rasmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the tests, LGTM!

@rniwa
Copy link
Contributor Author

rniwa commented Dec 12, 2024

Thanks for the review!

@rniwa rniwa merged commit f7e868f into llvm:main Dec 12, 2024
8 checks passed
@rniwa rniwa deleted the recognize-cxx-construct-expr branch December 12, 2024 17:37
rniwa added a commit to rniwa/llvm-project that referenced this pull request Feb 3, 2025
…in (llvm#119336)

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was
recognized in tryToFindPtrOrigin.
devincoughlin pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 25, 2025
…in (llvm#119336)

Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was
recognized in tryToFindPtrOrigin.
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request Apr 24, 2025
https://bugs.webkit.org/show_bug.cgi?id=292007

Reviewed by Ryosuke Niwa and Mike Wyrzykowski.

llvm/llvm-project#119336 was merged four months
ago. Presumably this is all good now.

* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h:
(WebKit::RemoteGraphicsContextGL::send const):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteGPU.h:

Canonical link: https://commits.webkit.org/294073@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants