Closed
Bug 1419637
Opened 7 years ago
Closed 7 years ago
PodZero throws lots of warnings on clearing an object of non-trivial type when using gcc 8
Categories
(Core :: JavaScript Engine: JIT, defect, P3)
Core
JavaScript Engine: JIT
Tracking
()
RESOLVED
FIXED
mozilla59
Tracking | Status | |
---|---|---|
firefox59 | --- | fixed |
People
(Reporter: allstars.chh, Assigned: andi)
Details
Attachments
(1 file)
In file included from /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/js/HashTable.h:18:0, from /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/js/TracingAPI.h:12, from /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/js/GCPolicyAPI.h:47, from /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/js/GCVector.h:12, from /home/allstars/src/gcc8/js/src/jscntxt.h:15, from /home/allstars/src/gcc8/js/src/jit/JitFrames.h:12, from /home/allstars/src/gcc8/js/src/jit/Bailouts.h:12, from /home/allstars/src/gcc8/js/src/jit/Bailouts.cpp:7, from /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/js/src/Unified_cpp_js_src9.cpp:2: /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/mozilla/PodOperations.h: In instantiation of ‘void mozilla::PodZero(T*) [with T = js::jit::Address]’: /home/allstars/src/gcc8/js/src/jit/shared/Assembler-shared.h:301:38: required from here /home/allstars/src/gcc8/obj-x86_64-pc-linux-gnu/dist/include/mozilla/PodOperations.h:55:9: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct js::jit::Address’; use assignment or value-initialization instead [-Wclass-memaccess] memset(aT, 0, sizeof(T));
Assignee | ||
Comment 1•7 years ago
|
||
Te problem lies here:
>>struct Address
>>{
>> Register base;
>> int32_t offset;
>>
>> Address(Register base, int32_t offset) : base(base), offset(offset)
>> { }
>>
>> Address() { mozilla::PodZero(this); }
>>};
The two ctors are the issue, having them makes the class not being trivial.
Reporter | ||
Comment 2•7 years ago
|
||
Thanks, but there are many warnings, I just listed one of them. Perhaps I should close this one, and fix each caller site of PodZero individually.
Assignee | ||
Comment 3•7 years ago
|
||
I have a patch for this specific issue if you'd like.
Flags: needinfo?(allstars.chh)
Comment 4•7 years ago
|
||
(In reply to Andi-Bogdan Postelnicu [:andi] from comment #1) > Te problem lies here: > > >>struct Address > >>{ > >> Register base; > >> int32_t offset; > >> > >> Address(Register base, int32_t offset) : base(base), offset(offset) > >> { } > >> > >> Address() { mozilla::PodZero(this); } > >>}; > > The two ctors are the issue, having them makes the class not being trivial. Well, not really, the issue is that PodZero is a hidden way to do memset() and that the right thing here would be for base and offset to be initialized "manually" like: Address() : base(), offset(0) {} (Register has its own constructor with no argument too)
Assignee | ||
Comment 5•7 years ago
|
||
(In reply to Mike Hommey [:glandium] from comment #4) > (In reply to Andi-Bogdan Postelnicu [:andi] from comment #1) > > Te problem lies here: > > > > >>struct Address > > >>{ > > >> Register base; > > >> int32_t offset; > > >> > > >> Address(Register base, int32_t offset) : base(base), offset(offset) > > >> { } > > >> > > >> Address() { mozilla::PodZero(this); } > > >>}; > > > > The two ctors are the issue, having them makes the class not being trivial. > > Well, not really, the issue is that PodZero is a hidden way to do memset() > and that the right thing here would be for base and offset to be initialized > "manually" like: > > Address() : base(), offset(0) {} > > (Register has its own constructor with no argument too) Yep, without the ctors the objet would have been trivial, and yes again the correct fix is what you wrote. In general doing memset on this is very dangerous, specially in those cases where the class is polymorphic.
Comment hidden (mozreview-request) |
Assignee | ||
Comment 7•7 years ago
|
||
This should also be added to:
>>struct BaseIndex
Comment hidden (mozreview-request) |
Comment 9•7 years ago
|
||
mozreview-review |
Comment on attachment 8930862 [details] Bug 1419637 - do not call memset on a non-trivial type. https://reviewboard.mozilla.org/r/201964/#review207472 Thanks!
Attachment #8930862 -
Flags: review?(jdemooij) → review+
Comment 10•7 years ago
|
||
Actually, Register has this: Register() = default; Doesn't that mean we should now initialize these Register fields explicitly to Register::Invalid() or something? I wonder if we could do that in the Register constructor - probably not without breaking other stuff...
Flags: needinfo?(bpostelnicu)
Comment 11•7 years ago
|
||
Comment on attachment 8930862 [details] Bug 1419637 - do not call memset on a non-trivial type. Clearing r+ per comment 10.
Attachment #8930862 -
Flags: review+
Updated•7 years ago
|
Component: MFBT → JavaScript Engine: JIT
Priority: -- → P3
Reporter | ||
Comment 13•7 years ago
|
||
(In reply to Andi-Bogdan Postelnicu [:andi] from comment #3) > I have a patch for this specific issue if you'd like. go ahead
Flags: needinfo?(allstars.chh)
Comment hidden (mozreview-request) |
Assignee | ||
Updated•7 years ago
|
Attachment #8930862 -
Flags: review?(jdemooij)
Comment 15•7 years ago
|
||
mozreview-review |
Comment on attachment 8930862 [details] Bug 1419637 - do not call memset on a non-trivial type. https://reviewboard.mozilla.org/r/201964/#review207778 Great, thanks!
Attachment #8930862 -
Flags: review?(jdemooij) → review+
Comment 16•7 years ago
|
||
Pushed by bpostelnicu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/da6568fa82df do not call memset on a non-trivial type. r=jandem
Comment 17•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/da6568fa82df
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
Updated•6 years ago
|
Assignee: nobody → bpostelnicu
You need to log in
before you can comment on or make changes to this bug.
Description
•