summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Assert when trying to seek un-seekable raw_fd_ostream.Yaron Keren2016-02-231-0/+1
| | | | llvm-svn: 261614
* When printing MIR, output to errs() rather than outs().Justin Lebar2016-02-191-3/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Without this, this command $ llvm-run llc -stop-after machine-cp -o - <( echo '' ) outputs an error, because we close stdout twice -- once when closing the file opened for "-o", and again when closing outs(). Also clarify in the outs() definition that you can't ever call it if you want to open your own raw_fd_ostream on stdout. Reviewers: jroelofs, tstellarAMD Subscribers: jholewinski, qcolombet, dsanders, llvm-commits Differential Revision: http://reviews.llvm.org/D17422 llvm-svn: 261286
* [Support] Use hexdigit. NFCCraig Topper2016-02-081-3/+2
| | | | llvm-svn: 260068
* [Support] Use range-based for loop. NFCCraig Topper2016-02-041-3/+1
| | | | llvm-svn: 259763
* [Support] Use hexdigit instead of manually coding the same thing. NFCCraig Topper2016-02-041-2/+2
| | | | llvm-svn: 259762
* Shrink character buffer size in raw_ostream::write_hex to 16 characters ↵Craig Topper2016-01-311-1/+1
| | | | | | intead of 20 as that's the largest string a 64-bit hex value can be. llvm-svn: 259313
* Use std::end instead of repeating buffer sizes.Craig Topper2016-01-311-2/+2
| | | | llvm-svn: 259312
* Avoid the deprecated GetVersionEx APIReid Kleckner2016-01-111-1/+1
| | | | | | | | | Apparently the preferred version is the incredibly complicated VerifyVersionInfoW function. Rename the function to avoid potential future name clashes. llvm-svn: 257415
* Fixing PR25717: fatal IO error writing large outputs to console on Windows.Yunzhong Gao2016-01-061-1/+18
| | | | | | | | | | | | | This patch is similar to the Python issue#11395. We need to cap the output size to 32767 on Windows to work around the size limit of WriteConsole(). Reference: https://bugs.python.org/issue11395 Writing a test for this bug turns out to be harder than I thought. I am still working on it (see phabricator review D15705). Differential Revision: http://reviews.llvm.org/D15553 llvm-svn: 256892
* Drop an unnecessary use of writev.Rafael Espindola2015-12-161-16/+2
| | | | | | | | | | | It looks like the code this patch deletes is based on a misunderstanding of what guarantees writev provides. In particular, writev with 1 iovec is not "more atomic" than a write. Testing on OS X shows that both write and writev from multiple processes can be intermixed. llvm-svn: 255837
* Revert "raw_ostream: << operator for callables with raw_stream argument"Matthias Braun2015-12-031-4/+0
| | | | | | | | This commit provoked "error C2593: 'operator <<' is ambiguous" on MSVC. This reverts commit r254655. llvm-svn: 254661
* raw_ostream: << operator for callables with raw_stream argumentMatthias Braun2015-12-031-0/+4
| | | | | | | | | | | | | | | | | This allows easier construction of print helpers. Example: Printable PrintLaneMask(unsigned LaneMask) { return Printable([LaneMask](raw_ostream &OS) { OS << format("%08X", LaneMask); }); } // Usage: OS << PrintLaneMask(Mask); Differential Revision: http://reviews.llvm.org/D14348 llvm-svn: 254655
* Fix GCC warning: extra `;' [-Wpedantic].Nick Lewycky2015-08-131-1/+1
| | | | llvm-svn: 244924
* Modify raw_svector_ostream to use its SmallString without additional buffering.Yaron Keren2015-08-131-62/+5
| | | | | | | | | This is faster and avoids the stream and SmallString state synchronization issue. resync() is a no-op and may be safely deleted. I'll do so in a follow-up commit. Reviewed by Rafael Espindola. llvm-svn: 244870
* Fix indentation. NFC.Craig Topper2015-05-301-1/+1
| | | | llvm-svn: 238647
* Don't allow pwrite to resize a stream.Rafael Espindola2015-04-201-9/+6
| | | | | | | | | | | | | | | | | | | | | The current implementations could exhibit some behavior differences: raw_fd_ostream: Whatever the underlying fd does with seek+write. In a normal file, the write position would be back to the old offset. raw_svector_ostream: The write position is always the end of the stream, so after pwrite the write position would be the new end. This matches what OS_X (all BSD?) do with a pwrite in a O_APPEND fd. Given that we don't need that feature and don't use O_APPEND a lot in LLVM, just disallow it. I am open to suggestions on renaming pwrite to something else, but this fixes the issue for now. Thanks to Yaron Keren for reporting it. llvm-svn: 235303
* Use the ability to pwrite to simplify the ELF writer.Rafael Espindola2015-04-141-1/+1
| | | | | | | | | | | | Now we don't have to do 2 synchronized passes to compute offsets and then write the file. This also includes a fix for the corner case of seeking in /dev/null. It is not an error, but on some systems (Linux) the returned offset is always 0. An error is signaled by returning -1. This is checked by the existing tests now that "clang -o /dev/null ..." seeks. llvm-svn: 234952
* Add raw_pwrite_stream type.Rafael Espindola2015-04-141-2/+29
| | | | | | | This is a raw_ostream that also supports pwrite. I will be used in a sec. llvm-svn: 234895
* Fix SupportsSeeking detection on windows.Rafael Espindola2015-04-131-0/+7
| | | | | | Will be tested by existing tests once used (soon). llvm-svn: 234737
* Add r234615 back, but make sure outs() is binary.Rafael Espindola2015-04-131-25/+21
| | | | | | | | | | | Original message. Have one raw_fd_ostream constructor forward to the other. This fixes some odd behaviour differences between the two. In particular, the version that takes a FD no longer unconditionally sets stdout to binary. llvm-svn: 234734
* Revert r234615, "Have one raw_fd_ostream constructor forward to the other."NAKAMURA Takumi2015-04-131-18/+24
| | | | | | | | | It broke MSVCRT hosts: LLVM :: Object/check_binary_output.ll LLVM :: Object/extract.ll llvm-svn: 234721
* Remember if lseek works in this FD.Rafael Espindola2015-04-101-1/+2
| | | | | | It will be used in clang in a sec. llvm-svn: 234619
* Have one raw_fd_ostream constructor forward to the other.Rafael Espindola2015-04-101-24/+18
| | | | | | | This fixes some odd behavior differences between the two. In particular, the version that takes a FD no longer unconditionally sets stdout to binary. llvm-svn: 234615
* Misc cleanup. NFC.Rafael Espindola2015-04-091-4/+4
| | | | | | These were lost when I reverted the raw_ostream changes. llvm-svn: 234504
* This reverts commit r234460 and r234461.Rafael Espindola2015-04-091-5/+4
| | | | | | | | | Revert "Add classof implementations to the raw_ostream classes." Revert "Use the cast machinery to remove dummy uses of formatted_raw_ostream." The underlying issue can be fixed without classof. llvm-svn: 234495
* Add classof implementations to the raw_ostream classes.Rafael Espindola2015-04-091-4/+5
| | | | | | More uses to follow in a another patch. llvm-svn: 234460
* Format: Modernize using variadic templates.Benjamin Kramer2015-02-151-1/+1
| | | | | | | | | | | Introduces a subset of C++14 integer sequences in STLExtras. This is just enough to support unpacking a std::tuple into the arguments of snprintf, we can add more of it when it's actually needed. Also removes an ancient macro hack that leaks a macro into the global namespace. Clean up users that made use of the convenient hack. llvm-svn: 229337
* Teach raw_ostream to support hex formatting without a prefix '0x'.Zachary Turner2015-01-261-2/+5
| | | | | | | | | | Previously using format_hex() would always print a 0x prior to the hex characters. This allows this to be optional, so that one can choose to print (e.g.) 255 as either 0xFF or just FF. Differential Revision: http://reviews.llvm.org/D7151 llvm-svn: 227108
* Clean up static analyzer warnings.Michael Ilseman2014-12-121-0/+1
| | | | | | | | | Clang's static analyzer found several potential cases of undefined behavior, use of un-initialized values, and potentially null pointer dereferences in tablegen, Support, MC, and ADT. This cleans them up with specific assertions on the assumptions of the code. llvm-svn: 224154
* 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
OpenPOWER on IntegriCloud