Closed Bug 1115477 Opened 10 years ago Closed 9 years ago

Fix -Wunused and -Wtype-limits warnings in js/src

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla37

People

(Reporter: cpeterson, Assigned: cpeterson)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Variable `id` is an object, but the printf format string specifies %d:

> js/ipc/JavaScriptLogging.h:118: warning: cannot pass objects of non-POD type 'class mozilla::jsipc::ObjectId' through '...'; call will abort at runtime

On x86 and x86-64 platforms, PostStorePrePopFP is only used in debug builds:

> js/src/asmjs/AsmJSFrameIterator.cpp:119:23 [-Wunused-const-variable] unused variable 'PostStorePrePopFP'

These `id_*` getter functions are only used in debug builds:

> js/src/jsinfer.cpp:57:1 [-Wunused-function] unused function 'id___proto__'
> js/src/jsinfer.cpp:62:1 [-Wunused-function] unused function 'id_constructor'
> js/src/jsinfer.cpp:67:1 [-Wunused-function] unused function 'id_caller'

clang complains that private member variable `padding` is never read or written. Making `padding` protected instead of private is kinda hacky, but it suppresses this -Wunused warning (because a derived class could theoretically use this protected member variable). Also convert redundant `typedef enum JSTryNoteKind` definition to `enum JSTryNoteKind`.

> js/src/jsscript.h:1876:14: error: private field 'padding' is not used [-Wunused-private-field]

The templatized `chars` parameter may be a Latin1Char or char16_t string. If `chars` is Latin1Char, then the comparison with UNIT_STATIC_LIMIT (constant 256U) is always true. To suppress this warning, copy chars into a char16_t. The StaticStrings::getUnitStringForElement() function does something similar:

https://mxr.mozilla.org/mozilla-central/source/js/src/vm/String-inl.h#372

> js/src/vm/String.cpp:778:27 [-Wtype-limits] comparison is always true due to limited range of data type
> js/src/vm/String.cpp:778:25: warning: comparison of constant 256 with expression of type 'const unsigned char' is always true [-Wtautological-constant-out-of-range-compare]
Attachment #8541390 - Flags: review?(jdemooij)
Comment on attachment 8541390 [details] [diff] [review]
fix-js-warnings.patch

Review of attachment 8541390 [details] [diff] [review]:
-----------------------------------------------------------------

Great, thanks!

::: js/src/jsinfer.cpp
@@ +49,5 @@
>  using mozilla::PodZero;
>  
>  static inline jsid
>  id_prototype(JSContext *cx) {
>      return NameToId(cx->names().prototype);

Pre-existing nit: while you're here, would you mind moving the "{" to its own line? Same for the functions below. See types::TypeIdStringImpl below for what it should look like.
Attachment #8541390 - Flags: review?(jdemooij) → review+
https://hg.mozilla.org/mozilla-central/rev/2fbdaa8a5ea7
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla37
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: