https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/130911
Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant. >From 6eefb934996532201cc3f137931e3cb140bf25c1 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <rn...@webkit.org> Date: Wed, 12 Mar 2025 00:11:14 -0700 Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Treat an explicit construction of Ref from a Ref return value safe. Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant. --- clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 2 ++ clang/test/Analysis/Checkers/WebKit/call-args.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index 5e67cb29d08e4..1d9e8a468e899 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -70,6 +70,8 @@ bool tryToFindPtrOrigin( if (isCtorOfSafePtr(ConversionFunc)) return callback(E, true); } + if (isa<CXXFunctionalCastExpr>(E) && isSafePtrType(cast->getType())) + return callback(E, true); } // FIXME: This can give false "origin" that would lead to false negatives // in checkers. See https://reviews.llvm.org/D37023 for reference. diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp index e7afd9798da3e..0d53df6a2052f 100644 --- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp +++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp @@ -407,6 +407,13 @@ namespace call_with_explicit_temporary_obj { void baz() { bar<int>(); } + + class Foo { + Ref<RefCountable> ensure(); + void foo() { + Ref { ensure() }->method(); + } + }; } namespace call_with_explicit_construct { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits