Skip to content

Commit 5c6c7ff

Browse files
committed
opal: cleanup with clang-tidy readability-braces-around-statements
To match Open MPI style guidelines all control statements must use braces even if they have a single statement. This commit fixes all sources that compile on macOS (limitation of clang-tidy that sources need to be compilable) in the opal subdir to match this guideline. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
1 parent 4c4d520 commit 5c6c7ff

Some content is hidden

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

47 files changed

+473
-260
lines changed

opal/class/opal_bitmap.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ int opal_bitmap_init(opal_bitmap_t *bm, int size)
8484
bm->array_size = (int) (((size_t) size + SIZE_OF_BASE_TYPE - 1) / SIZE_OF_BASE_TYPE);
8585
if (NULL != bm->bitmap) {
8686
free(bm->bitmap);
87-
if (bm->max_size < bm->array_size)
87+
if (bm->max_size < bm->array_size) {
8888
bm->max_size = bm->array_size;
89+
}
8990
}
9091
bm->bitmap = (uint64_t *) malloc(bm->array_size * sizeof(uint64_t));
9192
if (NULL == bm->bitmap) {
@@ -114,8 +115,9 @@ int opal_bitmap_set_bit(opal_bitmap_t *bm, int bit)
114115
valid and we simply expand the bitmap */
115116

116117
new_size = index + 1;
117-
if (new_size > bm->max_size)
118+
if (new_size > bm->max_size) {
118119
new_size = bm->max_size;
120+
}
119121

120122
/* New size is just a multiple of the original size to fit in
121123
the index. */
@@ -368,8 +370,9 @@ int opal_bitmap_num_set_bits(opal_bitmap_t *bm, int len)
368370
#endif
369371

370372
for (i = 0; i < len; ++i) {
371-
if (0 == (val = bm->bitmap[i]))
373+
if (0 == (val = bm->bitmap[i])) {
372374
continue;
375+
}
373376
/* Peter Wegner in CACM 3 (1960), 322. This method goes through as many
374377
* iterations as there are set bits. */
375378
for (; val; cnt++) {

opal/class/opal_cstring.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ int opal_cstring_to_int(opal_cstring_t *string, int *interp)
8787
errno = 0;
8888
tmp = strtol(string->string, &endp, 10);
8989
/* we found something not a number */
90-
if (*endp != '\0')
90+
if (*endp != '\0') {
9191
return OPAL_ERR_BAD_PARAM;
92+
}
9293
/* underflow */
93-
if (tmp == 0 && errno == EINVAL)
94+
if (tmp == 0 && errno == EINVAL) {
9495
return OPAL_ERR_BAD_PARAM;
96+
}
9597

9698
*interp = (int) tmp;
9799

opal/class/opal_free_list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ int opal_free_list_init(opal_free_list_t *flist, size_t frag_size, size_t frag_a
123123

124124
if (0 < payload_buffer_size) {
125125
if (payload_buffer_alignment <= 1
126-
|| (payload_buffer_alignment & (payload_buffer_alignment - 1)))
126+
|| (payload_buffer_alignment & (payload_buffer_alignment - 1))) {
127127
return OPAL_ERROR;
128+
}
128129
}
129130

130131
if (frag_class && frag_size < frag_class->cls_sizeof) {

opal/class/opal_hash_table.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ int opal_hash_table_remove_value_uint32(opal_hash_table_t *ht, uint32_t key)
426426
ht->ht_type_methods = &opal_hash_type_methods_uint32;
427427
for (ii = key % capacity;; ii += 1) {
428428
opal_hash_element_t *elt;
429-
if (ii == capacity)
429+
if (ii == capacity) {
430430
ii = 0;
431+
}
431432
elt = &ht->ht_table[ii];
432433
if (!elt->valid) {
433434
return OPAL_ERR_NOT_FOUND;

opal/class/opal_interval_tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ static opal_interval_tree_token_t opal_interval_tree_reader_get_token(opal_inter
138138

139139
while (
140140
!OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_32((opal_atomic_int32_t *) &tree->reader_epochs[token],
141-
&(int32_t){UINT_MAX}, tree->epoch))
142-
;
141+
&(int32_t){UINT_MAX}, tree->epoch)) {
142+
}
143143

144144
return token;
145145
}
@@ -166,8 +166,8 @@ static bool opal_interval_tree_write_trylock(opal_interval_tree_t *tree)
166166

167167
static void opal_interval_tree_write_lock(opal_interval_tree_t *tree)
168168
{
169-
while (!opal_interval_tree_write_trylock(tree))
170-
;
169+
while (!opal_interval_tree_write_trylock(tree)) {
170+
}
171171
}
172172

173173
static void opal_interval_tree_write_unlock(opal_interval_tree_t *tree)
@@ -478,8 +478,8 @@ static inline void rp_wait_for_readers(opal_interval_tree_t *tree)
478478

479479
/* wait for all readers to see the new tree version */
480480
for (int i = 0; i < tree->reader_count; ++i) {
481-
while (tree->reader_epochs[i] < epoch_id)
482-
;
481+
while (tree->reader_epochs[i] < epoch_id) {
482+
}
483483
}
484484
}
485485

opal/class/opal_list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx)
117117
#endif
118118
/* pointer to element 0 */
119119
ptr = list->opal_list_sentinel.opal_list_next;
120-
for (i = 0; i < idx - 1; i++)
120+
for (i = 0; i < idx - 1; i++) {
121121
ptr = ptr->opal_list_next;
122+
}
122123

123124
next = ptr->opal_list_next;
124125
item->opal_list_next = next;

opal/class/opal_value_array.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ static void opal_value_array_construct(opal_value_array_t *array)
3030

3131
static void opal_value_array_destruct(opal_value_array_t *array)
3232
{
33-
if (NULL != array->array_items)
33+
if (NULL != array->array_items) {
3434
free(array->array_items);
35+
}
3536
}
3637

3738
OBJ_CLASS_INSTANCE(opal_value_array_t, opal_object_t, opal_value_array_construct,
@@ -47,13 +48,15 @@ int opal_value_array_set_size(opal_value_array_t *array, size_t size)
4748
#endif
4849

4950
if (size > array->array_alloc_size) {
50-
while (array->array_alloc_size < size)
51+
while (array->array_alloc_size < size) {
5152
array->array_alloc_size <<= 1;
53+
}
5254
array->array_items = (unsigned char *) realloc(array->array_items,
5355
array->array_alloc_size
5456
* array->array_item_sizeof);
55-
if (NULL == array->array_items)
57+
if (NULL == array->array_items) {
5658
return OPAL_ERR_OUT_OF_RESOURCE;
59+
}
5760
}
5861
array->array_size = size;
5962
return OPAL_SUCCESS;

opal/datatype/opal_convertor.c

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ void opal_convertor_destroy_masters(void)
7878
master->next = NULL;
7979
/* Cleanup the conversion function if not one of the defaults */
8080
if ((master->pFunctions != opal_datatype_heterogeneous_copy_functions)
81-
&& (master->pFunctions != opal_datatype_copy_functions))
81+
&& (master->pFunctions != opal_datatype_copy_functions)) {
8282
free(master->pFunctions);
83+
}
8384

8485
free(master);
8586
master = opal_convertor_master_list;
@@ -98,8 +99,9 @@ opal_convertor_master_t *opal_convertor_find_or_create_master(uint32_t remote_ar
9899
size_t *remote_sizes;
99100

100101
while (NULL != master) {
101-
if (master->remote_arch == remote_arch)
102+
if (master->remote_arch == remote_arch) {
102103
return master;
104+
}
103105
master = master->next;
104106
}
105107
/**
@@ -148,16 +150,18 @@ opal_convertor_master_t *opal_convertor_find_or_create_master(uint32_t remote_ar
148150
* over 2 bytes (with the exception of logicals) have to be byte-swapped.
149151
*/
150152
for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) {
151-
if (remote_sizes[i] != opal_datatype_local_sizes[i])
153+
if (remote_sizes[i] != opal_datatype_local_sizes[i]) {
152154
master->hetero_mask |= (((uint32_t) 1) << i);
155+
}
153156
}
154157
if (opal_arch_checkmask(&master->remote_arch, OPAL_ARCH_ISBIGENDIAN)
155158
!= opal_arch_checkmask(&opal_local_arch, OPAL_ARCH_ISBIGENDIAN)) {
156159
uint32_t hetero_mask = 0;
157160

158161
for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) {
159-
if (remote_sizes[i] > 1)
162+
if (remote_sizes[i] > 1) {
160163
hetero_mask |= (((uint32_t) 1) << i);
164+
}
161165
}
162166
hetero_mask &= ~(((uint32_t) 1) << OPAL_DATATYPE_BOOL);
163167
master->hetero_mask |= hetero_mask;
@@ -169,10 +173,11 @@ opal_convertor_master_t *opal_convertor_find_or_create_master(uint32_t remote_ar
169173
* try to minimize the usage of the heterogeneous versions.
170174
*/
171175
for (i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) {
172-
if (master->hetero_mask & (((uint32_t) 1) << i))
176+
if (master->hetero_mask & (((uint32_t) 1) << i)) {
173177
master->pFunctions[i] = opal_datatype_heterogeneous_copy_functions[i];
174-
else
178+
} else {
175179
master->pFunctions[i] = opal_datatype_copy_functions[i];
180+
}
176181
}
177182

178183
/* We're done so far, return the mater convertor */
@@ -237,14 +242,15 @@ int32_t opal_convertor_pack(opal_convertor_t *pConv, struct iovec *iov, uint32_t
237242
if (iov[i].iov_len >= pending_length) {
238243
goto complete_contiguous_data_pack;
239244
}
240-
if (OPAL_LIKELY(NULL == iov[i].iov_base))
245+
if (OPAL_LIKELY(NULL == iov[i].iov_base)) {
241246
iov[i].iov_base = (IOVBASE_TYPE *) base_pointer;
242-
else
247+
} else {
243248
#if OPAL_CUDA_SUPPORT
244249
MEMCPY_CUDA(iov[i].iov_base, base_pointer, iov[i].iov_len, pConv);
245250
#else
246251
MEMCPY(iov[i].iov_base, base_pointer, iov[i].iov_len);
247252
#endif
253+
}
248254
pending_length -= iov[i].iov_len;
249255
base_pointer += iov[i].iov_len;
250256
}
@@ -254,14 +260,15 @@ int32_t opal_convertor_pack(opal_convertor_t *pConv, struct iovec *iov, uint32_t
254260

255261
complete_contiguous_data_pack:
256262
iov[i].iov_len = pending_length;
257-
if (OPAL_LIKELY(NULL == iov[i].iov_base))
263+
if (OPAL_LIKELY(NULL == iov[i].iov_base)) {
258264
iov[i].iov_base = (IOVBASE_TYPE *) base_pointer;
259-
else
265+
} else {
260266
#if OPAL_CUDA_SUPPORT
261267
MEMCPY_CUDA(iov[i].iov_base, base_pointer, iov[i].iov_len, pConv);
262268
#else
263269
MEMCPY(iov[i].iov_base, base_pointer, iov[i].iov_len);
264270
#endif
271+
}
265272
pConv->bConverted = pConv->local_size;
266273
*out_size = i + 1;
267274
pConv->flags |= CONVERTOR_COMPLETED;
@@ -421,8 +428,9 @@ int32_t opal_convertor_set_position_nocheck(opal_convertor_t *convertor, size_t
421428
} else {
422429
if ((0 == (*position)) || ((*position) < convertor->bConverted)) {
423430
rc = opal_convertor_create_stack_at_begining(convertor, opal_datatype_local_sizes);
424-
if (0 == (*position))
431+
if (0 == (*position)) {
425432
return rc;
433+
}
426434
}
427435
rc = opal_convertor_generic_simple_position(convertor, position);
428436
/**
@@ -584,17 +592,20 @@ int32_t opal_convertor_prepare_for_recv(opal_convertor_t *convertor,
584592
convertor->fAdvance = opal_generic_simple_unpack_checksum;
585593
}
586594
}
587-
} else
595+
} else {
588596
#endif /* defined(CHECKSUM) */
589597
if (OPAL_UNLIKELY(!(convertor->flags & CONVERTOR_HOMOGENEOUS))) {
590-
convertor->fAdvance = opal_unpack_general;
591-
} else {
592-
if (convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
593-
convertor->fAdvance = opal_unpack_homogeneous_contig;
598+
convertor->fAdvance = opal_unpack_general;
594599
} else {
595-
convertor->fAdvance = opal_generic_simple_unpack;
600+
if (convertor->pDesc->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
601+
convertor->fAdvance = opal_unpack_homogeneous_contig;
602+
} else {
603+
convertor->fAdvance = opal_generic_simple_unpack;
604+
}
596605
}
606+
#if defined(CHECKSUM)
597607
}
608+
#endif
598609
return OPAL_SUCCESS;
599610
}
600611

@@ -619,30 +630,35 @@ int32_t opal_convertor_prepare_for_send(opal_convertor_t *convertor,
619630
} else {
620631
if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
621632
if (((datatype->ub - datatype->lb) == (ptrdiff_t) datatype->size)
622-
|| (1 >= convertor->count))
633+
|| (1 >= convertor->count)) {
623634
convertor->fAdvance = opal_pack_homogeneous_contig_checksum;
624-
else
635+
} else {
625636
convertor->fAdvance = opal_pack_homogeneous_contig_with_gaps_checksum;
637+
}
626638
} else {
627639
convertor->fAdvance = opal_generic_simple_pack_checksum;
628640
}
629641
}
630-
} else
642+
} else {
631643
#endif /* defined(CHECKSUM) */
632644
if (CONVERTOR_SEND_CONVERSION
633645
== (convertor->flags & (CONVERTOR_SEND_CONVERSION | CONVERTOR_HOMOGENEOUS))) {
634-
convertor->fAdvance = opal_pack_general;
635-
} else {
636-
if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
637-
if (((datatype->ub - datatype->lb) == (ptrdiff_t) datatype->size)
638-
|| (1 >= convertor->count))
639-
convertor->fAdvance = opal_pack_homogeneous_contig;
640-
else
641-
convertor->fAdvance = opal_pack_homogeneous_contig_with_gaps;
646+
convertor->fAdvance = opal_pack_general;
642647
} else {
643-
convertor->fAdvance = opal_generic_simple_pack;
648+
if (datatype->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
649+
if (((datatype->ub - datatype->lb) == (ptrdiff_t) datatype->size)
650+
|| (1 >= convertor->count)) {
651+
convertor->fAdvance = opal_pack_homogeneous_contig;
652+
} else {
653+
convertor->fAdvance = opal_pack_homogeneous_contig_with_gaps;
654+
}
655+
} else {
656+
convertor->fAdvance = opal_generic_simple_pack;
657+
}
644658
}
659+
#if defined(CHECKSUM)
645660
}
661+
#endif
646662
return OPAL_SUCCESS;
647663
}
648664

