1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 12:02:58 +02:00
Commit Graph

178 Commits

Author SHA1 Message Date
Yaron Keren
672ca3153a Assert when trying to seek un-seekable raw_fd_ostream.
llvm-svn: 261614
2016-02-23 07:17:58 +00:00
Justin Lebar
975bf7a977 When printing MIR, output to errs() rather than outs().
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
2016-02-19 00:18:46 +00:00
Craig Topper
c6e9b3c725 [Support] Use hexdigit. NFC
llvm-svn: 260068
2016-02-08 01:03:01 +00:00
Craig Topper
a26758c5e3 [Support] Use range-based for loop. NFC
llvm-svn: 259763
2016-02-04 06:51:41 +00:00
Craig Topper
befca6184f [Support] Use hexdigit instead of manually coding the same thing. NFC
llvm-svn: 259762
2016-02-04 06:51:38 +00:00
Craig Topper
d406f34e77 Shrink character buffer size in raw_ostream::write_hex to 16 characters intead of 20 as that's the largest string a 64-bit hex value can be.
llvm-svn: 259313
2016-01-31 01:12:38 +00:00
Craig Topper
10624d8809 Use std::end instead of repeating buffer sizes.
llvm-svn: 259312
2016-01-31 01:12:35 +00:00
Reid Kleckner
74860c06bf Avoid the deprecated GetVersionEx API
Apparently the preferred version is the incredibly complicated
VerifyVersionInfoW function.

Rename the function to avoid potential future name clashes.

llvm-svn: 257415
2016-01-11 23:33:03 +00:00
Yunzhong Gao
0526fb6aaa Fixing PR25717: fatal IO error writing large outputs to console on Windows.
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
2016-01-06 00:50:06 +00:00
Rafael Espindola
5428b16a54 Drop an unnecessary use of writev.
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
2015-12-16 22:59:06 +00:00
Matthias Braun
a075ebf2eb Revert "raw_ostream: << operator for callables with raw_stream argument"
This commit provoked "error C2593: 'operator <<' is ambiguous" on MSVC.

This reverts commit r254655.

