Skip to content

Conversation

rniwa
Copy link
Contributor

@rniwa rniwa commented Aug 22, 2025

Since a temporary object lives until the end of the statement, it's safe to pass such an object as a function argument without explicitly creating a CheckedRef/CheckedPtr in stack.

…ing a temporary object as an argument.

Since a temporary object lives until the end of the statement, it's safe to pass such an object as
a function argument without explicitly creating a CheckedRef/CheckedPtr in stack.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Aug 22, 2025
@rniwa rniwa requested a review from t-rasmud August 22, 2025 21:41
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

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

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

Changes

Since a temporary object lives until the end of the statement, it's safe to pass such an object as a function argument without explicitly creating a CheckedRef/CheckedPtr in stack.


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

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+2)
  • (modified) clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp (+5)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 478bd85177143..0d2294e1e9bb0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -208,6 +208,8 @@ bool isASafeCallArg(const Expr *E) {
         return true;
     }
   }
+  if (isa<CXXTemporaryObjectExpr>(E))
+    return true; // A temporary lives until the end of this statement.
   if (isConstOwnerPtrMemberExpr(E))
     return true;
 
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
index 8685978ebf1ac..b89a3246606ed 100644
--- a/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
@@ -32,3 +32,8 @@ void foo() {
   provide()->doWork();
   // expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
 }
+
+void doWorkWithObject(const CheckedObject&);
+void bar() {
+  doWorkWithObject(CheckedObject());
+}

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.

2 participants