[flang-commits] [flang] 35249cb - [Flang] Fix error messages on Windows.
Mats Petersson via flang-commits
flang-commits at lists.llvm.org
Thu Aug 12 10:51:46 PDT 2021
Author: Ivan Zhechev
Date: 2021-08-12T18:35:54+01:00
New Revision: 35249cb7b1e82147ef08de12bdf34a29d8c58d53
URL: https://github.com/llvm/llvm-project/commit/35249cb7b1e82147ef08de12bdf34a29d8c58d53
DIFF: https://github.com/llvm/llvm-project/commit/35249cb7b1e82147ef08de12bdf34a29d8c58d53.diff
LOG: [Flang] Fix error messages on Windows.
Flang uses positional arguments for `messages::say()`, such as "%1$s" which is only supported in MS Compilers with the `_*printf_p` form of the function. This uses a conditional macro to convert the existing `vsnprintf` used to the one needed in MS-World.
7 tests in D107575 rely on this change.
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D107654
Added:
Modified:
flang/lib/Parser/message.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/message.cpp b/flang/lib/Parser/message.cpp
index f565112eb928d..fd4a52c895bf9 100644
--- a/flang/lib/Parser/message.cpp
+++ b/flang/lib/Parser/message.cpp
@@ -38,14 +38,26 @@ void MessageFormattedText::Format(const MessageFixedText *text, ...) {
}
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;
More information about the flang-commits
mailing list