[PATCH] D107654: [Flang] Fix error messages on Windows.

Mats Petersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 10:51:58 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35249cb7b1e8: [Flang] Fix error messages on Windows. (authored by ijan1, committed by MatsPetersson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107654/new/

https://reviews.llvm.org/D107654

Files:
  flang/lib/Parser/message.cpp


Index: flang/lib/Parser/message.cpp
===================================================================
--- flang/lib/Parser/message.cpp
+++ flang/lib/Parser/message.cpp
@@ -38,14 +38,26 @@
   }
   va_list ap;
   va_start(ap, text);
+#ifdef _MSC_VER
+  // Microsoft has a separate function for "positional arguments", which is
+  // used in some messages.
+  int need{_vsprintf_p(nullptr, 0, p, ap)};
+#else
   int need{vsnprintf(nullptr, 0, p, ap)};
+#endif
+
   CHECK(need >= 0);
   char *buffer{
       static_cast<char *>(std::malloc(static_cast<std::size_t>(need) + 1))};
   CHECK(buffer);
   va_end(ap);
   va_start(ap, text);
+#ifdef _MSC_VER
+  // Use positional argument variant of printf.
+  int need2{_vsprintf_p(buffer, need + 1, p, ap)};
+#else
   int need2{vsnprintf(buffer, need + 1, p, ap)};
+#endif
   CHECK(need2 == need);
   va_end(ap);
   string_ = buffer;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107654.366036.patch
Type: text/x-patch
Size: 877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210812/f84f5b09/attachment.bin>


More information about the llvm-commits mailing list