Commit Graph

481 Commits

Author SHA1 Message Date
Hans Wennborg 44e2746418 BumpPtrAllocator: do the size check without moving any pointers
Instead of aligning and moving the CurPtr forward, and then comparing
with End, simply calculate how much space is needed, and compare that
to how much is available.

Hopefully this avoids any doubts about comparing addresses possibly
derived from past the end of the slab array, overflowing, etc.

Also add a test where aligning CurPtr would move it past End.

llvm-svn: 217330
2014-09-07 04:24:31 +00:00
Rafael Espindola 9c35966944 Add writeFileWithSystemEncoding to LibLLVMSuppor.
This patch adds to LLVMSupport the capability of writing files with
international characters encoded in the current system encoding. This
is relevant for Windows, where we can either use UTF16 or the current
code page (the legacy Windows international characters). On UNIX, the
file is always saved in UTF8.

This will be used in a patch for clang to thoroughly support response
files creation when calling other tools, addressing PR15171. On
Windows, to correctly support internationalization, we need the
ability to write response files both in UTF16 or the current code
page, depending on the tool we will call. GCC for mingw, for instance,
requires files to be encoded in the current code page. MSVC tools
requires files to be encoded in UTF16.

Patch by Rafael Auler!

llvm-svn: 217068
2014-09-03 20:02:00 +00:00
David Blaikie 99b96f42d6 Ensure ErrorOr cannot implicitly invoke explicit ctors of the underlying type.
An unpleasant surprise while migrating unique_ptrs (see changes in
lib/Object): ErrorOr<int*> was implicitly convertible to
ErrorOr<std::unique_ptr<int>>.

Keep the explicit conversions otherwise it's a pain to convert
ErrorOr<int*> to ErrorOr<std::unique_ptr<int>>.

I'm not sure if there should be more SFINAE on those explicit ctors (I
could check if !is_convertible && is_constructible, but since the ctor
has to be called explicitly I don't think there's any need to disable
them when !is_constructible - they'll just fail anyway. It's the
converting ctors that can create interesting ambiguities without proper
SFINAE). I had to SFINAE the explicit ones because otherwise they'd be
ambiguous with the implicit ones in an explicit context, so far as I
could tell.

The converting assignment operators seemed unnecessary (and similarly
buggy/dangerous) - just rely on the converting ctors to convert to the
right type for assignment instead.

llvm-svn: 217048
2014-09-03 17:31:25 +00:00
Hans Wennborg 3b84f59b6b BumpPtrAllocator: use uintptr_t when aligning addresses to avoid undefined behaviour
In theory, alignPtr() could push a pointer beyond the end of the current slab, making
comparisons with that pointer undefined behaviour. Use an integer type to avoid this.

llvm-svn: 216973
2014-09-02 21:51:35 +00:00
David Blaikie 15913f46b2 unique_ptrify the result of SpecialCaseList::create
llvm-svn: 216925
2014-09-02 18:13:54 +00:00
Chris Bieneman 5e7f44c25e Cleaning up static initializers in TimeValue.
Code reviewed by Chandlerc

llvm-svn: 216703
2014-08-29 01:05:12 +00:00
David Blaikie dfbe3d6b17 Convert a few more cases of direct intialization of unique_ptrs from MemoryBuffer::getMemBuffer to move initialization now that it returns by unique_ptr instead of raw pointer.
Cleanup/improvements following r216583.

llvm-svn: 216605
2014-08-27 20:14:18 +00:00
Rafael Espindola 3560ff2c1f Return a std::unique_ptr when creating a new MemoryBuffer.
llvm-svn: 216583
2014-08-27 20:03:13 +00:00
Rafael Espindola 68669e3a7b yaml::Stream doesn't need to take ownership of the buffer.
In fact, most users were already using the StringRef version.

llvm-svn: 216575
2014-08-27 19:03:22 +00:00
Craig Topper e1d1294853 Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created.
llvm-svn: 216525
2014-08-27 05:25:25 +00:00
Reid Kleckner d83c63b704 Fix Path unittests on Windows after raw_fd_ostream changes
llvm-svn: 216422
2014-08-26 00:24:23 +00:00
Rafael Espindola 3fd1e9933f 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
Reid Kleckner e3f146d941 Fix PR17239 by changing the semantics of the RemainingArgsClass Option kind
This patch contains the LLVM side of the fix of PR17239.

