Skip to content

Commit

Permalink
[OpenMP][libomp] Allow white spaces in OMP_TARGET_OFFLOAD value
Browse files Browse the repository at this point in the history
Remove heading/trailing white spaces when matching OMP_TARGET_OFFLOAD
value.

Differential Revision: https://reviews.llvm.org/D149890
  • Loading branch information
hansangbae committed Jun 5, 2023
1 parent b25c001 commit bd46706
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions openmp/runtime/src/kmp_settings.cpp
Expand Up @@ -282,6 +282,25 @@ static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
kmp_setting_t **rivals // List of rival settings (must include current one).
);

// Helper struct that trims heading/trailing white spaces
struct kmp_trimmed_str_t {
kmp_str_buf_t buf;
kmp_trimmed_str_t(const char *str) {
__kmp_str_buf_init(&buf);
size_t len = KMP_STRLEN(str);
if (len == 0)
return;
const char *begin = str;
const char *end = str + KMP_STRLEN(str) - 1;
SKIP_WS(begin);
while (begin < end && *end == ' ')
end--;
__kmp_str_buf_cat(&buf, begin, end - begin + 1);
}
~kmp_trimmed_str_t() { __kmp_str_buf_free(&buf); }
const char *get() { return buf.str; }
};

// -----------------------------------------------------------------------------
// Helper parse functions.

Expand Down Expand Up @@ -1385,14 +1404,13 @@ static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
// OpenMP 5.0: OMP_TARGET_OFFLOAD
static void __kmp_stg_parse_target_offload(char const *name, char const *value,
void *data) {
const char *next = value;
const char *scan = next;

kmp_trimmed_str_t value_str(value);
const char *scan = value_str.get();
__kmp_target_offload = tgt_default;
SKIP_WS(next);
if (*next == '\0')

if (*scan == '\0')
return;
scan = next;

if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
__kmp_target_offload = tgt_mandatory;
} else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
Expand All @@ -1402,7 +1420,6 @@ static void __kmp_stg_parse_target_offload(char const *name, char const *value,
} else {
KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
}

} // __kmp_stg_parse_target_offload

static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
Expand Down

0 comments on commit bd46706

Please sign in to comment.