Closed Bug 1434689 Opened 8 years ago Closed 8 years ago

Add support for a MOZ_TEMPORARY_CLASS annotation

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement)

enhancement
Not set
normal

Tracking

(firefox60 fixed)

RESOLVED FIXED
mozilla60
Tracking Status
firefox60 --- fixed

People

(Reporter: erahm, Assigned: erahm)

References

Details

Attachments

(4 files, 1 obsolete file)

Some types are intended to be temporary-only (eg `nsTSubstringTuple`), it would be nice to have an annotation for that, essentially the opposite of `MOZ_NON_TEMPORARY_CLASS` [1]. [1] https://searchfox.org/mozilla-central/rev/c56f656febb1aa58c72b218699e24a76425bd284/mfbt/Attributes.h#470-474
I'm going to take a crack at this.
Assignee: nobody → erahm
This adds a `moz_non_temporary_class` annotation that can be used to indicate a class is intended to only be used as a temporary.
Comment on attachment 8947273 [details] [diff] [review] Part 1: Add moz_temporary_class annotation Review of attachment 8947273 [details] [diff] [review]: ----------------------------------------------------------------- Hey Nika, this is my first draft at adding support for annotating temporary-only classes. I've got the the point where this compiles and the tests are run, but there are a two cases I think it's missing. Would you mind giving me some pointers? On a side-note: Is there a better way to "run" the tests than doing a full |mach build|? ::: build/clang-plugin/tests/TestTemporaryClass.cpp @@ +61,5 @@ > + > +// Can't be member of a class, this should error. > +struct RandomClass { > + // These should error. > + Temporary nonstaticMember; // This should fail. Why doesn't this fail? I'd expect this to fail, but it does not. I feel like I need to update another bit of logic besides just `ScopeChecker::check`. @@ +66,5 @@ > + static Temporary staticMember; // expected-error {{variable of type 'Temporary' is only valid as a temporary}} expected-note {{value incorrectly allocated in a global variable}} > +}; > + > +// Need to declare MOZ_TEMPORARY_CLASS when inheriting, this should error. > +struct BadInherit : Temporary {}; // Should this fail? I also think this should fail, but maybe we don't need to be explicit about inheriting the behavior?
Attachment #8947273 - Flags: feedback?(nika)
Comment on attachment 8947273 [details] [diff] [review] Part 1: Add moz_temporary_class annotation Review of attachment 8947273 [details] [diff] [review]: ----------------------------------------------------------------- ::: build/clang-plugin/tests/TestTemporaryClass.cpp @@ +61,5 @@ > + > +// Can't be member of a class, this should error. > +struct RandomClass { > + // These should error. > + Temporary nonstaticMember; // This should fail. Why doesn't this fail? This is allowed because RandomClass is only ever used as a temporary. It wouldn't be allowed if RandomClass was ever used in a non-temporary context. @@ +66,5 @@ > + static Temporary staticMember; // expected-error {{variable of type 'Temporary' is only valid as a temporary}} expected-note {{value incorrectly allocated in a global variable}} > +}; > + > +// Need to declare MOZ_TEMPORARY_CLASS when inheriting, this should error. > +struct BadInherit : Temporary {}; // Should this fail? same as above here
Attachment #8947273 - Flags: feedback?(nika) → feedback+
Thanks for the feedback, that makes sense now. I've update the comments but the content is the same. This adds a `moz_non_temporary_class` annotation that can be used to indicate a class is intended to only be used as a temporary.
Attachment #8947302 - Flags: review?(nika)
Attachment #8947273 - Attachment is obsolete: true
This adds the MOZ_TEMPORARY_CLASS attribute to Attributes.h.
Attachment #8947303 - Flags: review?(nika)
The documentation indicates nsTStringTuple is intended for internal use only and is designed to be only be used as a temporary. This makes that fact explicit by annotating the class for static analysis.
Attachment #8947304 - Flags: review?(dbaron)
> This adds a `moz_non_temporary_class` annotation that can be used to indicate Fix the annotation name?
(In reply to Boris Zbarsky [:bz] (no decent commit message means r-) from comment #8) > > This adds a `moz_non_temporary_class` annotation that can be used to indicate > > Fix the annotation name? Will do.
Comment on attachment 8947302 [details] [diff] [review] Part 1: Add moz_temporary_class annotation Review of attachment 8947302 [details] [diff] [review]: ----------------------------------------------------------------- LGTM
Attachment #8947302 - Flags: review?(nika) → review+
Attachment #8947303 - Flags: review?(nika) → review+
Comment on attachment 8947304 [details] [diff] [review] Part 3: Annotate nsTSubstringTuple as MOZ_TEMPORARY_CLASS Redirecting, dbaron is out for a bit.
Attachment #8947304 - Flags: review?(dbaron) → review?(nfroyd)
Comment on attachment 8947304 [details] [diff] [review] Part 3: Annotate nsTSubstringTuple as MOZ_TEMPORARY_CLASS Review of attachment 8947304 [details] [diff] [review]: ----------------------------------------------------------------- +1
Attachment #8947304 - Flags: review?(nfroyd) → review+
Since IgnoreErrors has already landed, do you want to annotate that too?
IgnoreErrors is intended to only be used as a temporary class, this adds an explicit annotation.
Attachment #8947995 - Flags: review?(bzbarsky)
Comment on attachment 8947995 [details] [diff] [review] Part 4: Annotate IgnoreErrors as MOZ_TEMPORARY_CLASS r=me
Attachment #8947995 - Flags: review?(bzbarsky) → review+
Pushed by erahm@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/8a8ec57b40f0 Part 1: Add moz_temporary_class annotation. r=mystor https://hg.mozilla.org/integration/mozilla-inbound/rev/0894630b8269 Part 2: Add MOZ_TEMPORARY_CLASS attribute. r=mystor https://hg.mozilla.org/integration/mozilla-inbound/rev/11f8f004395c Part 3: Annotate nsTSubstringTuple as MOZ_TEMPORARY_CLASS. r=froydnj https://hg.mozilla.org/integration/mozilla-inbound/rev/38fdcb96bb92 Part 4: Annotate IgnoreErrors as MOZ_TEMPORARY_CLASS. r=bz
Product: Core → Firefox Build System
Blocks: 1479232
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: