[Openmp-commits] [PATCH] D41504: Remove unused positional argument for printf

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Dec 21 10:52:26 PST 2017


protze.joachim created this revision.
protze.joachim added reviewers: Hahnfeld, jlpeyton.

gcc on Ubuntu compiles by default with -D_FORTIFY_SOURCE=2. This results in a fatal runtime error, when kmp_msg tries to print a hint:

- invalid %N$ use detected ***

The format string for hints only prints the second argument (string) and drops the first argument (hint id). Depending on how you read the POSIX text for printf, this could be valid. But for practical reason, i.e., unpacking the va_list passed to printf based on the formating information, it makes sense to fix the implementation and not pass the id for hint.

Failing testcases are:

misc_bugs/teams-reduction.c
ompt/parallel/not_enough_threads.c


https://reviews.llvm.org/D41504

Files:
  runtime/src/i18n/en_US.txt
  runtime/src/kmp_i18n.cpp


Index: runtime/src/kmp_i18n.cpp
===================================================================
--- runtime/src/kmp_i18n.cpp
+++ runtime/src/kmp_i18n.cpp
@@ -823,13 +823,15 @@
     switch (message.type) {
     case kmp_mt_hint: {
       format = kmp_i18n_fmt_Hint;
+      // we cannot skip %1$ and only use %2$ to print the message without the number
+      fmsg = __kmp_msg_format(format, message.str);
     } break;
     case kmp_mt_syserr: {
       format = kmp_i18n_fmt_SysErr;
+      fmsg = __kmp_msg_format(format, message.num, message.str);
     } break;
     default: { KMP_DEBUG_ASSERT(0); }
     }
-    fmsg = __kmp_msg_format(format, message.num, message.str);
     __kmp_str_free(&message.str);
     __kmp_str_buf_cat(&buffer, fmsg.str, fmsg.len);
     __kmp_str_free(&fmsg.str);
Index: runtime/src/i18n/en_US.txt
===================================================================
--- runtime/src/i18n/en_US.txt
+++ runtime/src/i18n/en_US.txt
@@ -115,7 +115,7 @@
 Warning                      "OMP: Warning #%1$d: %2$s\n"
 Fatal                        "OMP: Error #%1$d: %2$s\n"
 SysErr                       "OMP: System error #%1$d: %2$s\n"
-Hint                         "OMP: Hint: %2$s\n"
+Hint                         "OMP: Hint %1$s\n"
 
 Pragma                       "%1$s pragma (at %2$s:%3$s():%4$s)"
     # %1 is pragma name (like "parallel" or "master",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41504.127912.patch
Type: text/x-patch
Size: 1382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20171221/ae385e89/attachment.bin>


More information about the Openmp-commits mailing list