Skip to content

Commit

Permalink
core: fix: cast-function-type -> ..-strict clang
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <[email protected]>
  • Loading branch information
grom72 committed Jan 29, 2025
1 parent cb474ec commit 4061c9e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
11 changes: 11 additions & 0 deletions src/core/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright 2014-2024, Intel Corporation */
/* Copyright 2025 Hewlett Packard Enterprise Development LP */
/*
* Copyright (c) 2016-2020, Microsoft Corporation. All rights reserved.
*
Expand Down Expand Up @@ -331,6 +332,16 @@ char *util_concat_str(const char *s1, const char *s2);
#define SUPPRESS_ARG_8(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_7(__VA_ARGS__)
#define SUPPRESS_ARG_9(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_8(__VA_ARGS__)

#if __clang__
#define CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN(exp) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wcast-function-type-strict\"") \
exp; \
_Pragma("clang diagnostic pop")
#else
#define CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN(exp) exp
#endif

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/libpmem/libpmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ int
pmem_log_set_function(pmem_log_function *log_function)
{

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
int ret = core_log_set_function((core_log_function *)log_function);
#pragma GCC diagnostic pop
int ret;
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
ret = core_log_set_function((core_log_function *)log_function));
return core_log_error_translate(ret);
}
24 changes: 10 additions & 14 deletions src/libpmemobj/lane.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,19 @@ lane_init(PMEMobjpool *pop, struct lane *lane, struct lane_layout *layout)
if (lane->internal == NULL)
goto error_internal_new;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
lane->external = operation_new((struct ulog *)&layout->external,
LANE_REDO_EXTERNAL_SIZE,
lane_redo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_REDO);
#pragma GCC diagnostic pop
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
lane->external = operation_new((struct ulog *)&layout->external, \
LANE_REDO_EXTERNAL_SIZE, \
lane_redo_extend, (ulog_free_fn)pfree, &pop->p_ops, \
LOG_TYPE_REDO));
if (lane->external == NULL)
goto error_external_new;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
lane->undo = operation_new((struct ulog *)&layout->undo,
LANE_UNDO_SIZE,
lane_undo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_UNDO);
#pragma GCC diagnostic pop
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
lane->undo = operation_new((struct ulog *)&layout->undo, \
LANE_UNDO_SIZE, \
lane_undo_extend, (ulog_free_fn)pfree, &pop->p_ops, \
LOG_TYPE_UNDO));
if (lane->undo == NULL)
goto error_undo_new;

Expand Down
7 changes: 3 additions & 4 deletions src/libpmemobj/obj_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold,
int
pmemobj_log_set_function(pmemobj_log_function *log_function)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
int ret = core_log_set_function((core_log_function *)log_function);
#pragma GCC diagnostic pop
int ret;
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
ret = core_log_set_function((core_log_function *)log_function));
return core_log_error_translate(ret);
}
8 changes: 4 additions & 4 deletions src/test/ctl_prefault/ctl_prefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ main(int argc, char *argv[])
int prefault = atoi(argv[2]);
int open = atoi(argv[3]);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
prefault_fun(prefault, (fun)pmemobj_ctl_get, (fun)pmemobj_ctl_set);
#pragma GCC diagnostic pop
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
prefault_fun(prefault, \
(fun)pmemobj_ctl_get, \
(fun)pmemobj_ctl_set));
test_obj(path, open);

DONE(NULL);
Expand Down
39 changes: 18 additions & 21 deletions src/test/obj_memops/obj_memops.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,11 @@ test_same_twice(struct operation_context *ctx, struct test_object *object)
static void
test_redo(PMEMobjpool *pop, struct test_object *object)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
#pragma GCC diagnostic pop
struct operation_context *ctx;
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
ctx = operation_new((struct ulog *)&object->redo, TEST_ENTRIES, \
pmalloc_redo_extend, (ulog_free_fn)pfree, &pop->p_ops, \
LOG_TYPE_REDO));

/*
* Keep this test first.
Expand Down Expand Up @@ -624,13 +622,12 @@ static void
test_redo_cleanup_same_size(PMEMobjpool *pop, struct test_object *object)
{
#define ULOG_SIZE 1024
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
#pragma GCC diagnostic pop
struct operation_context *ctx;
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
ctx = operation_new((struct ulog *)&object->redo, \
TEST_ENTRIES, \
pmalloc_redo_extend, (ulog_free_fn)pfree, \
&pop->p_ops, LOG_TYPE_REDO));

int ret = pmalloc(pop, &object->redo.next, ULOG_SIZE, 0, 0);
UT_ASSERTeq(ret, 0);
Expand All @@ -655,13 +652,13 @@ test_redo_cleanup_same_size(PMEMobjpool *pop, struct test_object *object)
static void
test_undo(PMEMobjpool *pop, struct test_object *object)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
struct operation_context *ctx = operation_new(
(struct ulog *)&object->undo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_UNDO);
#pragma GCC diagnostic pop
struct operation_context *ctx;
CLANG_IGNORE_CAST_FUNCTION_STRICT_WARN( \
ctx = operation_new((struct ulog *)&object->undo, \
TEST_ENTRIES, \
pmalloc_redo_extend, \
(ulog_free_fn)pfree, \
&pop->p_ops, LOG_TYPE_UNDO));

test_undo_small_single_copy(ctx, object);
test_undo_small_single_set(ctx, object);
Expand Down

0 comments on commit 4061c9e

Please sign in to comment.