Closed Bug 1878108 Opened 2 years ago Closed 2 years ago

Consider using `[[clang:lifetime_bound]]` attribute for FunctionRef

Categories

(Core :: MFBT, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
124 Branch
Tracking Status
firefox124 --- fixed

People

(Reporter: nika, Assigned: emilio)

References

Details

Attachments

(2 files)

In bug 1877672, the FunctionRef type is made to be MOZ_TEMPORARY_CLASS to prevent it from being used outside of a temporary context. This is being done to avoid issues with a temporary lambda being passed into the FunctionRef, which is then kept around longer than the constructor's expression.

Out of curiosity I noticed that absl has a similar FunctionRef type (https://searchfox.org/mozilla-central/rev/5c4a45eb17423373ecb71aea9819d41a6231613e/third_party/libwebrtc/third_party/abseil-cpp/absl/functional/function_ref.h#104), which has neither mitigation we have used for our type, but specifies this ABSL_ATTRIBUTE_LIFETIME_BOUND annotation. This appears to be a clang-specific annotation for cases like the one in bug 1877672 (https://clang.llvm.org/docs/AttributeReference.html#lifetimebound).

Unlike our custom static analysis, builtin clang attributes will be checked on developer's machines if they build with clang, without the clang-plugin enabled, meaning that it may catch bugs earlier in development.

This bug is to track potentially adding attributes for this annotation to Attributes.h, and potentially using it for our FunctionRef type (either in addition to MOZ_TEMPORARY_CLASS or instead of that attribute).

Flags: needinfo?(emilio)

The built-in version is better as it also allows annotating particular
parameters (it not only applies to method declarations).

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bb356c39c0e2 Replace custom MOZ_LIFETIME_BOUND with built-in. r=nika,glandium https://hg.mozilla.org/integration/autoland/rev/05e2d2bc1260 Annotate FunctionRef constructor with MOZ_LIFETIME_BOUND. r=nika
Backout by pstanciu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/da4017ea7dfb Backed out 2 changesets for causing sm bustages in Attributes.h. CLOSED TREE

Backed out for causing sm bustages in Attributes.h.

[task 2024-02-06T10:10:59.162Z] /builds/worker/workspace/obj-spider/dist/include/mozilla/Attributes.h:457:32: error: missing ')' after "__has_attribute"
[task 2024-02-06T10:10:59.162Z]  #  if __has_cpp_attribute(clang::lifetimebound)
[task 2024-02-06T10:10:59.162Z]                                 ^
[task 2024-02-06T10:10:59.162Z] /builds/worker/workspace/obj-spider/dist/include/mozilla/Attributes.h:457:33: error:  ':' without preceding '?'
[task 2024-02-06T10:10:59.162Z]  #  if __has_cpp_attribute(clang::lifetimebound)
[task 2024-02-06T10:10:59.162Z]                                  ^
[task 2024-02-06T10:10:59.162Z] gmake[4]: *** [/builds/worker/checkouts/gecko/config/rules.mk:600: pure_virtual.o] Error 1
[task 2024-02-06T10:10:59.162Z] gmake[4]: Leaving directory '/builds/worker/workspace/obj-spider/build/pure_virtual'
[task 2024-02-06T10:10:59.162Z] gmake[4]: Target 'target-objects' not remade because of errors.
[task 2024-02-06T10:10:59.162Z] gmake[3]: *** [/builds/worker/checkouts/gecko/config/recurse.mk:72: build/pure_virtual/target-objects] Error 2
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bad3848767f6 Replace custom MOZ_LIFETIME_BOUND with built-in. r=nika,glandium https://hg.mozilla.org/integration/autoland/rev/d9f3cf9b2cb7 Annotate FunctionRef constructor with MOZ_LIFETIME_BOUND. r=nika
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: