Commit Graph

164 Commits

Author SHA1 Message Date
Craig Topper
15617cdf57 Fix indentation. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238647 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-30 07:35:21 +00:00
Rafael Espindola
f30ac8f5ec Don't allow pwrite to resize a stream.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235303 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-20 13:04:30 +00:00
Rafael Espindola
83ed6b7814 Use the ability to pwrite to simplify the ELF writer.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234952 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-14 22:54:16 +00:00
Rafael Espindola
661ed85834 Add raw_pwrite_stream type.
This is a raw_ostream that also supports pwrite.
I will be used in a sec.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234895 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-14 15:00:34 +00:00
Rafael Espindola
e29e10190e Fix SupportsSeeking detection on windows.
Will be tested by existing tests once used (soon).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234737 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 11:09:48 +00:00
Rafael Espindola
2b6ba77325 Add r234615 back, but make sure outs() is binary.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234734 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 10:28:56 +00:00
NAKAMURA Takumi
47882583cb Revert r234615, "Have one raw_fd_ostream constructor forward to the other."
It broke MSVCRT hosts:

  LLVM :: Object/check_binary_output.ll
  LLVM :: Object/extract.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234721 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-13 04:54:19 +00:00
Rafael Espindola
e37b898edb Remember if lseek works in this FD.
It will be used in clang in a sec.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234619 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10 18:15:51 +00:00
Rafael Espindola
f52cd1c1a3 Have one raw_fd_ostream constructor forward to the other.
This fixes some odd behavior differences between the two. In particular,
the version that takes a FD no longer unconditionally sets stdout to binary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234615 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10 17:52:22 +00:00
Rafael Espindola
b7fc45006e Misc cleanup. NFC.
These were lost when I reverted the raw_ostream changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234504 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-09 16:59:07 +00:00
Rafael Espindola
a93117c50d This reverts commit r234460 and r234461.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234495 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-09 15:54:59 +00:00
Rafael Espindola
271631a0af Add classof implementations to the raw_ostream classes.
More uses to follow in a another patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234460 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-09 02:10:28 +00:00
Benjamin Kramer
aee01b35e4 Format: Modernize using variadic templates.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229337 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-15 22:15:41 +00:00
Zachary Turner
019c097d1b Teach raw_ostream to support hex formatting without a prefix '0x'.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227108 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-26 18:21:33 +00:00
Michael Ilseman
3f0e8837be Clean up static analyzer warnings.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224154 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-12 21:48:03 +00:00
David Majnemer
220c5ca8f4 Support: Don't call close again if we get EINTR
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219189 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-07 05:48:40 +00:00
David Majnemer
346056ffc0 Support: Remove undefined behavior from &raw_ostream::operator<<
Don't negate signed integer types in &raw_ostream::operator<<(const
FormattedNumber &FN).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218496 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-26 02:48:14 +00:00
Nick Kledzik
e93da60ac4 [Support] Add type-safe alternative to llvm::format()
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  "



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218463 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-25 20:30:58 +00:00
Rafael Espindola
8c96862847 Modernize raw_fd_ostream's constructor a bit.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216393 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-25 18:16:47 +00:00
Hans Wennborg
c636a42d4a Typo: exists -> exits
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213290 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 18:33:44 +00:00
Alp Toker
1736df6ae0 Simplify the raw_svector_ostream tweak from r212816
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);

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212837 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-11 18:23:08 +00:00
Alp Toker
81bc6fb854 raw_svector_ostream: grow and reserve atomically
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212816 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-11 14:02:04 +00:00
Alp Toker
8dd8d5c2b2 Revert "Introduce a string_ostream string builder facilty"
Temporarily back out commits r211749, r211752 and r211754.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211814 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-26 22:52:05 +00:00
Alp Toker
2559070422 Introduce a string_ostream string builder facilty
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-26 00:00:48 +00:00
Rafael Espindola
5c792faa0e Don't use 'using std::error_code' in include/llvm.
This should make sure that most new uses use the std prefix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210835 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-12 21:46:39 +00:00
Rafael Espindola
d5132f9073 Remove system_error.h.
This is a minimal change to remove the header. I will remove the occurrences
of "using std::error_code" in a followup patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210803 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-12 17:38:55 +00:00
Craig Topper
0b6cb7104b [C++11] More 'nullptr' conversion. In some cases just using a boolean check instead of comparing to nullptr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206252 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-15 06:32:26 +00:00
Ben Langmuir
8a6c29ef5b Revert "Use StringRef in raw_fd_ostream constructor"
This reverts commit r202225, which may cause a performance regression.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202338 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-27 02:09:10 +00:00
Ben Langmuir
ca302abd20 Use StringRef in raw_fd_ostream constructor
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202225 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-26 03:21:00 +00:00
Rafael Espindola
ac69459e0f Replace the F_Binary flag with a F_Text one.
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 :-)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202052 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-24 18:20:12 +00:00
NAKAMURA Takumi
25ca9f9ef1 raw_fd_ostream: Don't change STDERR to O_BINARY, or w*printf() (in assert()) would barf wide chars after llvm::errs().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199057 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-12 16:14:24 +00:00
NAKAMURA Takumi
486fdaae66 raw_stream formatter: [Win32] Use std::signbit() if available, instead of _fpclass().
FIXME: It should be generic to C++11. For now, it is dedicated to mingw-w64.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199052 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-12 14:44:46 +00:00
Benjamin Kramer
63fac20ec5 raw_fd_ostream: Be more verbose about the reason when opening a file fails.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191911 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-03 16:59:14 +00:00
NAKAMURA Takumi
f7e73accb7 raw_ostream.cpp: Introduce <fcntl.h> to let O_BINARY provided. Or, llvm::outs() would be set to O_TEXT by default.
llvm/test/Object/check_binary_output.ll is expected to pass on win32.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186480 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-17 02:21:10 +00:00
Rafael Espindola
c1b49b56d4 Add a wrapper for open.
This centralizes the handling of O_BINARY and opens the way for hiding more
differences (like how open behaves with directories).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186447 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 19:44:17 +00:00
Rafael Espindola
67f9b377ba Create files with mode 666. This matches the behavior of other unix tools.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186414 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 14:10:07 +00:00
Rafael Espindola
9f1d9fd196 Remove the program class.
It was only used to implement ExecuteAndWait and ExecuteNoWait. Expose just
those two functions and make Execute and Wait implementations details.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183864 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-12 20:58:35 +00:00
Chad Rosier
2b7f219051 Don't try to generate crash diagnostics if we had an I/O failure. It's very
likely the crash diagnostics generation will fail as well.
Part of rdar://13296693


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178163 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-27 18:30:00 +00:00
Matt Beaumont-Gay
b79d25ca9c Don't crash if write_impl() leaves less buffer space available than expected.
This was tickled by a Clang diagnostic; Clang test case to follow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176911 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-12 23:55:24 +00:00
Guy Benyei
87d0b9ed14 Add static cast to unsigned char whenever a character classification function is called with a signed char argument, in order to avoid assertions in Windows Debug configuration.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175006 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-12 21:21:59 +00:00
Chandler Carruth
d04a8d4b33 Use the new script to sort the includes of every file under lib.
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. =]

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169131 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-03 16:50:05 +00:00
Benjamin Kramer
55907d1274 Replace the BUILTIN_EXPECT macro with a less horrible LLVM_LIKELY/LLVM_UNLIKELY interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162873 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-29 22:57:00 +00:00
Daniel Dunbar
d79637b940 raw_ostream: Add a has_colors() method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160558 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-20 18:29:41 +00:00
Galina Kistanova
d897599e5b Fixed few warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160142 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-12 20:45:36 +00:00
Benjamin Kramer
246de858e3 Reapply 'Add reverseColor to raw_ostream'.
To be used in printing unprintable source in clang diagnostics.
Patch by Seth Cantrell, with a minor fix for mingw by me.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154805 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-16 08:56:50 +00:00
Argyrios Kyrtzidis
c9413c745b Revert r154800 which breaks windows builders.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154802 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-16 07:59:39 +00:00
Argyrios Kyrtzidis
7d31d75a77 Add reverseColor to raw_ostream.
To be used in printing unprintable source in clang diagnostics.
Patch by Seth Cantrell!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154800 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-16 07:07:38 +00:00
Michael J. Spencer
b92cb30cf5 Support/Program: Make Change<stream>ToBinary return error_code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146522 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-13 23:16:49 +00:00
Eli Friedman
90406e18b8 Avoid undefined behavior in signed integer negation. Patch by Ahmed Charles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141905 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-13 22:49:56 +00:00
Nick Lewycky
b1b051ec97 Fix integer overflow bug in raw_ostream::write. This showed up as a
non-deterministic crash in the test suite. Fixes PR10055!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138717 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-28 03:30:02 +00:00