summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Support: Don't call close again if we get EINTRDavid Majnemer2014-10-071-11/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Most Unix-like operating systems guarantee that the file descriptor is closed after a call to close(2), even if close comes back with EINTR. For these systems, calling close _again_ will either do nothing or close some other file descriptor open(2)'d by another thread. (Linux) However, some operating systems do not have this behavior. They require at least another call to close(2) before guaranteeing that the descriptor is closed. (HP-UX) And some operating systems have an unpredictable blend of the two behaviors! (xnu) Avoid this disaster by blocking all signals before we call close(2). This ensures that a signal will not be delivered to the thread and close(2) will not give us back EINTR. We restore the signal mask once the operation is done. N.B. This isn't a problem on Windows, it doesn't have a notion of EINTR because signals always get delivered to dedicated signal handling threads. llvm-svn: 219189
* Support: Remove undefined behavior from &raw_ostream::operator<<David Majnemer2014-09-261-1/+1
| | | | | | | Don't negate signed integer types in &raw_ostream::operator<<(const FormattedNumber &FN). llvm-svn: 218496
* [Support] Add type-safe alternative to llvm::format()Nick Kledzik2014-09-251-0/+57
| | | | | | | | | | | | | | | | | | | | | llvm::format() is somewhat unsafe. The compiler does not check that integer parameter size matches the %x or %d size and it does not complain when a StringRef is passed for a %s. And correctly using a StringRef with format() is ugly because you have to convert it to a std::string then call c_str(). The cases where llvm::format() is useful is controlling how numbers and strings are printed, especially when you want fixed width output. This patch adds some new formatting functions to raw_streams to format numbers and StringRefs in a type safe manner. Some examples: OS << format_hex(255, 6) => "0x00ff" OS << format_hex(255, 4) => "0xff" OS << format_decimal(0, 5) => " 0" OS << format_decimal(255, 5) => " 255" OS << right_justify(Str, 5) => " foo" OS << left_justify(Str, 5) => "foo " llvm-svn: 218463
* Modernize raw_fd_ostream's constructor a bit.Rafael Espindola2014-08-251-12/+4
| | | | | | | | | | Take a StringRef instead of a "const char *". Take a "std::error_code &" instead of a "std::string &" for error. A create static method would be even better, but this patch is already a bit too big. llvm-svn: 216393
* Typo: exists -> exitsHans Wennborg2014-07-171-1/+1
| | | | llvm-svn: 213290
* Simplify the raw_svector_ostream tweak from r212816Alp Toker2014-07-111-13/+4
| | | | | | | | | | | | The memcpy() and overlap helps didn't help much with timings, so clean up the change. The difference at this point is that we now leave growth of the storage buffer up to SmallVector's implementation: - OS.reserve(OS.capacity() * 2); + OS.reserve(OS.size() + 64); llvm-svn: 212837
* raw_svector_ostream: grow and reserve atomicallyAlp Toker2014-07-111-15/+17
| | | | | | | | | | Including the scratch buffer size in the initial reservation eliminates the subsequent malloc+move operation and offers a healthier constant growth with less memory wastage. When doing this, take care to avoid invalidating the source buffer. llvm-svn: 212816
* Revert "Introduce a string_ostream string builder facilty"Alp Toker2014-06-261-4/+0
| | | | | | Temporarily back out commits r211749, r211752 and r211754. llvm-svn: 211814
* Introduce a string_ostream string builder faciltyAlp Toker2014-06-261-0/+4
| | | | | | | | | | | | | | | | | | | | string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream<bytes> additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. llvm-svn: 211749
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-1/+1
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* Remove system_error.h.Rafael Espindola2014-06-121-1/+1
| | | | | | | This is a minimal change to remove the header. I will remove the occurrences of "using std::error_code" in a followup patch. llvm-svn: 210803
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-151-3/+3
| | | | | | instead of comparing to nullptr. llvm-svn: 206252
* Revert "Use StringRef in raw_fd_ostream constructor"Ben Langmuir2014-02-271-2/+3
| | | | | | This reverts commit r202225, which may cause a performance regression. llvm-svn: 202338
* Use StringRef in raw_fd_ostream constructorBen Langmuir2014-02-261-3/+2
| | | | llvm-svn: 202225
* Replace the F_Binary flag with a F_Text one.Rafael Espindola2014-02-241-1/+1
| | | | | | | | | After this I will set the default back to F_None. The advantage is that before this patch forgetting to set F_Binary would corrupt a file on windows. Forgetting to set F_Text produces one that cannot be read in notepad, which is a better failure mode :-) llvm-svn: 202052
* raw_fd_ostream: Don't change STDERR to O_BINARY, or w*printf() (in assert()) ↵NAKAMURA Takumi2014-01-121-2/+3
| | | | | | would barf wide chars after llvm::errs(). llvm-svn: 199057
* raw_stream formatter: [Win32] Use std::signbit() if available, instead of ↵NAKAMURA Takumi2014-01-121-0/+6
| | | | | | | _fpclass(). FIXME: It should be generic to C++11. For now, it is dedicated to mingw-w64. llvm-svn: 199052
* raw_fd_ostream: Be more verbose about the reason when opening a file fails.Benjamin Kramer2013-10-031-1/+2
| | | | llvm-svn: 191911
* raw_ostream.cpp: Introduce <fcntl.h> to let O_BINARY provided. Or, ↵NAKAMURA Takumi2013-07-171-0/+5
| | | | | | | | llvm::outs() would be set to O_TEXT by default. llvm/test/Object/check_binary_output.ll is expected to pass on win32. llvm-svn: 186480
* Add a wrapper for open.Rafael Espindola2013-07-161-31/+9
| | | | | | | This centralizes the handling of O_BINARY and opens the way for hiding more differences (like how open behaves with directories). llvm-svn: 186447
* Create files with mode 666. This matches the behavior of other unix tools.Rafael Espindola2013-07-161-1/+1
| | | | llvm-svn: 186414
* Remove the program class.Rafael Espindola2013-06-121-1/+1
| | | | | | | It was only used to implement ExecuteAndWait and ExecuteNoWait. Expose just those two functions and make Execute and Wait implementations details. llvm-svn: 183864
* Don't try to generate crash diagnostics if we had an I/O failure. It's veryChad Rosier2013-03-271-1/+1
| | | | | | | likely the crash diagnostics generation will fail as well. Part of rdar://13296693 llvm-svn: 178163
* Don't crash if write_impl() leaves less buffer space available than expected.Matt Beaumont-Gay2013-03-121-1/+6
| | | | | | This was tickled by a Clang diagnostic; Clang test case to follow. llvm-svn: 176911
* Add static cast to unsigned char whenever a character classification ↵Guy Benyei2013-02-121-1/+2
| | | | | | function is called with a signed char argument, in order to avoid assertions in Windows Debug configuration. llvm-svn: 175006
* Use the new script to sort the includes of every file under lib.Chandler Carruth2012-12-031-5/+5
| | | | | | | | | | | | | | | | | Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
* Replace the BUILTIN_EXPECT macro with a less horrible ↵Benjamin Kramer2012-08-291-6/+6
| | | | | | LLVM_LIKELY/LLVM_UNLIKELY interface. llvm-svn: 162873
* raw_ostream: Add a has_colors() method.Daniel Dunbar2012-07-201-0/+4
| | | | llvm-svn: 160558
* Fixed few warnings.Galina Kistanova2012-07-121-1/+2
| | | | llvm-svn: 160142
* Reapply 'Add reverseColor to raw_ostream'.Benjamin Kramer2012-04-161-0/+13
| | | | | | | To be used in printing unprintable source in clang diagnostics. Patch by Seth Cantrell, with a minor fix for mingw by me. llvm-svn: 154805
* Revert r154800 which breaks windows builders.Argyrios Kyrtzidis2012-04-161-13/+0
| | | | llvm-svn: 154802
* Add reverseColor to raw_ostream.Argyrios Kyrtzidis2012-04-161-0/+13
| | | | | | | To be used in printing unprintable source in clang diagnostics. Patch by Seth Cantrell! llvm-svn: 154800
* Support/Program: Make Change<stream>ToBinary return error_code.Michael J. Spencer2011-12-131-0/+1
| | | | llvm-svn: 146522
* Avoid undefined behavior in signed integer negation. Patch by Ahmed Charles.Eli Friedman2011-10-131-1/+2
| | | | llvm-svn: 141905
* Fix integer overflow bug in raw_ostream::write. This showed up as aNick Lewycky2011-08-281-2/+2
| | | | | | non-deterministic crash in the test suite. Fixes PR10055! llvm-svn: 138717
* raw_ostream: [PR6745] Tweak formatting (double)%e for Windows hosts.NAKAMURA Takumi2011-03-181-0/+30
| | | | | | | On MSVCRT and compatible, output of %e is incompatible to Posix by default. Number of exponent digits should be at least 2. "%+03d" FIXME: Implement our formatter in future! llvm-svn: 127872
* lib/Support/raw_ostream.cpp: On mingw, report_fatal_error() should not be ↵NAKAMURA Takumi2011-03-161-0/+8
| | | | | | | | called at dtor context. report_fatal_error() invokes exit(). We know report_fatal_error() might not write messages to stderr when any errors were detected on FD == 2. llvm-svn: 127726
* raw_ostream: while it is generally desirable to do larger writes, it can lead toBenjamin Kramer2011-03-041-3/+7
| | | | | | | | | | inefficient file system buffering if the writes are not a multiple of the desired buffer size. Avoid this by limiting the large write to a multiple of the buffer size and copying the remainder into the buffer. Thanks to Dan for pointing this out. llvm-svn: 127026
* raw_ostream: If writing a string that is larger than the buffer, write it ↵Benjamin Kramer2011-03-041-9/+13
| | | | | | | | directly instead of doing many buffer-sized writes. This caps the number of write(2) calls per string to a maximum of 2. llvm-svn: 127010
* raw_fd_ostream: Add a SetUseAtomicWrites() method (uses writev).Daniel Dunbar2011-02-031-3/+21
| | | | llvm-svn: 124771
* Support/raw_ostream: Fix uninitalized variable in raw_fd_ostream constructor.Michael J. Spencer2011-01-171-0/+7
| | | | llvm-svn: 123643
* Merge System into Support.Michael J. Spencer2010-11-291-2/+2
| | | | llvm-svn: 120298
* raw_ostream::write_escaped: Add a UseHexEscapes argument.Daniel Dunbar2010-11-271-6/+15
| | | | llvm-svn: 120200
* lib/Support/raw_ostream.cpp: Fix Cygwin's build.NAKAMURA Takumi2010-10-191-0/+4
| | | | | | setmode is provided by io.h on Cygwin. llvm-svn: 116784
* Always use binary mode for output stream. This is important to prevent ↵Francois Pichet2010-10-141-0/+13
| | | | | | unwanted end of line conversion on Windows. Should not affect Unix where O_BINARY is not defined. This fix /clang/test/lexer/preamble.c XFAIL on WIN32. llvm-svn: 116509
* Move tool_output_file into its own file.Dan Gohman2010-10-071-32/+0
| | | | llvm-svn: 115973
* Make tool_output_file's raw_ostream instance a member variable insteadDan Gohman2010-09-011-14/+18
| | | | | | | | | | of a base class. This makes it possible to unregister the file from FilesToRemove when the file is done. Also, this eliminates the need for formatted_tool_output_file. llvm-svn: 112706
* Make outs() close its file when its stream is destructed, so thatDan Gohman2010-08-201-2/+4
| | | | | | pending output errors are detected. llvm-svn: 111643
* Delete raw_stdout_ostream and raw_stderr_ostream, which are unusedDan Gohman2010-08-201-12/+4
| | | | | | | outside of outs() and errs() themselves, and they don't really need custom classes. llvm-svn: 111642
* Move raw_ostream's Error flag into raw_fd_ostream, as that's the onlyDan Gohman2010-08-201-16/+17
| | | | | | class which is using it. llvm-svn: 111639
OpenPOWER on IntegriCloud