Closed
Bug 1226376
Opened 10 years ago
Closed 9 years ago
Mark mozilla::StaticMutex as MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS
Categories
(Developer Infrastructure :: Source Code Analysis, defect)
Developer Infrastructure
Source Code Analysis
Tracking
(firefox46 fixed)
RESOLVED
FIXED
mozilla46
| Tracking | Status | |
|---|---|---|
| firefox46 | --- | fixed |
People
(Reporter: nika, Assigned: nika)
References
Details
Attachments
(2 files, 1 obsolete file)
|
1.10 KB,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
|
6.21 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
This will prohibit it from being allocated outside of a static context, which the documentation comment seems to suggest is mandatory.
| Assignee | ||
Updated•10 years ago
|
Summary: Mark mozilla::StaticMutex as MOZ_GLOBAL_CLASS → Mark mozilla::StaticMutex as MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS
| Assignee | ||
Comment 1•10 years ago
|
||
| Assignee | ||
Updated•10 years ago
|
Attachment #8689743 -
Flags: review?(nfroyd)
Updated•10 years ago
|
Attachment #8689743 -
Flags: review?(nfroyd) → review+
Comment 3•10 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/ae540161167aa228eca563fa93e45aac567b2015
Backout changeset aad9086f8efd (bug 1226376) for breaking Opt static-analysis build.
| Assignee | ||
Comment 4•10 years ago
|
||
So, the problem here is that Atomic<T> doesn't have a non-trivial constructor, instead, it has a constexpr constructor which dispatches to AtomicBase, which also has a constexpr constructor.
I'm not sure about what the exact semantics of constexpr are, and whether that is acceptable. For example, on MSVC right now it seems like StaticMutex has a "non-trivial" constructor, (though it will probably? be optimized away?), and on clang/gcc it's a constexpr constructor, and shouldn't therefore have any runtime cost at startup (I think?).
Comment 5•10 years ago
|
||
We should = delete some of the things on StaticMutex (and probably StaticAutoPtr, if we don't already). I'm not sure what to do about the DEBUG-only StaticMutex constructor; I think now that we have the static analysis that ensures StaticMutex only occurs at toplevel, we could get rid of the assert.
| Assignee | ||
Comment 6•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #5)
> We should = delete some of the things on StaticMutex (and probably
> StaticAutoPtr, if we don't already). I'm not sure what to do about the
> DEBUG-only StaticMutex constructor; I think now that we have the static
> analysis that ensures StaticMutex only occurs at toplevel, we could get rid
> of the assert.
So, the analysis to ensure that things only appear at the top level is currently (MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS), which also asserts that all constructors are trivial (in release mode), which is not the case for StaticMutex, as Atomic has a constructor. Do you think that I should also expose MOZ_GLOBAL_CLASS directly for types which must be global, but which may have a non-trivial constructor?
I agree that removing the assert is probably OK, but I don't really see any reason to. The thing I'm more worried about is that StaticMutex has a non-trivial destructor in release mode, which AFAICR is a slight problem.
Flags: needinfo?(nfroyd)
Comment 7•10 years ago
|
||
Where do you see the release-mode destructor for StaticMutex? That would certainly be a bad thing. I'm a bit surprised that MSVC would have a non-trivial constructor; constexpr isn't supported by 2013, but I think MSVC would optimize the initialization away...unless there's something else I'm missing.
I am not super-thrilled about adding another annotation, as I think the current set of annotations is complicated enough. It seems like we ought to permit constexpr constructors in the analysis.
Flags: needinfo?(nfroyd)
| Assignee | ||
Comment 8•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #7)
> Where do you see the release-mode destructor for StaticMutex? That would
> certainly be a bad thing. I'm a bit surprised that MSVC would have a
> non-trivial constructor; constexpr isn't supported by 2013, but I think MSVC
> would optimize the initialization away...unless there's something else I'm
> missing.
>
> I am not super-thrilled about adding another annotation, as I think the
> current set of annotations is complicated enough. It seems like we ought to
> permit constexpr constructors in the analysis.
That's what I was thinking too, I think that it would be optimized away, so it _probably_ isn't a problem (I don't really want to read the output from the compiler to find out ^.^).
It's only constructor, sorry, I typoed and typed destructor instead of constructor. I can probably whitelist constexpr constructors in the analysis, I'll take a look at how annoying that will be to do.
| Assignee | ||
Comment 9•10 years ago
|
||
I believe that this should be OK for the purpose of MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS, as constexpr functions should be run at compile time, and thus there shouldn't be any of the static constructor overhead.
We may want to re-name the internal annotation name to MOZ_CONSTEXPR_CTOR_DTOR if we choose to use this.
Attachment #8697302 -
Flags: review?(ehsan)
Updated•10 years ago
|
Attachment #8697302 -
Flags: review?(ehsan) → review+
| Assignee | ||
Comment 10•10 years ago
|
||
Sorry for asking for review again. I was going to push, but noticed some weird edge cases. I just want to make sure that the edge cases are OK before actually making this change, as they may make this entire thing too complicated and annoying (meaning that we should scrap this entire patch).
Attachment #8697415 -
Flags: review?(ehsan)
| Assignee | ||
Updated•10 years ago
|
Attachment #8697302 -
Attachment is obsolete: true
Updated•10 years ago
|
Attachment #8697415 -
Flags: review?(ehsan) → review+
Comment 11•9 years ago
|
||
Comment 12•9 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/22e911e48008
https://hg.mozilla.org/mozilla-central/rev/09c58ad8358d
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox46:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
Updated•7 years ago
|
Product: Core → Firefox Build System
Updated•3 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
•