Skip to content

Commit d9f5f50

Browse files
Refactor warning macros (#5432)
* Refactor warning macros Replaces the scheme in H5warnings.h with a more compiler-agnostic one that relocates ifdef complexity to the warnings header file and uses better naming. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent aa9784e commit d9f5f50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+850
-782
lines changed

.clang-format

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,41 @@ StatementMacros:
8585
- H5E_END_TRY
8686
- H5_BEGIN_TAG
8787
- H5_END_TAG
88-
- H5_GCC_DIAG_OFF
89-
- H5_GCC_DIAG_ON
90-
- H5_CLANG_DIAG_OFF
91-
- H5_CLANG_DIAG_ON
92-
- H5_GCC_CLANG_DIAG_OFF
93-
- H5_GCC_CLANG_DIAG_ON
9488
- H5_LEAVE
89+
- H5_WARN_C11_EXTENSIONS_OFF
90+
- H5_WARN_C11_EXTENSIONS_ON
91+
- H5_WARN_CAST_ALIGNMENT_OFF
92+
- H5_WARN_CAST_ALIGNMENT_ON
93+
- H5_WARN_CAST_AWAY_CONST_OFF
94+
- H5_WARN_CAST_AWAY_CONST_ON
95+
- H5_WARN_DUPLICATED_BRANCHES_OFF
96+
- H5_WARN_DUPLICATED_BRANCHES_ON
97+
- H5_WARN_FLOAT_CONVERSION_OFF
98+
- H5_WARN_FLOAT_CONVERSION_ON
99+
- H5_WARN_FLOAT_EQUAL_OFF
100+
- H5_WARN_FLOAT_EQUAL_ON
101+
- H5_WARN_FORMAT_NONLITERAL_OFF
102+
- H5_WARN_FORMAT_NONLITERAL_ON
103+
- H5_WARN_FORMAT_TRUNCATION_OFF
104+
- H5_WARN_FORMAT_TRUNCATION_ON
105+
- H5_WARN_IMPLICIT_FALLTHROUGH_OFF
106+
- H5_WARN_IMPLICIT_FALLTHROUGH_ON
107+
- H5_WARN_LARGE_STACK_OBJECTS_OFF
108+
- H5_WARN_LARGE_STACK_OBJECTS_ON
109+
- H5_WARN_MISSING_PROTOTPYE_OFF
110+
- H5_WARN_MISSING_PROTOTPYE_ON
111+
- H5_WARN_MPI_STATUSES_IGNORE_OFF
112+
- H5_WARN_MPI_STATUSES_IGNORE_ON
113+
- H5_WARN_NONSTD_SUFFIX_OFF
114+
- H5_WARN_NONSTD_SUFFIX_ON
115+
- H5_WARN_OBJ_FXN_POINTER_CONVERSION_OFF
116+
- H5_WARN_OBJ_FXN_POINTER_CONVERSION_ON
117+
- H5_WARN_SIGN_CONVERSION_OFF
118+
- H5_WARN_SIGN_CONVERSION_ON
119+
- H5_WARN_UNUSED_PARAMETER_OFF
120+
- H5_WARN_UNUSED_PARAMETER_ON
121+
- H5_WARN_USELESS_COMPARISON_OFF
122+
- H5_WARN_USELESS_COMPARISON_ON
95123
- HGOTO_DONE
96124
- HMPI_DONE_ERROR
97125
- HMPI_ERROR

c++/test/tcompound.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ test_compound_2()
9898
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
9999
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
100100
for (i = 0; i < nelmts; i++) {
101-
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
101+
H5_WARN_CAST_ALIGNMENT_OFF
102+
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
103+
H5_WARN_CAST_ALIGNMENT_ON
102104
s_ptr->a = i * 8 + 0;
103105
s_ptr->b = i * 8 + 1;
104106
s_ptr->c[0] = i * 8 + 2;
@@ -139,8 +141,10 @@ test_compound_2()
139141

140142
// Compare results
141143
for (i = 0; i < nelmts; i++) {
144+
H5_WARN_CAST_ALIGNMENT_OFF
142145
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
143146
d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i;
147+
H5_WARN_CAST_ALIGNMENT_ON
144148
if (s_ptr->a != d_ptr->a || s_ptr->b != d_ptr->b || s_ptr->c[0] != d_ptr->c[0] ||
145149
s_ptr->c[1] != d_ptr->c[1] || s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] ||
146150
s_ptr->d != d_ptr->d || s_ptr->e != d_ptr->e) {
@@ -208,7 +212,9 @@ test_compound_3()
208212
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
209213
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
210214
for (i = 0; i < nelmts; i++) {
211-
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
215+
H5_WARN_CAST_ALIGNMENT_OFF
216+
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
217+
H5_WARN_CAST_ALIGNMENT_ON
212218
s_ptr->a = i * 8 + 0;
213219
s_ptr->b = i * 8 + 1;
214220
s_ptr->c[0] = i * 8 + 2;
@@ -247,8 +253,10 @@ test_compound_3()
247253

248254
/* Compare results */
249255
for (i = 0; i < nelmts; i++) {
256+
H5_WARN_CAST_ALIGNMENT_OFF
250257
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
251258
d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i;
259+
H5_WARN_CAST_ALIGNMENT_ON
252260
if (s_ptr->a != d_ptr->a || s_ptr->c[0] != d_ptr->c[0] || s_ptr->c[1] != d_ptr->c[1] ||
253261
s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] || s_ptr->e != d_ptr->e) {
254262
H5_FAILED();
@@ -320,7 +328,9 @@ test_compound_4()
320328
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
321329
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
322330
for (i = 0; i < nelmts; i++) {
323-
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
331+
H5_WARN_CAST_ALIGNMENT_OFF
332+
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
333+
H5_WARN_CAST_ALIGNMENT_ON
324334
s_ptr->a = i * 8 + 0;
325335
s_ptr->b = (i * 8 + 1) & 0x7fff;
326336
s_ptr->c[0] = i * 8 + 2;
@@ -361,8 +371,10 @@ test_compound_4()
361371

362372
/* Compare results */
363373
for (i = 0; i < nelmts; i++) {
374+
H5_WARN_CAST_ALIGNMENT_OFF
364375
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
365376
d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i;
377+
H5_WARN_CAST_ALIGNMENT_ON
366378
if (s_ptr->a != d_ptr->a || s_ptr->b != d_ptr->b || s_ptr->c[0] != d_ptr->c[0] ||
367379
s_ptr->c[1] != d_ptr->c[1] || s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] ||
368380
s_ptr->d != d_ptr->d || s_ptr->e != d_ptr->e) {
@@ -525,7 +537,9 @@ test_compound_6()
525537
bkg = static_cast<unsigned char *>(malloc(nelmts * sizeof(dst_typ_t)));
526538
orig = static_cast<unsigned char *>(malloc(nelmts * sizeof(src_typ_t)));
527539
for (i = 0; i < nelmts; i++) {
528-
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
540+
H5_WARN_CAST_ALIGNMENT_OFF
541+
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
542+
H5_WARN_CAST_ALIGNMENT_ON
529543
s_ptr->b = (i * 8 + 1) & 0x7fff;
530544
s_ptr->d = (i * 8 + 6) & 0x7fff;
531545
}
@@ -545,8 +559,10 @@ test_compound_6()
545559

546560
/* Compare results */
547561
for (i = 0; i < nelmts; i++) {
562+
H5_WARN_CAST_ALIGNMENT_OFF
548563
s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i;
549564
d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i;
565+
H5_WARN_CAST_ALIGNMENT_ON
550566
if (s_ptr->b != d_ptr->b || s_ptr->d != d_ptr->d) {
551567
H5_FAILED();
552568
cerr << " i=" << i << endl;

config/clang-warnings/general

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
-Wdouble-promotion
77
-Wextra
88
-Wformat=2
9+
-Wformat-nonliteral
910
-Wframe-larger-than=16384
1011
-Wimplicit-fallthrough
1112
-Wnull-dereference

config/gnu-warnings/5

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
-Warray-bounds=2
2-
-Wc99-c11-compat

config/gnu-warnings/general

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-Wextra
1313
-Wfloat-equal
1414
-Wformat=2
15+
-Wformat-nonliteral
1516
-Winit-self
1617
-Winvalid-pch
1718
-Wmissing-include-dirs

hl/fortran/src/H5TBfc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ h5tbmake_table_c(size_t_f *namelen1, _fcd name1, hid_t_f *loc_id, size_t_f *name
9292
/*
9393
* call H5TBmake_table function.
9494
*/
95-
H5_GCC_CLANG_DIAG_OFF("cast-qual")
95+
H5_WARN_CAST_AWAY_CONST_OFF
9696
if (H5TBmake_table(c_name1, (hid_t)*loc_id, c_name, c_nfields, (hsize_t)*nrecords, (size_t)*type_size,
9797
(const char **)c_field_names, c_field_offset, c_field_types, (hsize_t)*chunk_size,
9898
NULL, *compress, NULL) < 0)
9999
HGOTO_DONE(FAIL);
100-
H5_GCC_CLANG_DIAG_ON("cast-qual")
100+
H5_WARN_CAST_AWAY_CONST_ON
101101

102102
done:
103103
if (c_name)
@@ -195,12 +195,12 @@ h5tbmake_table_ptr_c(size_t_f *namelen1, _fcd name1, hid_t_f *loc_id, size_t_f *
195195
/*
196196
* call H5TBmake_table function.
197197
*/
198-
H5_GCC_CLANG_DIAG_OFF("cast-qual")
198+
H5_WARN_CAST_AWAY_CONST_OFF
199199
if (H5TBmake_table(c_name1, (hid_t)*loc_id, c_name, c_nfields, (hsize_t)*nrecords, (size_t)*type_size,
200200
(const char **)c_field_names, c_field_offset, c_field_types, (hsize_t)*chunk_size,
201201
fill_data, *compress, data) < 0)
202202
HGOTO_DONE(FAIL);
203-
H5_GCC_CLANG_DIAG_ON("cast-qual")
203+
H5_WARN_CAST_AWAY_CONST_ON
204204

205205
done:
206206
if (c_name)

hl/src/H5LT.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,13 +1256,13 @@ find_dataset(H5_ATTR_UNUSED hid_t loc_id, const char *name, H5_ATTR_UNUSED const
12561256
* modify the op_data buffer (i.e.: dset_name) during the traversal, and the
12571257
* library never modifies that buffer.
12581258
*/
1259-
H5_GCC_CLANG_DIAG_OFF("cast-qual")
1259+
H5_WARN_CAST_AWAY_CONST_OFF
12601260
herr_t
12611261
H5LTfind_dataset(hid_t loc_id, const char *dset_name)
12621262
{
12631263
return H5Literate2(loc_id, H5_INDEX_NAME, H5_ITER_INC, 0, find_dataset, (void *)dset_name);
12641264
}
1265-
H5_GCC_CLANG_DIAG_ON("cast-qual")
1265+
H5_WARN_CAST_AWAY_CONST_ON
12661266

12671267
/*-------------------------------------------------------------------------
12681268
*

java/src/jni/h5Constants.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern "C" {
1919
#include <stdlib.h>
2020
#include "h5jni.h"
2121

22-
H5_GCC_CLANG_DIAG_OFF("missing-prototypes")
23-
H5_GCC_CLANG_DIAG_OFF("unused-parameter")
22+
H5_WARN_MISSING_PROTOTYPE_OFF
23+
H5_WARN_UNUSED_PARAMETER_OFF
2424

2525
JNIEXPORT jlong JNICALL
2626
Java_hdf_hdf5lib_HDF5Constants_H5_1QUARTER_1HADDR_1MAX(JNIEnv *env, jclass cls)
@@ -1210,7 +1210,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5ES_1STATUS_1CANCELED(JNIEnv *env, jclass cls)
12101210
}
12111211

12121212
/* Java does not have unsigned native types */
1213-
H5_GCC_CLANG_DIAG_OFF("sign-conversion")
1213+
H5_WARN_SIGN_CONVERSION_OFF
12141214
JNIEXPORT jint JNICALL
12151215
Java_hdf_hdf5lib_HDF5Constants_H5F_1ACC_1CREAT(JNIEnv *env, jclass cls)
12161216
{
@@ -1251,7 +1251,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5F_1ACC_1SWMR_1WRITE(JNIEnv *env, jclass cls)
12511251
{
12521252
return H5F_ACC_SWMR_WRITE;
12531253
}
1254-
H5_GCC_CLANG_DIAG_ON("sign-conversion")
1254+
H5_WARN_SIGN_CONVERSION_ON
12551255

12561256
JNIEXPORT jint JNICALL
12571257
Java_hdf_hdf5lib_HDF5Constants_H5F_1CLOSE_1DEFAULT(JNIEnv *env, jclass cls)
@@ -1652,7 +1652,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5FD_1MEM_1DEFAULT_1GHEAP_1SIZE(JNIEnv *env, jcla
16521652
{
16531653
return (hsize_t)(3 * (HADDR_MAX / (H5FD_MEM_NTYPES - 1)));
16541654
}
1655-
H5_GCC_CLANG_DIAG_OFF("sign-conversion")
1655+
H5_WARN_SIGN_CONVERSION_OFF
16561656
JNIEXPORT jlong JNICALL
16571657
Java_hdf_hdf5lib_HDF5Constants_H5FD_1MEM_1DEFAULT_1LHEAP_1SIZE(JNIEnv *env, jclass cls)
16581658
{
@@ -1669,7 +1669,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5FD_1MEM_1DEFAULT_1OHDR_1SIZE(JNIEnv *env, jclas
16691669
/* XXX: BADNESS! - This value cannot fit into a jlong! */
16701670
return (hsize_t)(5 * (HADDR_MAX / (H5FD_MEM_NTYPES - 1)));
16711671
}
1672-
H5_GCC_CLANG_DIAG_ON("sign-conversion")
1672+
H5_WARN_SIGN_CONVERSION_ON
16731673

16741674
/* Symbols defined for compatibility with previous versions of the HDF5 API.
16751675
*
@@ -3800,8 +3800,8 @@ Java_hdf_hdf5lib_HDF5Constants_H5Z_1FILTER_1ALL(JNIEnv *env, jclass cls)
38003800
return H5Z_FILTER_ALL;
38013801
}
38023802

3803-
H5_GCC_CLANG_DIAG_ON("missing-prototypes")
3804-
H5_GCC_CLANG_DIAG_ON("unused-parameter")
3803+
H5_WARN_UNUSED_PARAMETER_ON
3804+
H5_WARN_MISSING_PROTOTYPE_ON
38053805

38063806
#ifdef __cplusplus
38073807
} /* end extern "C" */

src/H5Dint.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ H5FL_EXTERN(H5D_piece_info_t);
126126
/* Declare extern the free list to manage blocks of type conversion data */
127127
H5FL_BLK_EXTERN(type_conv);
128128

129-
/* Disable warning for intentional identical branches here -QAK */
130-
H5_GCC_DIAG_OFF("larger-than=")
131129
/* Define a static "default" dataset structure to use to initialize new datasets */
130+
H5_WARN_LARGE_STACK_OBJECTS_OFF
132131
static H5D_shared_t H5D_def_dset;
133-
H5_GCC_DIAG_ON("larger-than=")
132+
H5_WARN_LARGE_STACK_OBJECTS_ON
134133

135134
/* Dataset ID class */
136135
static const H5I_class_t H5I_DATASET_CLS[1] = {{

src/H5Dmpio.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,18 +4342,12 @@ H5D__mpio_share_chunk_modification_data(H5D_filtered_collective_io_info_t *chunk
43424342
else {
43434343
int all_sends_completed;
43444344

4345-
/* Determine if all send requests have completed
4346-
*
4347-
* gcc 11 complains about passing MPI_STATUSES_IGNORE as an MPI_Status
4348-
* array. See the discussion here:
4349-
*
4350-
* https://github.com/pmodels/mpich/issues/5687
4351-
*/
4352-
H5_GCC_DIAG_OFF("stringop-overflow")
4345+
/* Determine if all send requests have completed */
4346+
H5_WARN_MPI_STATUSES_IGNORE_OFF
43534347
if (MPI_SUCCESS != (mpi_code = MPI_Testall((int)num_send_requests, send_requests,
43544348
&all_sends_completed, MPI_STATUSES_IGNORE)))
43554349
HMPI_GOTO_ERROR(FAIL, "MPI_Testall failed", mpi_code)
4356-
H5_GCC_DIAG_ON("stringop-overflow")
4350+
H5_WARN_MPI_STATUSES_IGNORE_ON
43574351

43584352
if (all_sends_completed) {
43594353
/* Post non-blocking barrier */
@@ -4387,16 +4381,11 @@ H5D__mpio_share_chunk_modification_data(H5D_filtered_collective_io_info_t *chunk
43874381
* in the order that chunks are processed. So, the safest way to
43884382
* support both I/O modes is to simply make sure all messages
43894383
* are available.
4390-
*
4391-
* gcc 11 complains about passing MPI_STATUSES_IGNORE as an MPI_Status
4392-
* array. See the discussion here:
4393-
*
4394-
* https://github.com/pmodels/mpich/issues/5687
43954384
*/
4396-
H5_GCC_DIAG_OFF("stringop-overflow")
4385+
H5_WARN_MPI_STATUSES_IGNORE_OFF
43974386
if (MPI_SUCCESS != (mpi_code = MPI_Waitall((int)num_recv_requests, recv_requests, MPI_STATUSES_IGNORE)))
43984387
HMPI_GOTO_ERROR(FAIL, "MPI_Waitall failed", mpi_code)
4399-
H5_GCC_DIAG_ON("stringop-overflow")
4388+
H5_WARN_MPI_STATUSES_IGNORE_ON
44004389

44014390
/* Set the new number of locally-selected chunks */
44024391
chunk_list->num_chunk_infos = last_assigned_idx;

src/H5Eint.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,15 +1740,10 @@ H5E__set_stack_entry(H5E_error2_t *err_entry, const char *file, const char *func
17401740
if (ap) {
17411741
char *desc = NULL;
17421742

1743-
/* GCC complains about the 'fmt' parameter, but it's either from static
1744-
* strings in the library, which we know are OK, or from application
1745-
* error push calls, and the application should be sanity checking their
1746-
* strings.
1747-
*/
1748-
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
1743+
H5_WARN_FORMAT_NONLITERAL_OFF
17491744
if (HDvasprintf(&desc, fmt, *ap) < 0)
17501745
HGOTO_DONE(FAIL);
1751-
H5_GCC_CLANG_DIAG_ON("format-nonliteral")
1746+
H5_WARN_FORMAT_NONLITERAL_ON
17521747

17531748
err_entry->desc = desc;
17541749
}

0 commit comments

Comments
 (0)