This bug that happens because the /link (clang-cl.exe argument) is
marked as "consume all remaining arguments". However, when inside a
response file, /link should only consume all remaining arguments inside
the response file where it is located, not the entire command line after
expansion.

My patch will change the semantics of the RemainingArgsClass kind to
always consume only until the end of the response file when the option
originally came from a response file. There are only two options in this
class: dash dash (--) and /link.

Reviewed By: rnk

Differential Revision: http://reviews.llvm.org/D4899

Patch by Rafael Auler!

llvm-svn: 216280
2014-08-22 19:29:17 +00:00
Alex Lorenz 5117674f55 [Support] Fix the overflow bug in ULEB128 decoding.
Differential Revision: http://reviews.llvm.org/D5029

llvm-svn: 216268
2014-08-22 16:29:45 +00:00
David Blaikie 1961f14cf9 Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using std::unique_ptr
llvm-svn: 216223
2014-08-21 20:44:56 +00:00
Hans Wennborg fd1f0f17c5 BumpPtrAllocator: don't accept 0 for the alignment parameter
It seems unnecessary to have to use an extra branch to check for this special case.

http://reviews.llvm.org/D4945

llvm-svn: 216036
2014-08-19 23:35:33 +00:00
Rafael Espindola b16ecf8224 Convert an ownership comment with std::uinque_ptr.
llvm-svn: 215855
2014-08-17 22:20:33 +00:00
Hans Wennborg d47b1d76fd BumpPtrAllocator: remove 'no slabs allocated yet' check
We already handle the no-slabs case when checking whether the current slab
is large enough: if no slabs have been allocated, CurPtr and End are both 0.
alignPtr(0), will still be 0, and so "if (Ptr + Size <= End)" fails.

Differential Revision: http://reviews.llvm.org/D4943

llvm-svn: 215841
2014-08-17 18:31:18 +00:00
Sean Silva db79484998 Revert "[Support] Promote cl::StringSaver to a separate utility"
This reverts commit r215784 / 3f8a26f6fe16cc76c98ab21db2c600bd7defbbaa.

LLD has 3 StringSaver's, one of which takes a lock when saving the
string... Need to investigate more closely.

llvm-svn: 215790
2014-08-15 23:39:01 +00:00
Sean Silva 42ec6fdf58 [Support] Promote cl::StringSaver to a separate utility
This class is generally useful.

In breaking it out, the primary change is that it has been made
non-virtual. It seems like being abstract led to there being 3 different
(2 in llvm + 1 in clang) concrete implementations which disagreed about
the ownership of the saved strings (see the manual call to free() in the
unittest StrDupSaver; yes this is different from the CommandLine.cpp
StrDupSaver which owns the stored strings; which is different from
Clang's StringSetSaver which just holds a reference to a
std::set<std::string> which owns the strings).

I've identified 2 other places in the
codebase that are open-coding this pattern:

  memcpy(Alloc.Allocate<char>(strlen(S)+1), S, strlen(S)+1)

I'll be switching them over. They are
* llvm::sys::Process::GetArgumentVector
* The StringAllocator member of YAMLIO's Input class
This also will allow simplifying Clang's driver.cpp quite a bit.

Let me know if there are any other places that could benefit from
StringSaver. I'm also thinking of adding a saveStringRef member for
getting a stable StringRef.

llvm-svn: 215784
2014-08-15 23:18:33 +00:00
Benjamin Foster bdefab961a Test commit, remove trailing whitespace
llvm-svn: 215556
2014-08-13 16:11:50 +00:00
Aaron Ballman 74c2c8f160 Asserting that the call to chdir succeeds in this test. Fixes some -Wunused-result warnings.
llvm-svn: 215539
2014-08-13 11:17:41 +00:00
Rafael Espindola ffbabb7925 Fix expected windows result.
llvm-svn: 215267
2014-08-09 00:37:05 +00:00
Rafael Espindola 7e774c249f Remove dead code. Fixes pr20544.
llvm-svn: 215243
2014-08-08 21:35:52 +00:00
Rafael Espindola a97373f235 Fix bug 20125 - clang-format segfaults on bad config.
The problem was in unchecked dyn_cast inside of Input::createHNodes.
Patch by Roman Kashitsyn!

llvm-svn: 215205
2014-08-08 13:58:00 +00:00
Justin Bogner 487e764b58 Path: Stop claiming path::const_iterator is bidirectional
path::const_iterator claims that it's a bidirectional iterator, but it
doesn't satisfy all of the contracts for a bidirectional iterator.
For example, n3376 24.2.5 p6 says "If a and b are both dereferenceable,
then a == b if and only if *a and *b are bound to the same object",
but this doesn't work with how we stash and recreate Components.

This means that our use of reverse_iterator on this type is invalid
and leads to many of the valgrind errors we're hitting, as explained
by Tilmann Scheller here:

    http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140728/228654.html

Instead, we admit that path::const_iterator is only an input_iterator,
and implement a second input_iterator for path::reverse_iterator (by
changing const_iterator::operator-- to reverse_iterator::operator++).
All of the uses of this just traverse once over the path in one
direction or the other anyway.

llvm-svn: 214737
2014-08-04 17:36:41 +00:00
Justin Bogner 0c274aed23 unittests: Actually test reverse iterators in Path tests
This re-enables some #if 0'd code (since 2010) in the Path unittests
and makes at least a weak effort at testing sys::path's rbegin/rend.

This change was inspired by some test failures near uses of rbegin and
rend here:

    http://lab.llvm.org:8011/builders/clang-x86_64-linux-vg/builds/3209

The "valgrind was whining" comment looked promising in terms of a
simpler to debug case of the same errors. However, it appears that the
valgrind complaints the comment was referring to are distinct from the
ones in the frontend, since this updated test isn't complaining for me
under valgrind.

In any case, the disabled tests weren't helping anybody.

llvm-svn: 213125
2014-07-16 08:18:58 +00:00
Justin Bogner 759645ea89 Support: Fix option handling when using cl::Required with aliasopt
Until now, attempting to create an alias of a required option would
complain if the user supplied the alias, because the required option
didn't have a value. Similarly, if you said the alias was required,
then using the base option would complain that the alias wasn't
supplied. Lastly, if you put required on both, *neither* option would
work.

By changning alias to overload addOccurrence and setting cl::Required
on the original option, we can get this to behave in a more useful
way. I've also added a test and updated a user that was getting this
wrong.

llvm-svn: 212986
2014-07-14 20:53:57 +00:00
Alexey Samsonov b7dd329f2f Decouple llvm::SpecialCaseList text representation and its LLVM IR semantics.
Turn llvm::SpecialCaseList into a simple class that parses text files in
a specified format and knows nothing about LLVM IR. Move this class into
LLVMSupport library. Implement two users of this class:
  * DFSanABIList in DFSan instrumentation pass.
  * SanitizerBlacklist in Clang CodeGen library.
The latter will be modified to use actual source-level information from frontend
(source file names) instead of unstable LLVM IR things (LLVM Module identifier).

Remove dependency edge from ClangCodeGen/ClangDriver to LLVMTransformUtils.

No functionality change.

llvm-svn: 212643
2014-07-09 19:40:08 +00:00
Aaron Ballman 586ee604b5 These should be EXPECT_TRUE, not EXPECT_FALSE. Amends r212415.
llvm-svn: 212419
2014-07-06 20:20:02 +00:00
Aaron Ballman e56fe8af86 Fixing compile errors related to changes with MemoryBuffer::getFile.
llvm-svn: 212415
2014-07-06 19:34:52 +00:00
Rafael Espindola adf21f2a56 Update the MemoryBuffer API to use ErrorOr.
llvm-svn: 212405
2014-07-06 17:43:13 +00:00
Benjamin Kramer f2c4baf01b Remove unused typedef. GCC warns about this.
llvm-svn: 212105
2014-07-01 15:39:32 +00:00
Chandler Carruth 39cd216f8f Re-apply r211287: Remove support for LLVM runtime multi-threading.
I'll fix the problems in libclang and other projects in ways that don't
require <mutex> until we sort out the cygwin situation.