llvm-svn: 254661
2015-12-03 23:00:28 +00:00
Matthias Braun
cf5631d3ff raw_ostream: << operator for callables with raw_stream argument
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
2015-12-03 22:17:26 +00:00
Nick Lewycky
56f8b1409f Fix GCC warning: extra `;' [-Wpedantic].
llvm-svn: 244924
2015-08-13 18:10:19 +00:00
Yaron Keren
d2cb25b176 Modify raw_svector_ostream to use its SmallString without additional buffering.
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
2015-08-13 06:19:52 +00:00
Craig Topper
0ffd711178 Fix indentation. NFC.
llvm-svn: 238647
2015-05-30 07:35:21 +00:00
Rafael Espindola
28542bc9a4 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.

llvm-svn: 235303
2015-04-20 13:04:30 +00:00
Rafael Espindola
cf2ab6b126 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.

llvm-svn: 234952
2015-04-14 22:54:16 +00:00
Rafael Espindola
971bb23eca Add raw_pwrite_stream type.
This is a raw_ostream that also supports pwrite.
I will be used in a sec.

llvm-svn: 234895
2015-04-14 15:00:34 +00:00
Rafael Espindola
f087ddcbc4 Fix SupportsSeeking detection on windows.
Will be tested by existing tests once used (soon).

llvm-svn: 234737
2015-04-13 11:09:48 +00:00
Rafael Espindola
cedb53e4f1 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.

llvm-svn: 234734
2015-04-13 10:28:56 +00:00
NAKAMURA Takumi
0e31718486 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

llvm-svn: 234721
2015-04-13 04:54:19 +00:00
Rafael Espindola
88d9186eda Remember if lseek works in this FD.
It will be used in clang in a sec.

llvm-svn: 234619
2015-04-10 18:15:51 +00:00
Rafael Espindola
a87c07adf8 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.

llvm-svn: 234615
2015-04-10 17:52:22 +00:00
Rafael Espindola
00b7d1173b Misc cleanup. NFC.
These were lost when I reverted the raw_ostream changes.

llvm-svn: 234504
2015-04-09 16:59:07 +00:00
Rafael Espindola
edd11eb538 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.

llvm-svn: 234495
2015-04-09 15:54:59 +00:00
Rafael Espindola
0c8f021b8e Add classof implementations to the raw_ostream classes.
More uses to follow in a another patch.

llvm-svn: 234460
2015-04-09 02:10:28 +00:00
Benjamin Kramer
99efbfba33 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.

llvm-svn: 229337
2015-02-15 22:15:41 +00:00
Zachary Turner
0593219bd6 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

llvm-svn: 227108
2015-01-26 18:21:33 +00:00
Michael Ilseman
6d636ee500 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.

llvm-svn: 224154
2014-12-12 21:48:03 +00:00
David Majnemer
a2fe666876 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.

llvm-svn: 219189
2014-10-07 05:48:40 +00:00
David Majnemer
b3c0e72987 Support: Remove undefined behavior from &raw_ostream::operator<<
Don't negate signed integer types in &raw_ostream::operator<<(const
FormattedNumber &FN).

llvm-svn: 218496
2014-09-26 02:48:14 +00:00
Nick Kledzik
2ac9102fff [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  "

llvm-svn: 218463
2014-09-25 20:30:58 +00:00
Rafael Espindola
1d5713d9bf 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.

llvm-svn: 216393
2014-08-25 18:16:47 +00:00
Hans Wennborg
ebf51704c5 Typo: exists -> exits
llvm-svn: 213290
2014-07-17 18:33:44 +00:00
Alp Toker
043f69cb8d 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);

llvm-svn: 212837
2014-07-11 18:23:08 +00:00
Alp Toker
0d0baf0938 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.

llvm-svn: 212816
2014-07-11 14:02:04 +00:00
Alp Toker
97022b0c1f Revert "Introduce a string_ostream string builder facilty"
Temporarily back out commits r211749, r211752 and r211754.

llvm-svn: 211814
2014-06-26 22:52:05 +00:00
Alp Toker
fd9ead3b6f 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.

llvm-svn: 211749
2014-06-26 00:00:48 +00:00
Rafael Espindola
e0e308ff6d Don't use 'using std::error_code' in include/llvm.
This should make sure that most new uses use the std prefix.

llvm-svn: 210835
2014-06-12 21:46:39 +00:00
Rafael Espindola
38dc624425 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.

llvm-svn: 210803
2014-06-12 17:38:55 +00:00
Craig Topper
c2260fc0ab [C++11] More 'nullptr' conversion. In some cases just using a boolean check instead of comparing to nullptr.
llvm-svn: 206252
2014-04-15 06:32:26 +00:00
Ben Langmuir
6633cebb29 Revert "Use StringRef in raw_fd_ostream constructor"
This reverts commit r202225, which may cause a performance regression.

llvm-svn: 202338
2014-02-27 02:09:10 +00:00
Ben Langmuir
bcef7bd317 Use StringRef in raw_fd_ostream constructor
llvm-svn: 202225
2014-02-26 03:21:00 +00:00
Rafael Espindola
d89ca7eab7 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 :-)

llvm-svn: 202052
2014-02-24 18:20:12 +00:00
NAKAMURA Takumi
10c79bd94c raw_fd_ostream: Don't change STDERR to O_BINARY, or w*printf() (in assert()) would barf wide chars after llvm::errs().
llvm-svn: 199057
2014-01-12 16:14:24 +00:00
NAKAMURA Takumi
c474312d66 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.
llvm-svn: 199052
2014-01-12 14:44:46 +00:00
Benjamin Kramer
e783c63afd raw_fd_ostream: Be more verbose about the reason when opening a file fails.
llvm-svn: 191911
2013-10-03 16:59:14 +00:00
NAKAMURA Takumi
26b99c6974 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.

llvm-svn: 186480
2013-07-17 02:21:10 +00:00
Rafael Espindola
2a9326a78f 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).

llvm-svn: 186447
2013-07-16 19:44:17 +00:00
Rafael Espindola
3a0a77998b Create files with mode 666. This matches the behavior of other unix tools.
llvm-svn: 186414
2013-07-16 14:10:07 +00:00