Skip to content

Commit b4a1f44

Browse files
committed
[OpenMP] Add a few small fixes
* Add comment to help ensure new construct data are added in two places * Check for division by zero in the loop worksharing code * Check for syntax errors in parrange parsing Differential Revision: https://reviews.llvm.org/D105929
1 parent 6eeb4c1 commit b4a1f44

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

openmp/runtime/src/kmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,8 @@ __kmp_mm_mwait(unsigned extensions, unsigned hints) {
14391439
/* Support datatypes for the orphaned construct nesting checks. */
14401440
/* ------------------------------------------------------------------------ */
14411441

1442+
/* When adding to this enum, add its corresponding string in cons_text_c[]
1443+
* array in kmp_error.cpp */
14421444
enum cons_type {
14431445
ct_none,
14441446
ct_parallel,

openmp/runtime/src/kmp_dispatch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ void __kmp_dispatch_init_algorithm(ident_t *loc, int gtid,
561561
_control87(_PC_64, _MCW_PC); // 0,0x30000
562562
#endif
563563
/* value used for comparison in solver for cross-over point */
564+
KMP_ASSERT(tc > 0);
564565
long double target = ((long double)chunk * 2 + 1) * nproc / tc;
565566

566567
/* crossover point--chunk indexes equal to or greater than
@@ -1715,7 +1716,7 @@ int __kmp_dispatch_next_algorithm(int gtid,
17151716
status = 0; // nothing to do, don't try atomic op
17161717
break;
17171718
}
1718-
KMP_DEBUG_ASSERT(init % chunk == 0);
1719+
KMP_DEBUG_ASSERT(chunk && init % chunk == 0);
17191720
// compare with K*nproc*(chunk+1), K=2 by default
17201721
if ((T)remaining < pr->u.p.parm2) {
17211722
// use dynamic-style schedule

openmp/runtime/src/kmp_settings.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ static void __kmp_stg_parse_par_range(char const *name, char const *value,
431431
int *out_range, char *out_routine,
432432
char *out_file, int *out_lb,
433433
int *out_ub) {
434+
const char *par_range_value;
434435
size_t len = KMP_STRLEN(value) + 1;
435436
par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
436437
KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
@@ -439,11 +440,14 @@ static void __kmp_stg_parse_par_range(char const *name, char const *value,
439440
__kmp_par_range_ub = INT_MAX;
440441
for (;;) {
441442
unsigned int len;
442-
if (*value == '\0') {
443+
if (!value || *value == '\0') {
443444
break;
444445
}
445446
if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
446-
value = strchr(value, '=') + 1;
447+
par_range_value = strchr(value, '=') + 1;
448+
if (!par_range_value)
449+
goto par_range_error;
450+
value = par_range_value;
447451
len = __kmp_readstr_with_sentinel(out_routine, value,
448452
KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
449453
if (len == 0) {
@@ -456,7 +460,10 @@ static void __kmp_stg_parse_par_range(char const *name, char const *value,
456460
continue;
457461
}
458462
if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
459-
value = strchr(value, '=') + 1;
463+
par_range_value = strchr(value, '=') + 1;
464+
if (!par_range_value)
465+
goto par_range_error;
466+
value = par_range_value;
460467
len = __kmp_readstr_with_sentinel(out_file, value,
461468
KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
462469
if (len == 0) {
@@ -470,7 +477,10 @@ static void __kmp_stg_parse_par_range(char const *name, char const *value,
470477
}
471478
if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
472479
(!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
473-
value = strchr(value, '=') + 1;
480+
par_range_value = strchr(value, '=') + 1;
481+
if (!par_range_value)
482+
goto par_range_error;
483+
value = par_range_value;
474484
if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
475485
goto par_range_error;
476486
}
@@ -482,7 +492,10 @@ static void __kmp_stg_parse_par_range(char const *name, char const *value,
482492
continue;
483493
}
484494
if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
485-
value = strchr(value, '=') + 1;
495+
par_range_value = strchr(value, '=') + 1;
496+
if (!par_range_value)
497+
goto par_range_error;
498+
value = par_range_value;
486499
if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
487500
goto par_range_error;
488501
}

0 commit comments

Comments
 (0)