Closed Bug 1718825 Opened 3 years ago Closed 3 years ago

`MOZ_KNOWN_LIVE` does not work as expected with `RefPtr` member etc

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement)

enhancement

Tracking

(firefox98 fixed)

RESOLVED FIXED
98 Branch
Tracking Status
firefox98 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(1 file)

If there is a stack class

struct MOZ_STACK_CLASS Foo final {
  MOZ_KNOWN_LIVE RefPtr<Bar> mBar;
};

and calling a method marked as MOZ_CAN_RUN_SCRIPT with it,

Foo foo{bar};
MayRunScript(foo.mBar);

and

Foo foo{bar};
MayRunScript(*foo.mBar);

becomes compile error. They require MOZ_KnownLive().

MOZ_KNOWN_LIVE RefPtr<Foo> mFoo is not treated as safe because its raw pointer
is referred with operators but they are not checked at handling MOZ_KNOWN_LIVE
annotation.

Additionally, when members marked as MOZ_KNOWN_LIVE are in the stack, they
are also not treated as safe, but they should be safe in most cases.

With these changes, HTMLTableEditor.cpp can get rid of a lot of
MOZ_KnownLive method calls.

Assignee: nobody → masayuki
Status: NEW → ASSIGNED

ping for review...

Flags: needinfo?(bpostelnicu)
Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/f66aeabcf86c Treat strong pointers which are members of class/struct and marked as `MOZ_KNOWN_LIVE` as safe r=andi
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch

(In reply to Masayuki Nakano [:masayuki] (he/him)(JST, +0900) from comment #0)

If there is a stack class

struct MOZ_STACK_CLASS Foo final {
  MOZ_KNOWN_LIVE RefPtr<Bar> mBar;
};

Fwiw this could've been fixed by marking the pointer as const (so const RefPtr...), but I guess that doesn't work for all your use cases?

(In reply to Emilio Cobos Álvarez (:emilio) from comment #5)

(In reply to Masayuki Nakano [:masayuki] (he/him)(JST, +0900) from comment #0)

If there is a stack class

struct MOZ_STACK_CLASS Foo final {
  MOZ_KNOWN_LIVE RefPtr<Bar> mBar;
};

Fwiw this could've been fixed by marking the pointer as const (so const RefPtr...), but I guess that doesn't work for all your use cases?

Yeah, if it requires complicated computation or delay for initializing the member, const is not useful (of course, can use const_cast though).

Flags: needinfo?(bpostelnicu)
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: