@@ -52,6 +52,7 @@ char const *traits_t<long>::spec = "ld";
52
52
} else if (i > 0 ) { \
53
53
t = (u - l) / i + 1 ; \
54
54
} else { \
55
+ KMP_DEBUG_ASSERT (i != 0 ); \
55
56
t = (l - u) / (-i) + 1 ; \
56
57
} \
57
58
KMP_COUNT_VALUE (stat, t); \
@@ -284,6 +285,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
284
285
// upper-lower can exceed the limit of signed type
285
286
trip_count = (UT)(*pupper - *plower) / incr + 1 ;
286
287
} else {
288
+ KMP_DEBUG_ASSERT (incr != 0 );
287
289
trip_count = (UT)(*plower - *pupper) / (-incr) + 1 ;
288
290
}
289
291
@@ -318,6 +320,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
318
320
if (plastiter != NULL )
319
321
*plastiter = (tid == trip_count - 1 );
320
322
} else {
323
+ KMP_DEBUG_ASSERT (nth != 0 );
321
324
if (__kmp_static == kmp_sch_static_balanced) {
322
325
UT small_chunk = trip_count / nth;
323
326
UT extras = trip_count % nth;
@@ -358,6 +361,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
358
361
case kmp_sch_static_chunked: {
359
362
ST span;
360
363
UT nchunks;
364
+ KMP_DEBUG_ASSERT (chunk != 0 );
361
365
if (chunk < 1 )
362
366
chunk = 1 ;
363
367
else if ((UT)chunk > trip_count)
@@ -383,6 +387,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
383
387
}
384
388
case kmp_sch_static_balanced_chunked: {
385
389
T old_upper = *pupper;
390
+ KMP_DEBUG_ASSERT (nth != 0 );
386
391
// round up to make sure the chunk is enough to cover all iterations
387
392
UT span = (trip_count + nth - 1 ) / nth;
388
393
@@ -398,8 +403,10 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
398
403
} else if (*pupper < old_upper)
399
404
*pupper = old_upper;
400
405
401
- if (plastiter != NULL )
406
+ if (plastiter != NULL ) {
407
+ KMP_DEBUG_ASSERT (chunk != 0 );
402
408
*plastiter = (tid == ((trip_count - 1 ) / (UT)chunk));
409
+ }
403
410
break ;
404
411
}
405
412
default :
@@ -417,6 +424,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
417
424
// Calculate chunk in case it was not specified; it is specified for
418
425
// kmp_sch_static_chunked
419
426
if (schedtype == kmp_sch_static) {
427
+ KMP_DEBUG_ASSERT (nth != 0 );
420
428
cur_chunk = trip_count / nth + ((trip_count % nth) ? 1 : 0 );
421
429
}
422
430
// 0 - "static" schedule
@@ -547,6 +555,7 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
547
555
// upper-lower can exceed the limit of signed type
548
556
trip_count = (UT)(*pupper - *plower) / incr + 1 ;
549
557
} else {
558
+ KMP_DEBUG_ASSERT (incr != 0 );
550
559
trip_count = (UT)(*plower - *pupper) / (-incr) + 1 ;
551
560
}
552
561
@@ -568,6 +577,7 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
568
577
*plastiter = (tid == 0 && team_id == trip_count - 1 );
569
578
} else {
570
579
// Get the team's chunk first (each team gets at most one chunk)
580
+ KMP_DEBUG_ASSERT (nteams != 0 );
571
581
if (__kmp_static == kmp_sch_static_balanced) {
572
582
UT chunkD = trip_count / nteams;
573
583
UT extras = trip_count % nteams;
@@ -619,6 +629,7 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
619
629
// upper-lower can exceed the limit of signed type
620
630
trip_count = (UT)(*pupperDist - *plower) / incr + 1 ;
621
631
} else {
632
+ KMP_DEBUG_ASSERT (incr != 0 );
622
633
trip_count = (UT)(*plower - *pupperDist) / (-incr) + 1 ;
623
634
}
624
635
KMP_DEBUG_ASSERT (trip_count);
@@ -637,6 +648,7 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
637
648
if (*plastiter != 0 && !(tid == trip_count - 1 ))
638
649
*plastiter = 0 ;
639
650
} else {
651
+ KMP_DEBUG_ASSERT (nth != 0 );
640
652
if (__kmp_static == kmp_sch_static_balanced) {
641
653
UT chunkL = trip_count / nth;
642
654
UT extras = trip_count % nth;
@@ -684,9 +696,11 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
684
696
*pstride = span * nth;
685
697
*plower = *plower + (span * tid);
686
698
*pupper = *plower + span - incr;
687
- if (plastiter != NULL )
699
+ if (plastiter != NULL ) {
700
+ KMP_DEBUG_ASSERT (chunk != 0 );
688
701
if (*plastiter != 0 && !(tid == ((trip_count - 1 ) / (UT)chunk) % nth))
689
702
*plastiter = 0 ;
703
+ }
690
704
break ;
691
705
}
692
706
default :
@@ -809,6 +823,7 @@ static void __kmp_team_static_init(ident_t *loc, kmp_int32 gtid,
809
823
// upper-lower can exceed the limit of signed type
810
824
trip_count = (UT)(upper - lower) / incr + 1 ;
811
825
} else {
826
+ KMP_DEBUG_ASSERT (incr != 0 );
812
827
trip_count = (UT)(lower - upper) / (-incr) + 1 ;
813
828
}
814
829
if (chunk < 1 )
@@ -817,8 +832,10 @@ static void __kmp_team_static_init(ident_t *loc, kmp_int32 gtid,
817
832
*p_st = span * nteams;
818
833
*p_lb = lower + (span * team_id);
819
834
*p_ub = *p_lb + span - incr;
820
- if (p_last != NULL )
835
+ if (p_last != NULL ) {
836
+ KMP_DEBUG_ASSERT (chunk != 0 );
821
837
*p_last = (team_id == ((trip_count - 1 ) / (UT)chunk) % nteams);
838
+ }
822
839
// Correct upper bound if needed
823
840
if (incr > 0 ) {
824
841
if (*p_ub < *p_lb) // overflow?
0 commit comments