llvm-svn: 211900
2014-06-27 15:13:01 +00:00
NAKAMURA Takumi 104e5f67e2 Revert r211287, "Remove support for LLVM runtime multi-threading."
libclang still requires it on cygming, lack of incomplete <mutex>.

llvm-svn: 211592
2014-06-24 13:36:31 +00:00
Duncan P. N. Exon Smith 7ef44be792 Support: Return ScaledNumbers::MaxScale from getQuotient()
Return MaxScale now that it's available.

llvm-svn: 211559
2014-06-24 00:26:08 +00:00
Duncan P. N. Exon Smith eceabc1f7d Support: Extract ScaledNumbers::getSum() and getDifference()
llvm-svn: 211553
2014-06-23 23:15:25 +00:00
Duncan P. N. Exon Smith 68a5ef1a63 Support: Return scale from ScaledNumbers::matchScales()
This will be convenient when extracting `ScaledNumbers::getSum()`.

llvm-svn: 211552
2014-06-23 23:14:51 +00:00
Duncan P. N. Exon Smith aa908fc991 Support: Extract ScaledNumbers::matchScale()
llvm-svn: 211531
2014-06-23 20:40:45 +00:00
Duncan P. N. Exon Smith 820c3ab3d9 Cleanup r211507
llvm-svn: 211521
2014-06-23 18:08:58 +00:00
Duncan P. N. Exon Smith 0067ff4678 Support: Extract ScaledNumbers::compare()
llvm-svn: 211507
2014-06-23 17:47:40 +00:00
Duncan P. N. Exon Smith 03c2bfc2ef Support: ScaledNumber: Fix inconsistent test names
llvm-svn: 211414
2014-06-20 22:36:09 +00:00
Duncan P. N. Exon Smith 818a8176ea Support: Write ScaledNumbers::getLg{,Floor,Ceiling}()
llvm-svn: 211413
2014-06-20 22:33:40 +00:00
Duncan P. N. Exon Smith 411840d963 Support: Write ScaledNumber::getQuotient() and getProduct()
llvm-svn: 211409
2014-06-20 21:47:47 +00:00
Duncan P. N. Exon Smith d4ea631fec Support: Mark end of namespaces
This convinces clang-format to leave a newline.

llvm-svn: 211406
2014-06-20 21:43:20 +00:00
Duncan P. N. Exon Smith 2800a3770d Support: Clean up getRounded() tests
llvm-svn: 211337
2014-06-20 02:31:07 +00:00
Duncan P. N. Exon Smith e9e44cd189 Support: Write ScaledNumbers::getAdjusted()
llvm-svn: 211336
2014-06-20 02:31:03 +00:00
Duncan P. N. Exon Smith 9c62dd583b Support: Write ScaledNumbers::getRounded()
Start extracting helper functions out of -block-freq's `UnsignedFloat`
into `Support/ScaledNumber.h` with the eventual goal of moving and
renaming the class to `ScaledNumber`.

The bike shed about names is still being painted, but I'm going with
this for now.

llvm-svn: 211333
2014-06-20 01:30:43 +00:00
Zachary Turner 9c9710eaf4 Remove support for LLVM runtime multi-threading.
After a number of previous small iterations, the functions
llvm_start_multithreaded() and llvm_stop_multithreaded() have
been reduced essentially to no-ops.  This change removes them
entirely.

Reviewed by: rnk, dblaikie

Differential Revision: http://reviews.llvm.org/D4216

llvm-svn: 211287
2014-06-19 18:18:23 +00:00
Nikola Smiljanic 89e561a63e PR10140 - StringPool's PooledStringPtr has non-const operator== causing bad OR-result.
Mark conversion operator explicit and const qualify comparison operators.

llvm-svn: 211244
2014-06-19 00:26:49 +00:00