[PATCH] D107654: [Flang] Fix error messages on Windows.
Ivan Zhechev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 10 08:28:41 PDT 2021
ijan1 updated this revision to Diff 365486.
ijan1 added a comment.
Changed to be less intrusive.
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.365486.patch
Type: text/x-patch
Size: 877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210810/76e24ac2/attachment.bin>
More information about the llvm-commits
mailing list