Skip to content

Commit c47afcd

Browse files
committedJul 3, 2017
OpenMP RTL cleanup: eliminated warnings with -Wcast-qual.
Changes are: replaced C-style casts with cons_cast and reinterpret_cast; type of several counters changed to signed; type of parameters of 32-bit and 64-bit AND and OR intrinsics changes to unsigned; changed files formatted using clang-format version 3.8.1. Differential Revision: https://reviews.llvm.org/D34759 llvm-svn: 307020
1 parent 5c787ab commit c47afcd

22 files changed

+376
-349
lines changed
 

‎openmp/runtime/src/kmp.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ typedef enum kmp_cancel_kind_t {
788788

789789
// KMP_HW_SUBSET support:
790790
typedef struct kmp_hws_item {
791-
int num;
792-
int offset;
791+
int num;
792+
int offset;
793793
} kmp_hws_item_t;
794794

795795
extern kmp_hws_item_t __kmp_hws_socket;
@@ -1533,9 +1533,9 @@ typedef struct KMP_ALIGN_CACHE dispatch_private_info32 {
15331533
kmp_uint32 ordered_lower;
15341534
kmp_uint32 ordered_upper;
15351535
#if KMP_OS_WINDOWS
1536-
// This var can be placed in the hole between 'tc' and 'parm1', instead of
1537-
// 'static_steal_counter'. It would be nice to measure execution times.
1538-
// Conditional if/endif can be removed at all.
1536+
// This var can be placed in the hole between 'tc' and 'parm1', instead of
1537+
// 'static_steal_counter'. It would be nice to measure execution times.
1538+
// Conditional if/endif can be removed at all.
15391539
kmp_int32 last_upper;
15401540
#endif /* KMP_OS_WINDOWS */
15411541
} dispatch_private_info32_t;
@@ -1568,9 +1568,9 @@ typedef struct KMP_ALIGN_CACHE dispatch_private_info64 {
15681568
kmp_uint64 ordered_lower;
15691569
kmp_uint64 ordered_upper;
15701570
#if KMP_OS_WINDOWS
1571-
// This var can be placed in the hole between 'tc' and 'parm1', instead of
1572-
// 'static_steal_counter'. It would be nice to measure execution times.
1573-
// Conditional if/endif can be removed at all.
1571+
// This var can be placed in the hole between 'tc' and 'parm1', instead of
1572+
// 'static_steal_counter'. It would be nice to measure execution times.
1573+
// Conditional if/endif can be removed at all.
15741574
kmp_int64 last_upper;
15751575
#endif /* KMP_OS_WINDOWS */
15761576
} dispatch_private_info64_t;
@@ -2109,7 +2109,7 @@ typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */
21092109

21102110
#if OMP_40_ENABLED
21112111
typedef struct kmp_taskgroup {
2112-
kmp_uint32 count; // number of allocated and not yet complete tasks
2112+
kmp_int32 count; // number of allocated and not yet complete tasks
21132113
kmp_int32 cancel_request; // request for cancellation of this taskgroup
21142114
struct kmp_taskgroup *parent; // parent taskgroup
21152115
// TODO: change to OMP_50_ENABLED, need to change build tools for this to work
@@ -2250,10 +2250,10 @@ struct kmp_taskdata { /* aligned during dynamic allocation */
22502250
kmp_int32 td_taskwait_thread; /* gtid + 1 of thread encountered taskwait */
22512251
KMP_ALIGN_CACHE kmp_internal_control_t
22522252
td_icvs; /* Internal control variables for the task */
2253-
KMP_ALIGN_CACHE volatile kmp_uint32
2253+
KMP_ALIGN_CACHE volatile kmp_int32
22542254
td_allocated_child_tasks; /* Child tasks (+ current task) not yet
22552255
deallocated */
2256-
volatile kmp_uint32
2256+
volatile kmp_int32
22572257
td_incomplete_child_tasks; /* Child tasks not yet complete */
22582258
#if OMP_40_ENABLED
22592259
kmp_taskgroup_t
@@ -2328,7 +2328,7 @@ typedef struct kmp_base_task_team {
23282328
#endif
23292329

23302330
KMP_ALIGN_CACHE
2331-
volatile kmp_uint32 tt_unfinished_threads; /* #threads still active */
2331+
volatile kmp_int32 tt_unfinished_threads; /* #threads still active */
23322332

23332333
KMP_ALIGN_CACHE
23342334
volatile kmp_uint32
@@ -2402,7 +2402,6 @@ typedef struct KMP_ALIGN_CACHE kmp_base_info {
24022402
kmp_uint64 th_team_bt_intervals;
24032403
#endif
24042404

2405-
24062405
#if KMP_AFFINITY_SUPPORTED
24072406
kmp_affin_mask_t *th_affin_mask; /* thread's current affinity mask */
24082407
#endif
@@ -3787,7 +3786,6 @@ extern int _You_must_link_with_Intel_OpenMP_library;
37873786
extern int _You_must_link_with_Microsoft_OpenMP_library;
37883787
#endif
37893788

3790-
37913789
// The routines below are not exported.
37923790
// Consider making them 'static' in corresponding source files.
37933791
void kmp_threadprivate_insert_private_data(int gtid, void *pc_addr,

‎openmp/runtime/src/kmp_affinity.cpp

+79-76
Large diffs are not rendered by default.

‎openmp/runtime/src/kmp_affinity.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,10 @@ class AddrUnsPair {
618618
};
619619

620620
static int __kmp_affinity_cmp_Address_labels(const void *a, const void *b) {
621-
const Address *aa = (const Address *)&(((AddrUnsPair *)a)->first);
622-
const Address *bb = (const Address *)&(((AddrUnsPair *)b)->first);
621+
const Address *aa =
622+
(const Address *)&(((AddrUnsPair *)CCAST(void *, a))->first);
623+
const Address *bb =
624+
(const Address *)&(((AddrUnsPair *)CCAST(void *, b))->first);
623625
unsigned depth = aa->depth;
624626
unsigned i;
625627
KMP_DEBUG_ASSERT(depth == bb->depth);
@@ -765,7 +767,6 @@ class hierarchy_info {
765767
skipPerLevel[i] = 2 * skipPerLevel[i - 1];
766768

767769
uninitialized = initialized; // One writer
768-
769770
}
770771

771772
// Resize the hierarchy if nproc changes to something larger than before
@@ -832,7 +833,6 @@ class hierarchy_info {
832833

833834
base_num_threads = nproc;
834835
resizing = 0; // One writer
835-
836836
}
837837
};
838838
#endif // KMP_AFFINITY_H

‎openmp/runtime/src/kmp_alloc.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,12 @@ static void __kmp_bget_dequeue(kmp_info_t *th) {
298298
#if USE_CMP_XCHG_FOR_BGET
299299
{
300300
volatile void *old_value = TCR_SYNC_PTR(th->th.th_local.bget_list);
301-
while (!KMP_COMPARE_AND_STORE_PTR(&th->th.th_local.bget_list, old_value,
302-
NULL)) {
301+
while (!KMP_COMPARE_AND_STORE_PTR(&th->th.th_local.bget_list,
302+
CCAST(void *, old_value), NULL)) {
303303
KMP_CPU_PAUSE();
304304
old_value = TCR_SYNC_PTR(th->th.th_local.bget_list);
305305
}
306-
p = (void *)old_value;
306+
p = CCAST(void *, old_value);
307307
}
308308
#else /* ! USE_CMP_XCHG_FOR_BGET */
309309
#ifdef USE_QUEUING_LOCK_FOR_BGET
@@ -362,15 +362,15 @@ static void __kmp_bget_enqueue(kmp_info_t *th, void *buf
362362
volatile void *old_value = TCR_PTR(th->th.th_local.bget_list);
363363
/* the next pointer must be set before setting bget_list to buf to avoid
364364
exposing a broken list to other threads, even for an instant. */
365-
b->ql.flink = BFH(old_value);
365+
b->ql.flink = BFH(CCAST(void *, old_value));
366366

367-
while (!KMP_COMPARE_AND_STORE_PTR(&th->th.th_local.bget_list, old_value,
368-
buf)) {
367+
while (!KMP_COMPARE_AND_STORE_PTR(&th->th.th_local.bget_list,
368+
CCAST(void *, old_value), buf)) {
369369
KMP_CPU_PAUSE();
370370
old_value = TCR_PTR(th->th.th_local.bget_list);
371371
/* the next pointer must be set before setting bget_list to buf to avoid
372372
exposing a broken list to other threads, even for an instant. */
373-
b->ql.flink = BFH(old_value);
373+
b->ql.flink = BFH(CCAST(void *, old_value));
374374
}
375375
}
376376
#else /* ! USE_CMP_XCHG_FOR_BGET */
@@ -607,7 +607,7 @@ static void *bget(kmp_info_t *th, bufsize requested_size) {
607607
if (thr->acqfcn != 0) {
608608
if (size > (bufsize)(thr->exp_incr - sizeof(bhead_t))) {
609609
/* Request is too large to fit in a single expansion block.
610-
Try to satisy it by a direct buffer acquisition. */
610+
Try to satisy it by a direct buffer acquisition. */
611611
bdhead_t *bdh;
612612

613613
size += sizeof(bdhead_t) - sizeof(bhead_t);

‎openmp/runtime/src/kmp_barrier.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@ static void __kmp_hierarchical_barrier_gather(
883883
ANNOTATE_REDUCE_BEFORE(reduce);
884884
ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
885885
}
886-
(void)KMP_TEST_THEN_AND64(
887-
(volatile kmp_int64 *)&thr_bar->b_arrived,
888-
~(thr_bar->leaf_state)); // clear leaf_state bits
886+
// clear leaf_state bits
887+
KMP_TEST_THEN_AND64(CCAST(kmp_uint64 *, &thr_bar->b_arrived),
888+
~(thr_bar->leaf_state));
889889
}
890890
// Next, wait for higher level children on each child's b_arrived flag
891891
for (kmp_uint32 d = 1; d < thr_bar->my_level;
@@ -1035,7 +1035,8 @@ static void __kmp_hierarchical_barrier_release(
10351035
TCW_8(thr_bar->b_go,
10361036
KMP_INIT_BARRIER_STATE); // Reset my b_go flag for next time
10371037
} else { // Reset my bits on parent's b_go flag
1038-
((char *)&(thr_bar->parent_bar->b_go))[thr_bar->offset] = 0;
1038+
(RCAST(volatile char *,
1039+
&(thr_bar->parent_bar->b_go)))[thr_bar->offset] = 0;
10391040
}
10401041
}
10411042
thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
@@ -1210,7 +1211,6 @@ static void __kmp_hierarchical_barrier_release(
12101211
gtid, team->t.t_id, tid, bt));
12111212
}
12121213

1213-
12141214
// End of Barrier Algorithms
12151215

12161216
// Internal function to do a barrier.
@@ -1347,7 +1347,7 @@ int __kmp_barrier(enum barrier_type bt, int gtid, int is_split,
13471347
if (KMP_MASTER_TID(tid)) {
13481348
status = 0;
13491349
if (__kmp_tasking_mode != tskm_immediate_exec) {
1350-
__kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1350+
__kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
13511351
}
13521352
#if USE_DEBUGGER
13531353
// Let the debugger know: All threads are arrived and starting leaving the

‎openmp/runtime/src/kmp_csupport.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -3092,8 +3092,8 @@ void __kmpc_doacross_init(ident_t *loc, int gtid, int num_dims,
30923092
// __kmp_dispatch_num_buffers)
30933093
if (idx != sh_buf->doacross_buf_idx) {
30943094
// Shared buffer is occupied, wait for it to be free
3095-
__kmp_wait_yield_4((kmp_uint32 *)&sh_buf->doacross_buf_idx, idx, __kmp_eq_4,
3096-
NULL);
3095+
__kmp_wait_yield_4((volatile kmp_uint32 *)&sh_buf->doacross_buf_idx, idx,
3096+
__kmp_eq_4, NULL);
30973097
}
30983098
// Check if we are the first thread. After the CAS the first thread gets 0,
30993099
// others get 1 if initialization is in progress, allocated pointer otherwise.
@@ -3258,8 +3258,8 @@ void __kmpc_doacross_post(ident_t *loc, int gtid, long long *vec) {
32583258
iter_number >>= 5; // divided by 32
32593259
flag = 1 << shft;
32603260
if ((flag & pr_buf->th_doacross_flags[iter_number]) == 0)
3261-
KMP_TEST_THEN_OR32((kmp_int32 *)&pr_buf->th_doacross_flags[iter_number],
3262-
(kmp_int32)flag);
3261+
KMP_TEST_THEN_OR32(
3262+
CCAST(kmp_uint32 *, &pr_buf->th_doacross_flags[iter_number]), flag);
32633263
KA_TRACE(20, ("__kmpc_doacross_post() exit: T#%d iter %lld posted\n", gtid,
32643264
(iter_number << 5) + shft));
32653265
}
@@ -3285,7 +3285,7 @@ void __kmpc_doacross_fini(ident_t *loc, int gtid) {
32853285
(kmp_int64)&sh_buf->doacross_num_done);
32863286
KMP_DEBUG_ASSERT(num_done == (kmp_int64)sh_buf->doacross_num_done);
32873287
KMP_DEBUG_ASSERT(idx == sh_buf->doacross_buf_idx);
3288-
__kmp_thread_free(th, (void *)sh_buf->doacross_flags);
3288+
__kmp_thread_free(th, CCAST(kmp_uint32 *, sh_buf->doacross_flags));
32893289
sh_buf->doacross_flags = NULL;
32903290
sh_buf->doacross_num_done = 0;
32913291
sh_buf->doacross_buf_idx +=

‎openmp/runtime/src/kmp_dispatch.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ template <>
172172
__forceinline kmp_int32 test_then_add<kmp_int32>(volatile kmp_int32 *p,
173173
kmp_int32 d) {
174174
kmp_int32 r;
175-
r = KMP_TEST_THEN_ADD32(p, d);
175+
r = KMP_TEST_THEN_ADD32(CCAST(kmp_int32 *, p), d);
176176
return r;
177177
}
178178

179179
template <>
180180
__forceinline kmp_int64 test_then_add<kmp_int64>(volatile kmp_int64 *p,
181181
kmp_int64 d) {
182182
kmp_int64 r;
183-
r = KMP_TEST_THEN_ADD64(p, d);
183+
r = KMP_TEST_THEN_ADD64(CCAST(kmp_int64 *, p), d);
184184
return r;
185185
}
186186

@@ -190,14 +190,14 @@ template <typename T> static __forceinline T test_then_inc_acq(volatile T *p);
190190
template <>
191191
__forceinline kmp_int32 test_then_inc_acq<kmp_int32>(volatile kmp_int32 *p) {
192192
kmp_int32 r;
193-
r = KMP_TEST_THEN_INC_ACQ32(p);
193+
r = KMP_TEST_THEN_INC_ACQ32(CCAST(kmp_int32 *, p));
194194
return r;
195195
}
196196

197197
template <>
198198
__forceinline kmp_int64 test_then_inc_acq<kmp_int64>(volatile kmp_int64 *p) {
199199
kmp_int64 r;
200-
r = KMP_TEST_THEN_INC_ACQ64(p);
200+
r = KMP_TEST_THEN_INC_ACQ64(CCAST(kmp_int64 *, p));
201201
return r;
202202
}
203203

@@ -207,14 +207,14 @@ template <typename T> static __forceinline T test_then_inc(volatile T *p);
207207
template <>
208208
__forceinline kmp_int32 test_then_inc<kmp_int32>(volatile kmp_int32 *p) {
209209
kmp_int32 r;
210-
r = KMP_TEST_THEN_INC32(p);
210+
r = KMP_TEST_THEN_INC32(CCAST(kmp_int32 *, p));
211211
return r;
212212
}
213213

214214
template <>
215215
__forceinline kmp_int64 test_then_inc<kmp_int64>(volatile kmp_int64 *p) {
216216
kmp_int64 r;
217-
r = KMP_TEST_THEN_INC64(p);
217+
r = KMP_TEST_THEN_INC64(CCAST(kmp_int64 *, p));
218218
return r;
219219
}
220220

@@ -262,7 +262,7 @@ static UT // unsigned 4- or 8-byte type
262262
register kmp_uint32 (*f)(UT, UT) = pred;
263263
register UT r;
264264

265-
KMP_FSYNC_SPIN_INIT(obj, (void *)spin);
265+
KMP_FSYNC_SPIN_INIT(obj, CCAST(UT *, spin));
266266
KMP_INIT_YIELD(spins);
267267
// main wait spin loop
268268
while (!f(r = *spin, check)) {
@@ -440,7 +440,7 @@ static void __kmp_dispatch_dxo(int *gtid_ref, int *cid_ref, ident_t *loc_ref) {
440440
th->th.th_dispatch->th_dispatch_pr_current);
441441
}
442442

443-
KMP_FSYNC_RELEASING(&sh->u.s.ordered_iteration);
443+
KMP_FSYNC_RELEASING(CCAST(UT *, &sh->u.s.ordered_iteration));
444444
#if !defined(KMP_GOMP_COMPAT)
445445
if (__kmp_env_consistency_check) {
446446
if (pr->ordered_bumped != 0) {
@@ -1162,7 +1162,9 @@ __kmp_dispatch_init(ident_t *loc, int gtid, enum sched_type schedule, T lb,
11621162
gtid, my_buffer_index, sh->buffer_index));
11631163

11641164
th->th.th_dispatch->th_dispatch_pr_current = (dispatch_private_info_t *)pr;
1165-
th->th.th_dispatch->th_dispatch_sh_current = (dispatch_shared_info_t *)sh;
1165+
th->th.th_dispatch->th_dispatch_sh_current =
1166+
RCAST(dispatch_shared_info_t *,
1167+
CCAST(dispatch_shared_info_template<UT> *, sh));
11661168
#if USE_ITT_BUILD
11671169
if (pr->ordered) {
11681170
__kmp_itt_ordered_init(gtid);
@@ -1978,7 +1980,8 @@ static int __kmp_dispatch_next(ident_t *loc, int gtid, kmp_int32 *p_last,
19781980
pr->u.p.parm2) { // compare with K*nproc*(chunk+1), K=2 by default
19791981
// use dynamic-style shcedule
19801982
// atomically inrement iterations, get old value
1981-
init = test_then_add<ST>((ST *)&sh->u.s.iteration, (ST)chunkspec);
1983+
init = test_then_add<ST>(
1984+
RCAST(ST *, CCAST(UT *, &sh->u.s.iteration)), (ST)chunkspec);
19821985
remaining = trip - init;
19831986
if (remaining <= 0) {
19841987
status = 0; // all iterations got by other threads
@@ -1995,8 +1998,8 @@ static int __kmp_dispatch_next(ident_t *loc, int gtid, kmp_int32 *p_last,
19951998
} // if
19961999
limit = init + (UT)(remaining *
19972000
*(double *)&pr->u.p.parm3); // divide by K*nproc
1998-
if (compare_and_swap<ST>((ST *)&sh->u.s.iteration, (ST)init,
1999-
(ST)limit)) {
2001+
if (compare_and_swap<ST>(RCAST(ST *, CCAST(UT *, &sh->u.s.iteration)),
2002+
(ST)init, (ST)limit)) {
20002003
// CAS was successful, chunk obtained
20012004
status = 1;
20022005
--limit;
@@ -2056,7 +2059,8 @@ static int __kmp_dispatch_next(ident_t *loc, int gtid, kmp_int32 *p_last,
20562059
if ((T)remaining < pr->u.p.parm2) {
20572060
// use dynamic-style shcedule
20582061
// atomically inrement iterations, get old value
2059-
init = test_then_add<ST>((ST *)&sh->u.s.iteration, (ST)chunk);
2062+
init = test_then_add<ST>(
2063+
RCAST(ST *, CCAST(UT *, &sh->u.s.iteration)), (ST)chunk);
20602064
remaining = trip - init;
20612065
if (remaining <= 0) {
20622066
status = 0; // all iterations got by other threads
@@ -2078,8 +2082,8 @@ static int __kmp_dispatch_next(ident_t *loc, int gtid, kmp_int32 *p_last,
20782082
if (rem) // adjust so that span%chunk == 0
20792083
span += chunk - rem;
20802084
limit = init + span;
2081-
if (compare_and_swap<ST>((ST *)&sh->u.s.iteration, (ST)init,
2082-
(ST)limit)) {
2085+
if (compare_and_swap<ST>(RCAST(ST *, CCAST(UT *, &sh->u.s.iteration)),
2086+
(ST)init, (ST)limit)) {
20832087
// CAS was successful, chunk obtained
20842088
status = 1;
20852089
--limit;
@@ -2716,7 +2720,7 @@ __kmp_wait_yield_4(volatile kmp_uint32 *spinner, kmp_uint32 checker,
27162720
register kmp_uint32 (*f)(kmp_uint32, kmp_uint32) = pred;
27172721
register kmp_uint32 r;
27182722

2719-
KMP_FSYNC_SPIN_INIT(obj, (void *)spin);
2723+
KMP_FSYNC_SPIN_INIT(obj, CCAST(kmp_uint32 *, spin));
27202724
KMP_INIT_YIELD(spins);
27212725
// main wait spin loop
27222726
while (!f(r = TCR_4(*spin), check)) {

‎openmp/runtime/src/kmp_environment.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ char *__kmp_env_get(char const *name) {
147147
void __kmp_env_free(char const **value) {
148148

149149
KMP_DEBUG_ASSERT(value != NULL);
150-
KMP_INTERNAL_FREE((void *)*value);
150+
KMP_INTERNAL_FREE(CCAST(char *, *value));
151151
*value = NULL;
152152

153153
} // func __kmp_env_free
@@ -475,7 +475,8 @@ void __kmp_env_blk_sort(
475475
kmp_env_blk_t *block // M: Block of environment variables to sort.
476476
) {
477477

478-
qsort((void *)block->vars, block->count, sizeof(kmp_env_var_t),
478+
qsort(CCAST(kmp_env_var_t *, block->vars), block->count,
479+
sizeof(kmp_env_var_t),
479480
(int (*)(void const *, void const *)) & ___kmp_env_var_cmp);
480481

481482
} // __kmp_env_block_sort
@@ -484,7 +485,7 @@ void __kmp_env_blk_free(
484485
kmp_env_blk_t *block // M: Block of environment variables to free.
485486
) {
486487

487-
KMP_INTERNAL_FREE((void *)block->vars);
488+
KMP_INTERNAL_FREE(CCAST(kmp_env_var_t *, block->vars));
488489
__kmp_str_free(&(block->bulk));
489490

490491
block->count = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.