Bug 1030521 - Make CHECK_EQUAL require its actual/expected expressions have the same signedness, to prevent introduction of compiler warnings. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Wed, 25 Jun 2014 18:47:04 -0700
changeset 191303 3c4cde5836b3509ec33b7b61aefc4054bc400427
parent 191302 97daabb8edbb2bfb9f68c65edffb5e8daa7a19ce
child 191304 d4500ef33c1249a9d8bc9acc4ea4b5e61def8919
push id7510
push userphilringnalda@gmail.com
push dateSun, 29 Jun 2014 03:53:28 +0000
treeherderfx-team@60468194f3d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1030521
milestone33.0a1
Bug 1030521 - Make CHECK_EQUAL require its actual/expected expressions have the same signedness, to prevent introduction of compiler warnings. r=jorendorff
js/src/jsapi-tests/testArrayBuffer.cpp
js/src/jsapi-tests/testGCOutOfMemory.cpp
js/src/jsapi-tests/testMappedArrayBuffer.cpp
js/src/jsapi-tests/testNewObject.cpp
js/src/jsapi-tests/testRegExp.cpp
js/src/jsapi-tests/testResolveRecursion.cpp
js/src/jsapi-tests/testScriptInfo.cpp
js/src/jsapi-tests/testTypedArrays.cpp
js/src/jsapi-tests/tests.h
js/src/jsapi.h
--- a/js/src/jsapi-tests/testArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testArrayBuffer.cpp
@@ -51,26 +51,26 @@ BEGIN_TEST(testArrayBuffer_bug720949_ste
         CHECK_SAME(v, INT_TO_JSVAL(MAGIC_VALUE_2));
 
         // Steal the contents
         void *contents = JS_StealArrayBufferContents(cx, obj);
         CHECK(contents != nullptr);
         CHECK(data != nullptr);
 
         // Check that the original ArrayBuffer is neutered
-        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0);
+        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0u);
         CHECK(JS_GetProperty(cx, obj, "byteLength", &v));
         CHECK_SAME(v, INT_TO_JSVAL(0));
         CHECK(JS_GetProperty(cx, view, "byteLength", &v));
         CHECK_SAME(v, INT_TO_JSVAL(0));
         CHECK(JS_GetProperty(cx, view, "byteOffset", &v));
         CHECK_SAME(v, INT_TO_JSVAL(0));
         CHECK(JS_GetProperty(cx, view, "length", &v));
         CHECK_SAME(v, INT_TO_JSVAL(0));
-        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0);
+        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0u);
         v = JSVAL_VOID;
         JS_GetElement(cx, obj, 0, &v);
         CHECK_SAME(v, JSVAL_VOID);
 
         // Transfer to a new ArrayBuffer
         JS::RootedObject dst(cx, JS_NewArrayBufferWithContents(cx, size, contents));
         CHECK(JS_IsArrayBufferObject(dst));
         data = JS_GetStableArrayBufferData(cx, obj);
--- a/js/src/jsapi-tests/testGCOutOfMemory.cpp
+++ b/js/src/jsapi-tests/testGCOutOfMemory.cpp
@@ -29,30 +29,30 @@ BEGIN_TEST(testGCOutOfMemory)
         "        array.push({});"
         "    array = []; array.push(0);"
         "})();";
     bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root);
 
     /* Check that we get OOM. */
     CHECK(!ok);
     CHECK(!JS_IsExceptionPending(cx));
-    CHECK_EQUAL(errorCount, 1);
+    CHECK_EQUAL(errorCount, 1u);
     JS_GC(rt);
 
     // Temporarily disabled to reopen the tree. Bug 847579.
     return true;
 
     EVAL("(function() {"
          "    var array = [];"
          "    for (var i = max >> 2; i != 0;) {"
          "        --i;"
          "        array.push({});"
          "    }"
          "})();", &root);