@@ -703,26 +719,35 @@ void opal_convertor_dump(opal_convertor_t *convertor)
703719
convertor->local_size, convertor->remote_size, convertor->flags,
704720
convertor->stack_size, convertor->partial_length, convertor->remoteArch,
705721
opal_local_arch);
706-
if (convertor->flags & CONVERTOR_RECV)
722+
if (convertor->flags & CONVERTOR_RECV) {
707723
opal_output(0, "unpack ");
708-
if (convertor->flags & CONVERTOR_SEND)
724+
}
725+
if (convertor->flags & CONVERTOR_SEND) {
709726
opal_output(0, "pack ");
710-
if (convertor->flags & CONVERTOR_SEND_CONVERSION)
727+
}
728+
if (convertor->flags & CONVERTOR_SEND_CONVERSION) {
711729
opal_output(0, "conversion ");
712-
if (convertor->flags & CONVERTOR_HOMOGENEOUS)
730+
}
731+
if (convertor->flags & CONVERTOR_HOMOGENEOUS) {
713732
opal_output(0, "homogeneous ");
714-
else
733+
} else {
715734
opal_output(0, "heterogeneous ");
716-
if (convertor->flags & CONVERTOR_NO_OP)
735+
}
736+
if (convertor->flags & CONVERTOR_NO_OP) {
717737
opal_output(0, "no_op ");
718-
if (convertor->flags & CONVERTOR_WITH_CHECKSUM)
738+
}
739+
if (convertor->flags & CONVERTOR_WITH_CHECKSUM) {
719740
opal_output(0, "checksum ");
720-
if (convertor->flags & CONVERTOR_CUDA)
741+
}
742+
if (convertor->flags & CONVERTOR_CUDA) {
721743
opal_output(0, "CUDA ");
722-
if (convertor->flags & CONVERTOR_CUDA_ASYNC)
744+
}
745+
if (convertor->flags & CONVERTOR_CUDA_ASYNC) {
723746
opal_output(0, "CUDA Async ");
724-
if (convertor->flags & CONVERTOR_COMPLETED)
747+
}
748+
if (convertor->flags & CONVERTOR_COMPLETED) {
725749
opal_output(0, "COMPLETED ");
750+
}
726751

727752
opal_datatype_dump(convertor->pDesc);
728753
if (!((0 == convertor->stack_pos)
@@ -742,13 +767,14 @@ void opal_datatype_dump_stack(const dt_stack_t *pStack, int stack_pos,
742767
for (; stack_pos >= 0; stack_pos--) {
743768
opal_output(0, "%d: pos %d count %" PRIsize_t " disp %ld ", stack_pos,
744769
pStack[stack_pos].index, pStack[stack_pos].count, pStack[stack_pos].disp);
745-
if (pStack->index != -1)
770+
if (pStack->index != -1) {
746771
opal_output(0, "\t[desc count %lu disp %ld extent %ld]\n",
747772
(unsigned long) pDesc[pStack[stack_pos].index].elem.count,
748773
(long) pDesc[pStack[stack_pos].index].elem.disp,
749774
(long) pDesc[pStack[stack_pos].index].elem.extent);
750-
else
775+
} else {
751776
opal_output(0, "\n");
777+
}
752778
}
753779
opal_output(0, "\n");
754780
}

0 commit comments

Comments
 (0)