[clang] [WebKit checkers] Recognize adoptRef as a safe function (PR #119846)

Rashmi Mudduluru via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 18 05:49:30 PST 2024


================
@@ -365,3 +365,20 @@ namespace call_with_explicit_temporary_obj {
     RefPtr { provide() }->method();
   }
 }
+
+namespace call_with_adopt_ref {
+  class Obj {
+  public:
+    void ref() const;
+    void deref() const;
+    void method();
+  };
+
+  struct dummy {
+    RefPtr<Obj> any;
----------------
t-rasmud wrote:

 Looks like there is some bug in AST generation. The return type of callee is different for both the versions at
 https://github.com/llvm/llvm-project/blob/fbc18b85d6ce5ab6489a2b08f9b38d446fe9d6f6/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp#L103

With dummy struct:
```
(lldb) p callee->getReturnType()->dump()
ElaboratedType 0x1309723b0 'RefPtr<Obj>' sugar
`-RecordType 0x130971240 'struct RefPtr<class call_with_adopt_ref::Obj>'
  `-ClassTemplateSpecialization 0x130971160 'RefPtr'

```
Without the dummy struct:
```
(lldb) p callee->getReturnType()->dump()
ElaboratedType 0x12c973230 'RefPtr<Obj>' sugar
`-TemplateSpecializationType 0x12c9731e0 'RefPtr<class call_with_adopt_ref::Obj>' sugar
  |-name: 'RefPtr' qualified
  | `-ClassTemplateDecl 0x12c95ee30 prev 0x12c95e690  RefPtr
  |-TemplateArgument type 'class call_with_adopt_ref::Obj'
  | `-SubstTemplateTypeParmType 0x12c9730a0 'class call_with_adopt_ref::Obj' sugar typename depth 0 index 0 T
  |   |-FunctionTemplate 0x12c95ec18 'adoptRef'
  |   `-RecordType 0x12c970560 'class call_with_adopt_ref::Obj'
  |     `-CXXRecord 0x12c9704d0 'Obj'
  `-RecordType 0x12c9731c0 'struct RefPtr<class call_with_adopt_ref::Obj>'
    `-ClassTemplateSpecialization 0x12c9730e0 'RefPtr'
```

Maybe create a separate radar for this issue and add the radar ID to the comment in the test case?
Otherwise, LGTM!

https://github.com/llvm/llvm-project/pull/119846


More information about the cfe-commits mailing list