Last Comment Bug 659546 - clang warns about alignment requirement increase in nsID::Equals after bug 164580
: clang warns about alignment requirement increase in nsID::Equals after bug 16...
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: XPCOM (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: mozilla7
Assigned To: :Ehsan Akhgari
:
: Nathan Froyd [:froydnj]
Mentors:
Depends on:
Blocks: 164580
  Show dependency treegraph
 
Reported: 2011-05-24 19:08 PDT by :Ehsan Akhgari
Modified: 2011-05-30 08:47 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch (v1) (1.06 KB, patch)
2011-05-24 19:10 PDT, :Ehsan Akhgari
benjamin: review+
Details | Diff | Splinter Review

Description :Ehsan Akhgari 2011-05-24 19:08:14 PDT
../../../../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.
Comment 1 :Ehsan Akhgari 2011-05-24 19:10:21 PDT
Created attachment 534972 [details] [diff] [review]
Patch (v1)
Comment 2 Justin Lebar (not reading bugmail) 2011-05-24 19:35:27 PDT
Wow, those are really pretty compile errors.  I like the aka's on the typedefs.  Man.
Comment 3 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2011-05-24 20:50:36 PDT
(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.
Comment 4 Benjamin Smedberg [:bsmedberg] 2011-05-25 10:03:02 PDT
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.
Comment 5 Justin Lebar (not reading bugmail) 2011-05-25 10:11:33 PDT
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.
Comment 6 :Ehsan Akhgari 2011-05-26 11:37:52 PDT
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... :(
Comment 7 Justin Lebar (not reading bugmail) 2011-05-27 14:03:42 PDT
See bug 660335 for forcing alignment of nsID.

Note You need to log in before you can comment on or make changes to this bug.