Bug 231954 - clang-tidy checker to find places where WTFMove/std::move are missing with RetainPtr<>
Summary: clang-tidy checker to find places where WTFMove/std::move are missing with Re...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-10-19 08:18 PDT by David Kilzer (:ddkilzer)
Modified: 2021-10-26 08:19 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2021-10-19 08:18:08 PDT
clang-tidy checker to find places where WTFMove/std::move are missing with RetainPtr<>.

In Bug 231814 Comment #6 and Bug 231814 Comment #11, I reimplemented a suggestion from Darin, but I missed adding a WTFMove() of a RetainPtr<> object that was going out of scope, resulting in some ref count churn:

    RetainPtr<SecKeyRef> LocalConnection::createCredentialPrivateKey(...)
    {
        RetainPtr privateKeyAttributes = @{ ... };

        if (context) {
            auto mutableCopy = adoptNS([privateKeyAttributes mutableCopy]);
            mutableCopy.get()[(id)kSecUseAuthenticationContext] = context;
            privateKeyAttributes = mutableCopy;  // FIXME: Missing WTFMove(mutableCopy)
        }
        [...]
    }

A clang-tidy checker would be useful that warns about a missing WTFMove/std::move where a RetainPtr<> object is last referenced in a block/function using an assignment operator to another RetainPtr<> variable.

I'm sure there are more of these cases in WebKit, and such a checker could probably be made generic enough for any class with an operator=(&&) implementation.
Comment 1 Radar WebKit Bug Importer 2021-10-26 08:19:16 PDT
<rdar://problem/84664132>