From 0ad07fa95431ca25129ffb2c89e4545fdd7b266c Mon Sep 17 00:00:00 2001 From: Ravindu-Hirimuthugoda Date: Sat, 15 Jul 2023 14:56:49 +0530 Subject: [PATCH] Fix clang warning --- include/nomp-log.h | 17 +++++++++++++++-- tests/nomp-api-105.c | 4 ++-- tests/nomp-test.h | 11 ++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/nomp-log.h b/include/nomp-log.h index ac42b73d..b13a2307 100644 --- a/include/nomp-log.h +++ b/include/nomp-log.h @@ -47,8 +47,21 @@ int nomp_log_set_verbose(const int verbose); int nomp_log_(const char *desc, int logno, nomp_log_type type, const char *fname, unsigned line_no, ...); -#define nomp_log(logno, type, desc, ...) \ - nomp_log_(desc, logno, type, __FILE__, __LINE__, ##__VA_ARGS__) +#define NOMP_CASE_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define NOMP_CASE(...) NOMP_CASE_IMPL(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0) + +#define NOMP_FIRST_IMPL(first, ...) first +#define NOMP_FIRST(...) NOMP_FIRST_IMPL(__VA_ARGS__, throwaway) + +#define NOMP_REST_IMPL_WITH_2(first, ...) , __VA_ARGS__ +#define NOMP_REST_IMPL_WITH_1(first) +#define NOMP_REST_IMPL_(num, ...) NOMP_REST_IMPL_WITH_##num(__VA_ARGS__) +#define NOMP_REST_IMPL(num, ...) NOMP_REST_IMPL_(num, __VA_ARGS__) +#define NOMP_REST(...) NOMP_REST_IMPL(NOMP_CASE(__VA_ARGS__), __VA_ARGS__) + +#define nomp_log(logno, type, ...) \ + nomp_log_(NOMP_FIRST(__VA_ARGS__), logno, type, __FILE__, \ + __LINE__ NOMP_REST(__VA_ARGS__)) /** * @ingroup nomp_log_utils diff --git a/tests/nomp-api-105.c b/tests/nomp-api-105.c index 277289a0..781bc7e4 100644 --- a/tests/nomp-api-105.c +++ b/tests/nomp-api-105.c @@ -7,14 +7,14 @@ // Calling nomp_jit() with valid functions should not return an error. static int test_valid_clauses(void) { int err = 0; - TEST_BUILTIN_TYPES(105_valid); + TEST_BUILTIN_TYPES(105_valid, ); return err; } // Calling nomp_jit() with invalid functions should return an error. static int test_invalid_clauses(void) { int err = 0; - TEST_BUILTIN_TYPES(105_invalid); + TEST_BUILTIN_TYPES(105_invalid, ); return err; } diff --git a/tests/nomp-test.h b/tests/nomp-test.h index 378c1d12..5089d3b6 100644 --- a/tests/nomp-test.h +++ b/tests/nomp-test.h @@ -47,7 +47,16 @@ inline static int subtest_(int err, const char *test_name) { printf("\t%s: %s\033[0m\n", test_name, result); return err; } -#define SUBTEST(subtest, ...) subtest_(subtest(__VA_ARGS__), TOSTRING(subtest)) +#define TEST_ARGS_CASE_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define TEST_ARGS_CASE(...) \ + TEST_ARGS_CASE_IMPL(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0) + +#define SUBTEST_IMPL_WITH_2(subtest, ...) \ + subtest_(subtest(__VA_ARGS__), TOSTRING(subtest)) +#define SUBTEST_IMPL_WITH_1(subtest) subtest_(subtest(), TOSTRING(subtest)) +#define SUBTEST_IMPL_(num, ...) SUBTEST_IMPL_WITH_##num(__VA_ARGS__) +#define SUBTEST_IMPL(num, ...) SUBTEST_IMPL_(num, __VA_ARGS__) +#define SUBTEST(...) SUBTEST_IMPL(TEST_ARGS_CASE(__VA_ARGS__), __VA_ARGS__) #define nomp_test_assert(cond) \ { \