[Openmp-commits] [openmp] bd46706 - [OpenMP][libomp] Allow white spaces in OMP_TARGET_OFFLOAD value
Hansang Bae via Openmp-commits
openmp-commits at lists.llvm.org
Mon Jun 5 15:42:21 PDT 2023
Author: Hansang Bae
Date: 2023-06-05T17:41:54-05:00
New Revision: bd46706b1f7590b832b3f01f84c54d79dbce8a04
URL: https://github.com/llvm/llvm-project/commit/bd46706b1f7590b832b3f01f84c54d79dbce8a04
DIFF: https://github.com/llvm/llvm-project/commit/bd46706b1f7590b832b3f01f84c54d79dbce8a04.diff
LOG: [OpenMP][libomp] Allow white spaces in OMP_TARGET_OFFLOAD value
Remove heading/trailing white spaces when matching OMP_TARGET_OFFLOAD
value.
Differential Revision: https://reviews.llvm.org/D149890
Added:
Modified:
openmp/runtime/src/kmp_settings.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp
index e6dd0ec946554..7092d6eb9104c 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -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.
@@ -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)) {
@@ -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,
More information about the Openmp-commits
mailing list