From afe4ef8b8f63f13c0cb3a6d7eaff5dc761c3d2b1 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Wed, 24 Aug 2022 12:05:01 +0100 Subject: [PATCH] Fix test skipping in math_brute_force (#1475) Commit 9666ca3c ("[NFC] Fix sign-compare warnings in math_brute_force (#1467)", 2022-08-23) inadvertently changed the semantics of the if condition. The `i > gEndTestNumber` comparison was relying on `gEndTestNumber` being promoted to unsigned. When casting `i` to `int32_t`, this promotion no longer happens and as a result any tests given on the command line were being skipped. Use an unsigned type for `gStartTestNumber` and `gEndTestNumber` to eliminate the casts and any implicit conversions between signed and unsigned types. Signed-off-by: Sven van Haastregt --- test_conformance/math_brute_force/main.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test_conformance/math_brute_force/main.cpp b/test_conformance/math_brute_force/main.cpp index 45b6e97d..8cebff9d 100644 --- a/test_conformance/math_brute_force/main.cpp +++ b/test_conformance/math_brute_force/main.cpp @@ -58,8 +58,8 @@ static char appName[MAXPATHLEN] = ""; cl_device_id gDevice = NULL; cl_context gContext = NULL; cl_command_queue gQueue = NULL; -static int32_t gStartTestNumber = -1; -static int32_t gEndTestNumber = -1; +static size_t gStartTestNumber = ~0u; +static size_t gEndTestNumber = ~0u; int gSkipCorrectnessTesting = 0; static int gStopOnError = 0; static bool gSkipRestOfTests; @@ -129,9 +129,8 @@ static int doTest(const char *name) const Func *const temp_func = functionList + i; if (strcmp(temp_func->name, name) == 0) { - if ((gStartTestNumber != -1 - && static_cast(i) < gStartTestNumber) - || static_cast(i) > gEndTestNumber) + if ((gStartTestNumber != ~0u && i < gStartTestNumber) + || i > gEndTestNumber) { vlog("Skipping function #%d\n", i); return 0; @@ -468,7 +467,7 @@ static int ParseArgs(int argc, const char **argv) long number = strtol(arg, &t, 0); if (t != arg) { - if (-1 == gStartTestNumber) + if (~0u == gStartTestNumber) gStartTestNumber = (int32_t)number; else gEndTestNumber = gStartTestNumber + (int32_t)number;