The default bug view has changed. See this FAQ.

clang warns about alignment requirement increase in nsID::Equals after bug 164580

RESOLVED FIXED in mozilla7

Status

()

Core
XPCOM
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: Ehsan, Assigned: Ehsan)

Tracking

unspecified
mozilla7
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

6 years ago
../../../../dist/include/nsID.h:77:8: warning: cast from 'const PRUint32 *' (aka 'const unsigned int *') to 'PRUint64 *' (aka 'unsigned long long *') increases required alignment from 4 to 8
      [-Wcast-align]
      ((PRUint64*) &m0)[0] == ((PRUint64*) &other.m0)[0] &&
       ^~~~~~~~~~~~~~~
../../../../dist/include/nsID.h:77:32: warning: cast from 'const PRUint32 *' (aka 'const unsigned int *') to 'PRUint64 *' (aka 'unsigned long long *') increases required alignment from 4 to 8
      [-Wcast-align]
      ((PRUint64*) &m0)[0] == ((PRUint64*) &other.m0)[0] &&
                               ^~~~~~~~~~~~~~~~~~~~~
../../../../dist/include/nsID.h:78:8: warning: cast from 'const PRUint32 *' (aka 'const unsigned int *') to 'PRUint64 *' (aka 'unsigned long long *') increases required alignment from 4 to 8
      [-Wcast-align]
      ((PRUint64*) &m0)[1] == ((PRUint64*) &other.m0)[1];
       ^~~~~~~~~~~~~~~
../../../../dist/include/nsID.h:78:32: warning: cast from 'const PRUint32 *' (aka 'const unsigned int *') to 'PRUint64 *' (aka 'unsigned long long *') increases required alignment from 4 to 8
      [-Wcast-align]
      ((PRUint64*) &m0)[1] == ((PRUint64*) &other.m0)[1];
                               ^~~~~~~~~~~~~~~~~~~~~

We're basically relying on the correct knowledge of alignment requirements here, so we'd better silence the compiler.
(Assignee)

Comment 1

6 years ago
Created attachment 534972 [details] [diff] [review]
Patch (v1)
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #534972 - Flags: review?(benjamin)
Wow, those are really pretty compile errors.  I like the aka's on the typedefs.  Man.
(In reply to comment #2)
> Wow, those are really pretty compile errors.  I like the aka's on the
> typedefs.  Man.

Reason #73 why clang is eventually going to kill off gcc.
Do we know that nsID is actually 64-bit aligned? Given that none of the members require 64-bit alignment, I'm not sure that the struct is actually always going to be 64-bit aligned.
It would probably be worth forcing 64-bit alignment, if only to be safe.  Do we have any macros wrapping the compiler directives for this?  I can't seem to find them.
(Assignee)

Comment 6

6 years ago
One possible way to force 64-bit alignment that I know of is to wrap its members into two unions, each with a 64-bit member.  But that would break the POD-ness of the type... :(
See bug 660335 for forcing alignment of nsID.
Attachment #534972 - Flags: review?(benjamin) → review+
(Assignee)

Comment 8

6 years ago
http://hg.mozilla.org/mozilla-central/rev/15bfb9729ff3
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla7
You need to log in before you can comment on or make changes to this bug.