-    CHECK_EQUAL(errorCount, 1);
+    CHECK_EQUAL(errorCount, 1u);
     return true;
 }
 
 virtual JSRuntime * createRuntime() {
     JSRuntime *rt = JS_NewRuntime(768 * 1024);
     if (!rt)
         return nullptr;
     setNativeStackQuota(rt);
--- a/js/src/jsapi-tests/testMappedArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testMappedArrayBuffer.cpp
@@ -67,33 +67,33 @@ JSObject *CreateNewObject(const int offs
     JSObject *obj = JS_NewMappedArrayBufferWithContents(cx, length, ptr);
     if (!obj) {
         JS_ReleaseMappedArrayBufferContents(ptr, length);
         return nullptr;
     }
     return obj;
 }
 
-bool VerifyObject(JS::HandleObject obj, const int offset, const int length, const bool mapped)
+bool VerifyObject(JS::HandleObject obj, uint32_t offset, uint32_t length, const bool mapped)
 {
     CHECK(obj);
     CHECK(JS_IsArrayBufferObject(obj));
     CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), length);
     if (mapped)
         CHECK(JS_IsMappedArrayBufferObject(obj));
     else
         CHECK(!JS_IsMappedArrayBufferObject(obj));
     const char *data = reinterpret_cast<const char *>(JS_GetArrayBufferData(obj));
     CHECK(data);
     CHECK(memcmp(data, test_data + offset, length) == 0);
 
     return true;
 }
 
-bool TestCreateObject(const int offset, const int length)
+bool TestCreateObject(uint32_t offset, uint32_t length)
 {
     JS::RootedObject obj(cx, CreateNewObject(offset, length));
     CHECK(VerifyObject(obj, offset, length, true));
 
     return true;
 }
 
 bool TestReleaseContents()
--- a/js/src/jsapi-tests/testNewObject.cpp
+++ b/js/src/jsapi-tests/testNewObject.cpp
@@ -64,26 +64,26 @@ BEGIN_TEST(testNewObject_1)
 
     // With no arguments.
     JS::RootedObject obj(cx, JS_New(cx, Array, JS::HandleValueArray::empty()));
     CHECK(obj);
     JS::RootedValue rt(cx, JS::ObjectValue(*obj));
     CHECK(JS_IsArrayObject(cx, obj));
     uint32_t len;
     CHECK(JS_GetArrayLength(cx, obj, &len));
-    CHECK_EQUAL(len, 0);
+    CHECK_EQUAL(len, 0u);
 
     // With one argument.
     argv[0].setInt32(4);
     obj = JS_New(cx, Array, JS::HandleValueArray::subarray(argv, 0, 1));
     CHECK(obj);
     rt = OBJECT_TO_JSVAL(obj);
     CHECK(JS_IsArrayObject(cx, obj));
     CHECK(JS_GetArrayLength(cx, obj, &len));
-    CHECK_EQUAL(len, 4);
+    CHECK_EQUAL(len, 4u);
 
     // With N arguments.
     for (size_t i = 0; i < N; i++)
         argv[i].setInt32(i);
     obj = JS_New(cx, Array, JS::HandleValueArray::subarray(argv, 0, N));
     CHECK(obj);
     rt = OBJECT_TO_JSVAL(obj);
     CHECK(JS_IsArrayObject(cx, obj));
--- a/js/src/jsapi-tests/testRegExp.cpp
+++ b/js/src/jsapi-tests/testRegExp.cpp
@@ -22,17 +22,17 @@ END_TEST(testObjectIsRegExp)
 
 BEGIN_TEST(testGetRegExpFlags)
 {
     JS::RootedValue val(cx);
     JS::RootedObject obj(cx);
 
     EVAL("/foopy/", &val);
     obj = val.toObjectOrNull();
-    CHECK_EQUAL(JS_GetRegExpFlags(cx, obj), 0);
+    CHECK_EQUAL(JS_GetRegExpFlags(cx, obj), 0u);
 
     EVAL("/foopy/g", &val);
     obj = val.toObjectOrNull();
     CHECK_EQUAL(JS_GetRegExpFlags(cx, obj), JSREG_GLOB);
 
     EVAL("/foopy/gi", &val);
     obj = val.toObjectOrNull();
     CHECK_EQUAL(JS_GetRegExpFlags(cx, obj), (JSREG_FOLD | JSREG_GLOB));
--- a/js/src/jsapi-tests/testResolveRecursion.cpp
+++ b/js/src/jsapi-tests/testResolveRecursion.cpp
@@ -57,18 +57,18 @@ BEGIN_TEST(testResolveRecursion)
     obj2 = nullptr;
     JS::RemoveObjectRoot(cx, &obj1);
     JS::RemoveObjectRoot(cx, &obj2);
     return true;
 }
 
 JS::Heap<JSObject *> obj1;
 JS::Heap<JSObject *> obj2;
-unsigned resolveEntryCount;
-unsigned resolveExitCount;
+int resolveEntryCount;
+int resolveExitCount;
 
 struct AutoIncrCounters {
 
     explicit AutoIncrCounters(cls_testResolveRecursion *t) : t(t) {
         t->resolveEntryCount++;
     }
 
     ~AutoIncrCounters() {
--- a/js/src/jsapi-tests/testScriptInfo.cpp
+++ b/js/src/jsapi-tests/testScriptInfo.cpp
@@ -32,17 +32,17 @@ BEGIN_TEST(testScriptInfo)
     JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code),
                                                  options));
 
     CHECK(script);
 
     jsbytecode *start = JS_LineNumberToPC(cx, script, startLine);
     CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine);
     CHECK_EQUAL(JS_PCToLineNumber(cx, script, start), startLine);
-    CHECK_EQUAL(JS_GetScriptLineExtent(cx, script), 11);
+    CHECK_EQUAL(JS_GetScriptLineExtent(cx, script), 11u);
     CHECK(strcmp(JS_GetScriptFilename(script), __FILE__) == 0);
     const jschar *sourceMap = JS_GetScriptSourceMap(cx, script);
     CHECK(sourceMap);
     CHECK(CharsMatch(sourceMap, "http://example.com/path/to/source-map.json"));
 
     return true;
 }
 static bool
--- a/js/src/jsapi-tests/testTypedArrays.cpp
+++ b/js/src/jsapi-tests/testTypedArrays.cpp
@@ -67,18 +67,18 @@ TestPlainTypedArray(JSContext *cx)
     RootedObject array(cx, Create(cx, 7));
     CHECK(JS_IsTypedArrayObject(array));
     RootedObject proto(cx);
     JS_GetPrototype(cx, array, &proto);
     CHECK(!JS_IsTypedArrayObject(proto));
     RootedObject dummy(cx, JS_GetParent(proto));
     CHECK(!JS_IsTypedArrayObject(dummy));
 
-    CHECK_EQUAL(JS_GetTypedArrayLength(array), 7);
-    CHECK_EQUAL(JS_GetTypedArrayByteOffset(array), 0);
+    CHECK_EQUAL(JS_GetTypedArrayLength(array), 7u);
+    CHECK_EQUAL(JS_GetTypedArrayByteOffset(array), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(array), sizeof(Element) * 7);
 
     Element *data;
     CHECK(data = GetData(array));
     *data = 13;
     RootedValue v(cx);
     CHECK(JS_GetElement(cx, array, 0, &v));
     CHECK_SAME(v, INT_TO_JSVAL(13));
@@ -102,31 +102,31 @@ TestArrayFromBuffer(JSContext *cx)
 
     {
         RootedObject notArray(cx, CreateWithBuffer(cx, buffer, UINT32_MAX, -1));
         CHECK(!notArray);
     }
 
     RootedObject array(cx, CreateWithBuffer(cx, buffer, 0, -1));
     CHECK_EQUAL(JS_GetTypedArrayLength(array), elts);
-    CHECK_EQUAL(JS_GetTypedArrayByteOffset(array), 0);
+    CHECK_EQUAL(JS_GetTypedArrayByteOffset(array), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(array), nbytes);
     CHECK_EQUAL(JS_GetArrayBufferViewBuffer(cx, array), (JSObject*) buffer);
 
     Element *data;
     CHECK(data = GetData(array));
     CHECK(bufdata = JS_GetStableArrayBufferData(cx, buffer));
     CHECK_EQUAL((void*) data, (void*) bufdata);
 
