The default bug view has changed. See this FAQ.

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

RESOLVED FIXED in mozilla7

Status

()

Core
JavaScript Engine
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

(Whiteboard: [fixed-in-tracemonkey])

Attachments

(1 attachment)

(Assignee)

Description

6 years ago
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);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(Assignee)

Comment 1

6 years ago
Created attachment 538141 [details] [diff] [review]
Patch (v1)
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+
(Assignee)

Comment 3

6 years ago
http://hg.mozilla.org/tracemonkey/rev/c0e8643e8e60
Whiteboard: [fixed-in-tracemonkey]
Target Milestone: --- → mozilla7
cdleary-bot mozilla-central merge info:
http://hg.mozilla.org/mozilla-central/rev/c0e8643e8e60
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.