Skip to content

Commit 9b1c496

Browse files
authored
[OpenMP] Fixup while loops to avoid bad NULL check (#83302)
1 parent de4d701 commit 9b1c496

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,14 +1829,8 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
18291829

18301830
// Figure out the depth and types in the topology
18311831
depth = 0;
1832-
pu = hwloc_get_pu_obj_by_os_index(tp, __kmp_affin_fullMask->begin());
1833-
KMP_ASSERT(pu);
1834-
obj = pu;
1835-
types[depth] = KMP_HW_THREAD;
1836-
hwloc_types[depth] = obj->type;
1837-
depth++;
1838-
while (obj != root && obj != NULL) {
1839-
obj = obj->parent;
1832+
obj = hwloc_get_pu_obj_by_os_index(tp, __kmp_affin_fullMask->begin());
1833+
while (obj && obj != root) {
18401834
#if HWLOC_API_VERSION >= 0x00020000
18411835
if (obj->memory_arity) {
18421836
hwloc_obj_t memory;
@@ -1858,6 +1852,7 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
18581852
hwloc_types[depth] = obj->type;
18591853
depth++;
18601854
}
1855+
obj = obj->parent;
18611856
}
18621857
KMP_ASSERT(depth > 0);
18631858

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,8 +2662,8 @@ void *__kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data) {
26622662
if (tg == NULL)
26632663
tg = thread->th.th_current_task->td_taskgroup;
26642664
KMP_ASSERT(tg != NULL);
2665-
kmp_taskred_data_t *arr = (kmp_taskred_data_t *)(tg->reduce_data);
2666-
kmp_int32 num = tg->reduce_num_data;
2665+
kmp_taskred_data_t *arr;
2666+
kmp_int32 num;
26672667
kmp_int32 tid = thread->th.th_info.ds.ds_tid;
26682668

26692669
#if OMPX_TASKGRAPH
@@ -2680,6 +2680,8 @@ void *__kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data) {
26802680

26812681
KMP_ASSERT(data != NULL);
26822682
while (tg != NULL) {
2683+
arr = (kmp_taskred_data_t *)(tg->reduce_data);
2684+
num = tg->reduce_num_data;
26832685
for (int i = 0; i < num; ++i) {
26842686
if (!arr[i].flags.lazy_priv) {
26852687
if (data == arr[i].reduce_shar ||
@@ -2713,8 +2715,6 @@ void *__kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data) {
27132715
}
27142716
KMP_ASSERT(tg->parent);
27152717
tg = tg->parent;
2716-
arr = (kmp_taskred_data_t *)(tg->reduce_data);
2717-
num = tg->reduce_num_data;
27182718
}
27192719
KMP_ASSERT2(0, "Unknown task reduction item");
27202720
return NULL; // ERROR, this line never executed

0 commit comments

Comments
 (0)