Closed Bug 662962 Opened 13 years ago Closed 13 years ago

Silence the clang warnings issued because of alignment requirements increase when compiling jsscript.h

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla7

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

Details

(Whiteboard: [fixed-in-tracemonkey])

Attachments

(1 file)

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);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Attached patch Patch (v1)Splinter Review
Assignee: general → ehsan
Status: NEW → ASSIGNED
Attachment #538141 - Flags: review?(jwalden+bmo)
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.
Attachment #538141 - Flags: review?(jwalden+bmo) → review+
http://hg.mozilla.org/tracemonkey/rev/c0e8643e8e60
Whiteboard: [fixed-in-tracemonkey]
Target Milestone: --- → mozilla7
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: