[PATCH 2/5] ddraw/tests: Fix absolute value warnings. (Clang)

Chip Davis cdavis at codeweavers.com
Thu Mar 26 02:46:04 CDT 2020


I wanted to teach Clang not to emit these warnings, but they insisted
that yes, Clang really should warn on absolute values of differences. So
I gave up on that.

Signed-off-by: Chip Davis <cdavis at codeweavers.com>
---
 dlls/ddraw/tests/ddraw1.c | 15 ++++++++++-----
 dlls/ddraw/tests/ddraw2.c | 17 +++++++++++------
 dlls/ddraw/tests/ddraw4.c | 17 +++++++++++------
 dlls/ddraw/tests/ddraw7.c | 17 +++++++++++------
 dlls/ddraw/tests/visual.c | 13 +++++++++----
 5 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 5bfca430086..1e4405eb74a 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -49,15 +49,20 @@ struct create_window_thread_param
     HANDLE thread;
 };
 
+static inline unsigned int absdiff(unsigned int a, unsigned int b)
+{
+    return a > b ? a - b : b - a;
+}
+
 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
 {
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     return TRUE;
 }
 
@@ -11756,7 +11761,7 @@ static void test_depth_readback(void)
             depth = *((DWORD *)ptr) & z_mask;
             expected_depth = (x * (0.9 / 640.0) + y * (0.1 / 480.0)) * z_mask;
             max_diff = ((0.5f * 0.9f) / 640.0f) * z_mask;
-            ok(abs(expected_depth - depth) <= max_diff,
+            ok(absdiff(expected_depth, depth) <= max_diff,
                     "z_depth %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
                     z_depth, depth, expected_depth - depth, expected_depth, max_diff, x, y);
         }
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index b472b3d5883..c6e6ae9f794 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -50,15 +50,20 @@ struct create_window_thread_param
     HANDLE thread;
 };
 
+static inline unsigned int absdiff(unsigned int a, unsigned int b)
+{
+    return a > b ? a - b : b - a;
+}
+
 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
 {
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     return TRUE;
 }
 
@@ -12735,10 +12740,10 @@ static void test_depth_readback(void)
                 /* The ddraw2 version of this test behaves similarly to the ddraw7 version on Nvidia GPUs,
                  * except that we only have D16 (broken on geforce 9) and D24X8 (broken on geforce 7) available.
                  * Accept all nvidia GPUs as broken here, but still expect one of the formats to pass. */
-                ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
+                ok(absdiff(expected_depth, depth) <= max_diff || ddraw_is_nvidia(ddraw),
                         "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
                         i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
-                if (abs(expected_depth - depth) > max_diff)
+                if (absdiff(expected_depth, depth) > max_diff)
                     all_pass = FALSE;
             }
         }
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 1e6cf4c446a..e6c1b2c35a8 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -80,15 +80,20 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
             && compare_float(vec->w, w, ulps);
 }
 
+static inline unsigned int absdiff(unsigned int a, unsigned int b)
+{
+    return a > b ? a - b : b - a;
+}
+
 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
 {
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     return TRUE;
 }
 
@@ -15268,10 +15273,10 @@ static void test_depth_readback(void)
                  * returns 0 for that format. Give up on pre-filtering formats, accept Nvidia as generally
                  * broken here, but still expect at least one format (D16 or D24X8 in practise) to pass. */
                 todo_wine_if(tests[i].todo)
-                    ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
+                    ok(absdiff(expected_depth, depth) <= max_diff || ddraw_is_nvidia(ddraw),
                              "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
                              i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
-                if (abs(expected_depth - depth) > max_diff)
+                if (absdiff(expected_depth, depth) > max_diff)
                     all_pass = FALSE;
 
                 hr = IDirectDrawSurface4_Unlock(ds, &r);
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 5c0c5bb7c39..e7e5e756192 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -87,15 +87,20 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
             && compare_float(vec->w, w, ulps);
 }
 
+static inline unsigned int absdiff(unsigned int a, unsigned int b)
+{
+    return a > b ? a - b : b - a;
+}
+
 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
 {
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     return TRUE;
 }
 
@@ -14713,11 +14718,11 @@ static void test_depth_readback(void)
                  * Arx Fatalis is broken on the Geforce 9 in the same way it was broken in Wine (bug 43654).
                  * The !tests[i].s_depth is supposed to rule out D16 on GF9 and D24X8 on GF7. */
                 todo_wine_if(tests[i].todo)
-                    ok(abs(expected_depth - depth) <= max_diff
+                    ok(absdiff(expected_depth, depth) <= max_diff
                             || (ddraw_is_nvidia(ddraw) && (all_zero || all_one || !tests[i].s_depth)),
                             "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
                             i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
-                if (abs(expected_depth - depth) > max_diff)
+                if (absdiff(expected_depth, depth) > max_diff)
                     all_pass = FALSE;
 
                 hr = IDirectDrawSurface7_Unlock(ds, &r);
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c
index 2cb1c892314..4ae5958cd22 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -45,15 +45,20 @@ static BOOL refdevice = FALSE;
 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid,
         void **ddraw, REFIID interface_iid, IUnknown *outer);
 
+static inline unsigned int absdiff(unsigned int a, unsigned int b)
+{
+    return a > b ? a - b : b - a;
+}
+
 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
 {
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     c1 >>= 8; c2 >>= 8;
-    if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+    if (absdiff(c1 & 0xff, c2 & 0xff) > max_diff) return FALSE;
     return TRUE;
 }
 
-- 
2.24.0




More information about the wine-devel mailing list