[Openmp-commits] [PATCH] D149890: [OpenMP][libomp] Allow white spcaes in OMP_TARGET_OFFLOAD value
Hansang Bae via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Thu May 4 12:28:24 PDT 2023
hbae created this revision.
hbae added reviewers: tlwilmar, jlpeyton, Nawrin.
hbae added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
hbae requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Remove heading/trailing white spaces when matching OMP_TARGET_OFFLOAD
value.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149890
Files:
openmp/runtime/src/kmp_settings.cpp
Index: openmp/runtime/src/kmp_settings.cpp
===================================================================
--- openmp/runtime/src/kmp_settings.cpp
+++ openmp/runtime/src/kmp_settings.cpp
@@ -282,6 +282,25 @@
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.
@@ -1373,14 +1392,13 @@
// 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)) {
@@ -1390,7 +1408,6 @@
} else {
KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
}
-
} // __kmp_stg_parse_target_offload
static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149890.519602.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230504/7bd67ccb/attachment.bin>
More information about the Openmp-commits
mailing list