Last Comment Bug 662962 - Silence the clang warnings issued because of alignment requirements increase when compiling jsscript.h
: Silence the clang warnings issued because of alignment requirements increase ...
Status: RESOLVED FIXED
[fixed-in-tracemonkey]
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: mozilla7
Assigned To: :Ehsan Akhgari
:
: Jason Orendorff [:jorendorff]
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-08 16:17 PDT by :Ehsan Akhgari
Modified: 2011-06-20 17:06 PDT (History)
1 user (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch (v1) (2.24 KB, patch)
2011-06-08 16:18 PDT, :Ehsan Akhgari
jwalden+bmo: review+
Details | Diff | Splinter Review

Description :Ehsan Akhgari 2011-06-08 16:17:11 PDT
These warnings drive me nuts.  We get thousands of them when compiling jsscript.h.

jstracer.cpp
In file included from /Users/ehsanakhgari/moz/tmp/js/src/jstracer.cpp:62:
In file included from /Users/ehsanakhgari/moz/tmp/js/src/jscntxt.h:55:
In file included from /Users/ehsanakhgari/moz/tmp/js/src/jsfun.h:49:
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:548:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'JSObjectArray *' (aka 'JSObjectArray *') increases required
      alignment from 1 to 8 [-Wcast-align]
        return (JSObjectArray *)((uint8 *) (this + 1) + objectsOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:553:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'JSUpvarArray *' (aka 'JSUpvarArray *') increases required
      alignment from 1 to 8 [-Wcast-align]
        return (JSUpvarArray *) ((uint8 *) (this + 1) + upvarsOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:558:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'JSObjectArray *' (aka 'JSObjectArray *') increases required
      alignment from 1 to 8 [-Wcast-align]
        return (JSObjectArray *) ((uint8 *) (this + 1) + regexpsOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:563:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'JSTryNoteArray *' (aka 'JSTryNoteArray *') increases
      required alignment from 1 to 8 [-Wcast-align]
        return (JSTryNoteArray *) ((uint8 *) (this + 1) + trynotesOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:568:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'js::GlobalSlotArray *' increases required alignment from 1
      to 8 [-Wcast-align]
        return (js::GlobalSlotArray *) ((uint8 *) (this + 1) + globalsOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ehsanakhgari/moz/tmp/js/src/jsscript.h:573:16: warning: cast from 'uint8 *' (aka 'unsigned char *') to 'JSConstArray *' (aka 'JSConstArray *') increases required
      alignment from 1 to 8 [-Wcast-align]
        return (JSConstArray *) ((uint8 *) (this + 1) + constOffset);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 1 :Ehsan Akhgari 2011-06-08 16:18:18 PDT
Created attachment 538141 [details] [diff] [review]
Patch (v1)
Comment 2 Jeff Walden [:Waldo] (remove +bmo to email) 2011-06-17 16:03:24 PDT
Comment on attachment 538141 [details] [diff] [review]
Patch (v1)

>-        return (JSObjectArray *)((uint8 *) (this + 1) + objectsOffset);
>+        return (JSObjectArray *) (void *) ((uint8 *) (this + 1) + objectsOffset);

This looks like another place where uintptr_t casting should come to the rescue of a gazillion casts:

>+        return reinterpret_cast<JSObjectArray *>(uintptr_t(this + 1) + objectsOffset);

(I tend to think readability is helped here by not having parentheses everywhere for everything here, so I'd change the outermost cast to a reinterpret_cast<> to make this easier on the eyes.)


>-        return (JSUpvarArray *) ((uint8 *) (this + 1) + upvarsOffset);
>+        return (JSUpvarArray *) (void *) ((uint8 *) (this + 1) + upvarsOffset);

And this:

>+        return reinterpret_cast<JSUpvarArray *>(uintptr_(this + 1) + upvarsOffset);


>-        return (JSObjectArray *) ((uint8 *) (this + 1) + regexpsOffset);
>+        return (JSObjectArray *) (void *) ((uint8 *) (this + 1) + regexpsOffset);

And this:

>+        return reinterpret_cast<JSObjectArray>(uintptr_t(this + 1) + regexpsOffset);


>-        return (JSTryNoteArray *) ((uint8 *) (this + 1) + trynotesOffset);
>+        return (JSTryNoteArray *) (void *) ((uint8 *) (this + 1) + trynotesOffset);

And this:

>+        return reinterpret_cast<JSTryNoteArray *>(uintptr_t(this + 1) + trynotesOffset);


>-        return (js::GlobalSlotArray *) ((uint8 *) (this + 1) + globalsOffset);
>+        return (js::GlobalSlotArray *) (void *) ((uint8 *) (this + 1) + globalsOffset);

And this:

>+        return reinterpret_cast<js::GlobalSlotArray *>(uintptr_t(this + 1) + globalsOffset);


>-        return (JSConstArray *) ((uint8 *) (this + 1) + constOffset);
>+        return (JSConstArray *) (void *) ((uint8 *) (this + 1) + constOffset);

And this:

>+        return reinterpret_cast<JSConstArray *>(uintptr_t(this + 1) + constOffset);


The same tests as mentioned in the other casting bug I just reviewed will also more than smoke out potential typos here.
Comment 3 :Ehsan Akhgari 2011-06-20 06:57:17 PDT
http://hg.mozilla.org/tracemonkey/rev/c0e8643e8e60
Comment 4 Chris Leary [:cdleary] (not checking bugmail) 2011-06-20 17:06:23 PDT
cdleary-bot mozilla-central merge info:
http://hg.mozilla.org/mozilla-central/rev/c0e8643e8e60

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