-    CHECK_EQUAL(*bufdata, 1);
-    CHECK_EQUAL(*reinterpret_cast<uint8_t*>(data), 1);
+    CHECK_EQUAL(*bufdata, 1u);
+    CHECK_EQUAL(*reinterpret_cast<uint8_t*>(data), 1u);
 
     RootedObject shortArray(cx, CreateWithBuffer(cx, buffer, 0, elts / 2));
     CHECK_EQUAL(JS_GetTypedArrayLength(shortArray), elts / 2);
-    CHECK_EQUAL(JS_GetTypedArrayByteOffset(shortArray), 0);
+    CHECK_EQUAL(JS_GetTypedArrayByteOffset(shortArray), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(shortArray), nbytes / 2);
 
     RootedObject ofsArray(cx, CreateWithBuffer(cx, buffer, nbytes / 2, -1));
     CHECK_EQUAL(JS_GetTypedArrayLength(ofsArray), elts / 2);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(ofsArray), nbytes / 2);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(ofsArray), nbytes / 2);
 
     // Make sure all 3 views reflect the same buffer at the expected locations
--- a/js/src/jsapi-tests/tests.h
+++ b/js/src/jsapi-tests/tests.h
@@ -2,16 +2,18 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef jsapi_tests_tests_h
 #define jsapi_tests_tests_h
 
+#include "mozilla/TypeTraits.h"
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "jsalloc.h"
 #include "jscntxt.h"
 #include "jsgc.h"
@@ -156,17 +158,22 @@ class JSAPITest
     }
 
     // Note that in some still-supported GCC versions (we think anything before
     // GCC 4.6), this template does not work when the second argument is
     // nullptr. It infers type U = long int. Use CHECK_NULL instead.
     template <typename T, typename U>
     bool checkEqual(const T &actual, const U &expected,
                     const char *actualExpr, const char *expectedExpr,
-                    const char *filename, int lineno) {
+                    const char *filename, int lineno)
+    {
+        static_assert(mozilla::IsSigned<T>::value == mozilla::IsSigned<U>::value,
+                      "using CHECK_EQUAL with different-signed inputs triggers compiler warnings");
+        static_assert(mozilla::IsUnsigned<T>::value == mozilla::IsUnsigned<U>::value,
+                      "using CHECK_EQUAL with different-signed inputs triggers compiler warnings");
         return (actual == expected) ||
             fail(JSAPITestString("CHECK_EQUAL failed: expected (") +
                  expectedExpr + ") = " + toSource(expected) +
                  ", got (" + actualExpr + ") = " + toSource(actual), filename, lineno);
     }
 
 #define CHECK_EQUAL(actual, expected) \
     do { \
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4655,20 +4655,20 @@ JS_ObjectIsDate(JSContext *cx, JS::Handl
 extern JS_PUBLIC_API(void)
 JS_ClearDateCaches(JSContext *cx);
 
 /************************************************************************/
 
 /*
  * Regular Expressions.
  */
-#define JSREG_FOLD      0x01    /* fold uppercase to lowercase */
-#define JSREG_GLOB      0x02    /* global exec, creates array of matches */
-#define JSREG_MULTILINE 0x04    /* treat ^ and $ as begin and end of line */
-#define JSREG_STICKY    0x08    /* only match starting at lastIndex */
+#define JSREG_FOLD      0x01u   /* fold uppercase to lowercase */
+#define JSREG_GLOB      0x02u   /* global exec, creates array of matches */
+#define JSREG_MULTILINE 0x04u   /* treat ^ and $ as begin and end of line */
+#define JSREG_STICKY    0x08u   /* only match starting at lastIndex */
 
 extern JS_PUBLIC_API(JSObject *)
 JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, char *bytes, size_t length,
                    unsigned flags);
 
 extern JS_PUBLIC_API(JSObject *)
 JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, jschar *chars, size_t length,
                      unsigned flags);