GCC 4.6 Warning on 64-bit linux: "jsobjinlines.h:353:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]" (224 lines of output)

RESOLVED FIXED in mozilla8

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: dholbert, Assigned: dholbert)

Tracking

(Blocks: 1 bug)

Trunk
mozilla8
x86_64
Linux
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [build_warning])

Attachments

(2 attachments)

(Assignee)

Description

6 years ago
Created attachment 552163 [details]
the 224 lines of warning output

I get 224 lines of build warning spam resulting from this warning:
> jsobjinlines.h: In member function ‘void JSObject::setArrayLength(uint32)’:
> jsobjinlines.h:353:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

(See attached log of the warnings.)

The code in question is:
> 350 JSObject::setArrayLength(uint32 length)
> 351 {
> 352     JS_ASSERT(isArray());
> 353     setPrivate((void*) length);
> 354 }

If we simply convert |length| to a long (or unsigned long if you like) just before the void* cast, I think that should fix this.
(Assignee)

Comment 1

6 years ago
Created attachment 552166 [details] [diff] [review]
fix: add size_t cast

er, I meant s/long/size_t/ in previous comment.  (dbaron tells me that "long" isn't guaranteed to be 64-bit on 64-bit systems -- e.g. on win64, a long is 32-bit -- whereas size_t is (more?) guaranteed to be the same size as a pointer.)

Tagging bhackett for review, since he added this line in bug 584917.

(Note that I'm assuming the GCC warning is innocuous -- it seems like we're using the void*-cast to just set a generic payload value, rather than actually depending on it being a sane pointer in this case.)
Assignee: general → dholbert
Status: NEW → ASSIGNED
Attachment #552166 - Flags: review?(bhackett1024)
(Assignee)

Updated

6 years ago
Blocks: 584917
Comment on attachment 552166 [details] [diff] [review]
fix: add size_t cast

Yeah, this warning is innocuous.  setPrivate takes a void* but can hold any word-sized payload, and setArrayLength takes a uint32 because that is the range for an array length permitted by the JS language.
Attachment #552166 - Flags: review?(bhackett1024) → review+
(Assignee)

Comment 3

6 years ago
Great -- thanks for the quick review!

I'll land this in the next day or so.
(Assignee)

Updated

6 years ago
Blocks: 187528
Whiteboard: [build_warning]
(Assignee)

Comment 4

6 years ago
http://hg.mozilla.org/integration/mozilla-inbound/rev/129f83a789be
Whiteboard: [build_warning] → [build_warning][inbound]
Target Milestone: --- → mozilla8
https://hg.mozilla.org/mozilla-central/rev/129f83a789be
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Whiteboard: [build_warning][inbound] → [build_warning]
At risk of utter pedantry, the _u_nsigned _int_eger _p_oin_t_e_r_-sized type is uintptr_t.  :-)  But, come to think of it, there might actually be some crazy architecture which will notice this.  I think someone filed a bug along those lines in the last few months, actually.  rs=me if someone feels motivated to change this, in the absence of someone actively complaining about it.
(Assignee)

Comment 7

6 years ago
http://stackoverflow.com/questions/1464174/size-t-vs-intptr-t says Waldo is right, & size_t isn't technically what we want here.

Pushed a followup to fix both setArrayLength() (the function touched by the earlier patch) and getArrayLength() (which also used a void*<-->size_t cast, and hence also benefits from Waldo's insight as well):
  http://hg.mozilla.org/integration/mozilla-inbound/rev/88e9970b7e80
http://hg.mozilla.org/mozilla-central/rev/88e9970b7e80
You need to log in before you can comment on or make changes to this bug.