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)
Developer Infrastructure
Source Code Analysis
Tracking
(firefox60 fixed)
RESOLVED
FIXED
mozilla60
| Tracking | Status | |
|---|---|---|
| firefox60 | --- | fixed |
People
(Reporter: erahm, Assigned: erahm)
References
Details
Attachments
(4 files, 1 obsolete file)
|
7.19 KB,
patch
|
nika
:
review+
|
Details | Diff | Splinter Review |
|
2.03 KB,
patch
|
nika
:
review+
|
Details | Diff | Splinter Review |
|
838 bytes,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
|
961 bytes,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
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
| Assignee | ||
Comment 2•8 years ago
|
||
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.
| Assignee | ||
Comment 3•8 years ago
|
||
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 4•8 years ago
|
||
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+
| Assignee | ||
Comment 5•8 years ago
|
||
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)
| Assignee | ||
Updated•8 years ago
|
Attachment #8947273 -
Attachment is obsolete: true
| Assignee | ||
Comment 6•8 years ago
|
||
This adds the MOZ_TEMPORARY_CLASS attribute to Attributes.h.
Attachment #8947303 -
Flags: review?(nika)
| Assignee | ||
Comment 7•8 years ago
|
||
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)
Comment 8•8 years ago
|
||
> This adds a `moz_non_temporary_class` annotation that can be used to indicate
Fix the annotation name?
| Assignee | ||
Comment 9•8 years ago
|
||
(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 10•8 years ago
|
||
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+
Updated•8 years ago
|
Attachment #8947303 -
Flags: review?(nika) → review+
| Assignee | ||
Comment 11•8 years ago
|
||
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)
| Assignee | ||
Comment 12•8 years ago
|
||
Comment 13•8 years ago
|
||
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+
Comment 14•8 years ago
|
||
Since IgnoreErrors has already landed, do you want to annotate that too?
| Assignee | ||
Comment 15•8 years ago
|
||
IgnoreErrors is intended to only be used as a temporary class, this adds an
explicit annotation.
Attachment #8947995 -
Flags: review?(bzbarsky)
Comment 16•8 years ago
|
||
Comment on attachment 8947995 [details] [diff] [review]
Part 4: Annotate IgnoreErrors as MOZ_TEMPORARY_CLASS
r=me
Attachment #8947995 -
Flags: review?(bzbarsky) → review+
Comment 17•8 years ago
|
||
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
Comment 18•8 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/8a8ec57b40f0
https://hg.mozilla.org/mozilla-central/rev/0894630b8269
https://hg.mozilla.org/mozilla-central/rev/11f8f004395c
https://hg.mozilla.org/mozilla-central/rev/38fdcb96bb92
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox60:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
Updated•8 years ago
|
Product: Core → Firefox Build System
Updated•4 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•