From 21aca4f380ac47b0c19d1926b13eaab0750406d0 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:42:40 -0700 Subject: Misc clang production warning fixes (#1932) * Misc clang production warning fixes * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- src/H5Cimage.c | 10 +++++----- src/H5FDmulti.c | 39 ++++++++++++++++++++++----------------- src/H5HLcache.c | 5 +++-- src/H5Tref.c | 25 ++++++++++++++----------- src/uthash.h | 45 +++++++++++++++++++++++---------------------- test/objcopy.c | 6 ++++++ test/objcopy_ref.c | 6 ++++++ 7 files changed, 79 insertions(+), 57 deletions(-) diff --git a/src/H5Cimage.c b/src/H5Cimage.c index 2a94fca..da4ac33 100644 --- a/src/H5Cimage.c +++ b/src/H5Cimage.c @@ -2784,8 +2784,6 @@ H5C__prep_for_file_close__scan_entries(const H5F_t *f, H5C_t *cache_ptr) size_t image_len; size_t entry_header_len; size_t fd_parents_list_len; - int i; - unsigned j; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -2862,7 +2860,7 @@ H5C__prep_for_file_close__scan_entries(const H5F_t *f, H5C_t *cache_ptr) HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for fd parent addrs buffer") - for (i = 0; i < (int)(entry_ptr->fd_parent_count); i++) { + for (int i = 0; i < (int)(entry_ptr->fd_parent_count); i++) { entry_ptr->fd_parent_addrs[i] = entry_ptr->flush_dep_parent[i]->addr; HDassert(H5F_addr_defined(entry_ptr->fd_parent_addrs[i])); } /* end for */ @@ -2946,12 +2944,14 @@ H5C__prep_for_file_close__scan_entries(const H5F_t *f, H5C_t *cache_ptr) HDassert(entries_visited == cache_ptr->index_len); HDassert(num_entries_in_image <= num_entries_tentatively_in_image); - j = 0; - for (i = H5C_MAX_RING_IN_IMAGE + 1; i <= H5C_RING_SB; i++) +#ifndef NDEBUG + unsigned j = 0; + for (int i = H5C_MAX_RING_IN_IMAGE + 1; i <= H5C_RING_SB; i++) j += cache_ptr->index_ring_len[i]; /* This will change */ HDassert(entries_visited == (num_entries_tentatively_in_image + j)); +#endif cache_ptr->num_entries_in_image = num_entries_in_image; entries_visited = 0; diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index 5f161aa..7849060 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -46,25 +46,30 @@ /* Macros for enabling/disabling particular GCC / clang warnings * - * These are (renamed) duplicates of macros in H5private.h. If you make changes - * here, be sure to update those as well. + * These are duplicated in H5private.h. If you make changes here, be sure to + * update those as well. * * (see the following web-sites for more info: * http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html * http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas */ -/* These pragmas are only implemented usefully in gcc 4.6+ */ -#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 -#define H5_MULTI_GCC_DIAG_JOINSTR(x, y) x y -#define H5_MULTI_GCC_DIAG_DO_PRAGMA(x) _Pragma(#x) -#define H5_MULTI_GCC_DIAG_PRAGMA(x) H5_MULTI_GCC_DIAG_DO_PRAGMA(GCC diagnostic x) - -#define H5_MULTI_GCC_DIAG_OFF(x) \ - H5_MULTI_GCC_DIAG_PRAGMA(push) H5_MULTI_GCC_DIAG_PRAGMA(ignored H5_MULTI_GCC_DIAG_JOINSTR("-W", x)) -#define H5_MULTI_GCC_DIAG_ON(x) H5_MULTI_GCC_DIAG_PRAGMA(pop) +#define H5_MULTI_DIAG_JOINSTR(x, y) x y +#define H5_MULTI_DIAG_DO_PRAGMA(x) _Pragma(#x) +#define H5_MULTI_DIAG_PRAGMA(x) H5_MULTI_DIAG_DO_PRAGMA(GCC diagnostic x) + +#define H5_MULTI_DIAG_OFF(x) \ + H5_MULTI_DIAG_PRAGMA(push) H5_MULTI_DIAG_PRAGMA(ignored H5_MULTI_DIAG_JOINSTR("-W", x)) +#define H5_MULTI_DIAG_ON(x) H5_MULTI_DIAG_PRAGMA(pop) + +/* Macros for enabling/disabling particular GCC / clang warnings. + * These macros should be used for warnings supported by both gcc and clang. + */ +#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__) +#define H5_MULTI_GCC_CLANG_DIAG_OFF(x) H5_MULTI_DIAG_OFF(x) +#define H5_MULTI_GCC_CLANG_DIAG_ON(x) H5_MULTI_DIAG_ON(x) #else -#define H5_MULTI_GCC_DIAG_OFF(x) -#define H5_MULTI_GCC_DIAG_ON(x) +#define H5_MULTI_GCC_CLANG_DIAG_OFF(x) +#define H5_MULTI_GCC_CLANG_DIAG_ON(x) #endif /* Loop through all mapped files */ @@ -2125,7 +2130,7 @@ compute_next(H5FD_multi_t *file) * tmp in the code below, but early (4.4.7, at least) gcc only * allows diagnostic pragmas to be toggled outside of functions. */ -H5_MULTI_GCC_DIAG_OFF("format-nonliteral") +H5_MULTI_GCC_CLANG_DIAG_OFF("format-nonliteral") static int open_members(H5FD_multi_t *file) { @@ -2163,7 +2168,7 @@ open_members(H5FD_multi_t *file) return 0; } -H5_MULTI_GCC_DIAG_ON("format-nonliteral") +H5_MULTI_GCC_CLANG_DIAG_ON("format-nonliteral") /*------------------------------------------------------------------------- * Function: H5FD_multi_delete @@ -2174,7 +2179,7 @@ H5_MULTI_GCC_DIAG_ON("format-nonliteral") * *------------------------------------------------------------------------- */ -H5_MULTI_GCC_DIAG_OFF("format-nonliteral") +H5_MULTI_GCC_CLANG_DIAG_OFF("format-nonliteral") static herr_t H5FD_multi_delete(const char *filename, hid_t fapl_id) { @@ -2228,7 +2233,7 @@ H5FD_multi_delete(const char *filename, hid_t fapl_id) return 0; } /* end H5FD_multi_delete() */ -H5_MULTI_GCC_DIAG_ON("format-nonliteral") +H5_MULTI_GCC_CLANG_DIAG_ON("format-nonliteral") /*------------------------------------------------------------------------- * Function: H5FD_multi_ctl diff --git a/src/H5HLcache.c b/src/H5HLcache.c index 4d78d0c..620704a 100644 --- a/src/H5HLcache.c +++ b/src/H5HLcache.c @@ -541,7 +541,6 @@ H5HL__cache_prefix_serialize(const H5_ATTR_NDEBUG_UNUSED H5F_t *f, void *_image, H5HL_prfx_t *prfx = (H5HL_prfx_t *)_thing; /* Pointer to local heap prefix to query */ H5HL_t *heap; /* Pointer to the local heap */ uint8_t *image = (uint8_t *)_image; /* Pointer into image buffer */ - size_t buf_size; /* expected size of the image buffer */ FUNC_ENTER_PACKAGE_NOERR @@ -558,11 +557,13 @@ H5HL__cache_prefix_serialize(const H5_ATTR_NDEBUG_UNUSED H5F_t *f, void *_image, heap = prfx->heap; HDassert(heap); +#ifndef NDEBUG /* Compute the buffer size */ - buf_size = heap->prfx_size; + size_t buf_size = heap->prfx_size; /* expected size of the image buffer */ if (heap->single_cache_obj) buf_size += heap->dblk_size; HDassert(len == buf_size); +#endif /* Update the free block value from the free list */ heap->free_block = heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL; diff --git a/src/H5Tref.c b/src/H5Tref.c index aea322a..f914b8d 100644 --- a/src/H5Tref.c +++ b/src/H5Tref.c @@ -961,13 +961,12 @@ done: static herr_t H5T__ref_disk_write(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, size_t src_size, H5R_type_t H5_ATTR_UNUSED src_type, H5VL_object_t *dst_file, void *dst_buf, - size_t dst_size, void *bg_buf) + size_t H5_ATTR_NDEBUG_UNUSED dst_size, void *bg_buf) { - const uint8_t *p = (const uint8_t *)src_buf; - uint8_t *q = (uint8_t *)dst_buf; - size_t buf_size_left = dst_size; - uint8_t *p_bg = (uint8_t *)bg_buf; - herr_t ret_value = SUCCEED; + const uint8_t *p = (const uint8_t *)src_buf; + uint8_t *q = (uint8_t *)dst_buf; + uint8_t *p_bg = (uint8_t *)bg_buf; + herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE H5T_REF_LOG_DEBUG(""); @@ -980,12 +979,14 @@ H5T__ref_disk_write(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, /* TODO Should get rid of bg stuff */ if (p_bg) { H5VL_blob_specific_args_t vol_cb_args; /* Arguments to VOL callback */ - size_t p_buf_size_left = dst_size; /* Skip the size / header */ p_bg += (sizeof(uint32_t) + H5R_ENCODE_HEADER_SIZE); + +#ifndef NDEBUG + size_t p_buf_size_left = dst_size; HDassert(p_buf_size_left > (sizeof(uint32_t) + H5R_ENCODE_HEADER_SIZE)); - p_buf_size_left -= (sizeof(uint32_t) + H5R_ENCODE_HEADER_SIZE); +#endif /* Set up VOL callback arguments */ vol_cb_args.op_type = H5VL_BLOB_DELETE; @@ -1000,12 +1001,14 @@ H5T__ref_disk_write(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, p += H5R_ENCODE_HEADER_SIZE; q += H5R_ENCODE_HEADER_SIZE; src_size -= H5R_ENCODE_HEADER_SIZE; - buf_size_left -= sizeof(uint32_t); + +#ifndef NDEBUG + size_t buf_size_left = dst_size - sizeof(uint32_t); + HDassert(buf_size_left > sizeof(uint32_t)); +#endif /* Set the size */ UINT32ENCODE(q, src_size); - HDassert(buf_size_left > sizeof(uint32_t)); - buf_size_left -= sizeof(uint32_t); /* Store blob */ if (H5VL_blob_put(dst_file, p, src_size, q, NULL) < 0) diff --git a/src/uthash.h b/src/uthash.h index ecf512d..b1e5cbb 100644 --- a/src/uthash.h +++ b/src/uthash.h @@ -699,28 +699,29 @@ typedef unsigned char uint8_t; hashv += (unsigned)(keylen); \ switch (_hj_k) { \ case 11: \ - hashv += ((unsigned)_hj_key[10] << 24); /* FALLTHROUGH */ \ - case 10: \ - hashv += ((unsigned)_hj_key[9] << 16); /* FALLTHROUGH */ \ - case 9: \ - hashv += ((unsigned)_hj_key[8] << 8); /* FALLTHROUGH */ \ - case 8: \ - _hj_j += ((unsigned)_hj_key[7] << 24); /* FALLTHROUGH */ \ - case 7: \ - _hj_j += ((unsigned)_hj_key[6] << 16); /* FALLTHROUGH */ \ - case 6: \ - _hj_j += ((unsigned)_hj_key[5] << 8); /* FALLTHROUGH */ \ - case 5: \ - _hj_j += _hj_key[4]; /* FALLTHROUGH */ \ - case 4: \ - _hj_i += ((unsigned)_hj_key[3] << 24); /* FALLTHROUGH */ \ - case 3: \ - _hj_i += ((unsigned)_hj_key[2] << 16); /* FALLTHROUGH */ \ - case 2: \ - _hj_i += ((unsigned)_hj_key[1] << 8); /* FALLTHROUGH */ \ - case 1: \ - _hj_i += _hj_key[0]; /* FALLTHROUGH */ \ - default:; \ + hashv += ((unsigned)_hj_key[10] << 24); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 10 : hashv += ((unsigned)_hj_key[9] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 9 : hashv += ((unsigned)_hj_key[8] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 8 : _hj_j += ((unsigned)_hj_key[7] << 24); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 7 : _hj_j += ((unsigned)_hj_key[6] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 6 : _hj_j += ((unsigned)_hj_key[5] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 5 : _hj_j += _hj_key[4]; \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 4 : _hj_i += ((unsigned)_hj_key[3] << 24); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 3 : _hj_i += ((unsigned)_hj_key[2] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 2 : _hj_i += ((unsigned)_hj_key[1] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 1 : _hj_i += _hj_key[0]; \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + default:; \ } \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ } while (0) diff --git a/test/objcopy.c b/test/objcopy.c index b0050f7..beb272b 100644 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -1678,11 +1678,17 @@ compare_groups(hid_t gid, hid_t gid2, hid_t pid, int depth, unsigned copy_flags) case H5O_TYPE_MAP: HDassert(0 && "maps not supported in native VOL connector"); + /* clang complains about implicit fallthrough here and + * our usual attributes and fall-through comments don't + * quiet the compiler. + */ + H5_CLANG_DIAG_OFF("implicit-fallthrough") case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: HDassert(0 && "Unknown type of object"); break; + H5_CLANG_DIAG_ON("implicit-fallthrough") } /* end switch */ /* Close objects */ diff --git a/test/objcopy_ref.c b/test/objcopy_ref.c index bee722a..12dc836 100644 --- a/test/objcopy_ref.c +++ b/test/objcopy_ref.c @@ -1390,11 +1390,17 @@ compare_groups(hid_t gid, hid_t gid2, hid_t pid, int depth, unsigned copy_flags) case H5O_TYPE_MAP: HDassert(0 && "maps not supported in native VOL connector"); + /* clang complains about implicit fallthrough here and + * our usual attributes and fall-through comments don't + * quiet the compiler. + */ + H5_CLANG_DIAG_OFF("implicit-fallthrough") case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: HDassert(0 && "Unknown type of object"); break; + H5_CLANG_DIAG_ON("implicit-fallthrough") } /* end switch */ /* Close objects */ -- cgit v0.12