[PATCH] D49680: [ADT] Replace std::isprint by llvm::isPrint.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 23 10:27:52 PDT 2018


Meinersbur created this revision.
Meinersbur added reviewers: Bigcheese, chandlerc, dblaikie, grimar, sammccall, jordan_rose.
Herald added a subscriber: dexonsmith.

The standard library functions isprint/std::isprint have platform- and locale-dependent behavior which makes LLVM's output less predictable. In particular, regression tests my fail depending on the implementation of these functions.

Implement llvm::isPrint in StringExtras.h with a standard behavior and replace all uses of isprint/std::isprint by a call it llvm::isPrint. The function is inlined and does not look up language settings so it should perform better than the standard library's version.

Such a replacement has already been done for isdigit, isalpha, isxdigit in r314883. gtest does the same in gtest-printers.cc using the following justification:

  // Returns true if c is a printable ASCII character.  We test the
  // value of c directly instead of calling isprint(), which is buggy on
  // Windows Mobile.
  inline bool IsPrintableAscii(wchar_t c) {
    return 0x20 <= c && c <= 0x7E;
  }

Similar issues have also been encountered by Julia: https://github.com/JuliaLang/julia/issues/7416

I noticed the problem myself when on Windows isprint('\t') started to evaluate to true (see https://stackoverflow.com/questions/51435249) and thus caused several unit tests to fail. The result of isprint doesn't seem to be well-defined even for ASCII characters. Therefore I suggest to replace isprint by a system-independent version.


Repository:
  rL LLVM

https://reviews.llvm.org/D49680

Files:
  include/llvm/ADT/StringExtras.h
  include/llvm/Support/raw_ostream.h
  lib/MC/MCAsmStreamer.cpp
  lib/ProfileData/InstrProfReader.cpp
  lib/Support/StringExtras.cpp
  lib/Support/raw_ostream.cpp
  lib/Support/regengine.inc
  tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
  tools/llvm-objdump/llvm-objdump.cpp
  tools/llvm-readobj/ObjDumper.cpp
  unittests/ADT/StringExtrasTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49680.156810.patch
Type: text/x-patch
Size: 7216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180723/889e4ce0/attachment.bin>


More information about the llvm-commits mailing list