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

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 7 23:29:14 PDT 2021


Meinersbur added a comment.

Using `$` index specifier is a POSIX extension and should not have been used in portable code. Using `llvm::formatv` (`#include <llvm/Support/FormatVariadic.h>`) would have been the better choice. Unfortunately that would be a larger change.

Instead of redefining a runtime library function, I suggest to #ifdef the code that uses it, which is less intrusive. That is,

  #ifdef _MSC_VER
  int need{_vsprintf_p(nullptr, 0, p, ap)};
  #else
  int need{vsnprintf(nullptr, 0, p, ap)};
  #endif

Alternatively, define a compatibility wrapper for a platform-specific function, such as in `runtime/file.cpp`:

  inline static int openfile_ftruncate(int fd, OpenFile::FileOffset at) {
  #ifdef _WIN32
    return ::_chsize(fd, at);
  #else
    return ::ftruncate(fd, at);
  #endif
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107654



More information about the llvm-commits mailing list