diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2015-04-08 08:55:49 -0700 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2015-04-09 15:04:38 -0700 |
commit | 4c5e43da7792f75567b693105cc53e3f1992ad98 (patch) | |
tree | 1b2c9792582e12f5af0b1512e3094425f0dc0df9 /lib/Support | |
parent | c75239e6119d0f9a74c57099d91cbc9bde56bf33 (diff) | |
download | external_llvm-4c5e43da7792f75567b693105cc53e3f1992ad98.zip external_llvm-4c5e43da7792f75567b693105cc53e3f1992ad98.tar.gz external_llvm-4c5e43da7792f75567b693105cc53e3f1992ad98.tar.bz2 |
Update aosp/master llvm for rebase to r233350
Change-Id: I07d935f8793ee8ec6b7da003f6483046594bca49
Diffstat (limited to 'lib/Support')
42 files changed, 345 insertions, 354 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index 393ecf4..5a402bb 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -1248,10 +1248,10 @@ APFloat::roundAwayFromZero(roundingMode rounding_mode, return false; case rmTowardPositive: - return sign == false; + return !sign; case rmTowardNegative: - return sign == true; + return sign; } llvm_unreachable("Invalid rounding mode found"); } @@ -1430,7 +1430,7 @@ APFloat::addOrSubtractSignificand(const APFloat &rhs, bool subtract) /* Determine if the operation on the absolute values is effectively an addition or subtraction. */ - subtract ^= (sign ^ rhs.sign) ? true : false; + subtract ^= static_cast<bool>(sign ^ rhs.sign); /* Are we bigger exponent-wise than the RHS? */ bits = exponent - rhs.exponent; diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 50a639c..2533fa0 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -672,6 +672,14 @@ hash_code llvm::hash_value(const APInt &Arg) { return hash_combine_range(Arg.pVal, Arg.pVal + Arg.getNumWords()); } +bool APInt::isSplat(unsigned SplatSizeInBits) const { + assert(getBitWidth() % SplatSizeInBits == 0 && + "SplatSizeInBits must divide width!"); + // We can check that all parts of an integer are equal by making use of a + // little trick: rotate and check if it's still the same value. + return *this == rotl(SplatSizeInBits); +} + /// HiBits - This function returns the high "numBits" bits of this APInt. APInt APInt::getHiBits(unsigned numBits) const { return APIntOps::lshr(*this, BitWidth - numBits); @@ -1310,13 +1318,8 @@ APInt APInt::sqrt() const { // libc sqrt function which will probably use a hardware sqrt computation. // This should be faster than the algorithm below. if (magnitude < 52) { -#if HAVE_ROUND return APInt(BitWidth, uint64_t(::round(::sqrt(double(isSingleWord()?VAL:pVal[0]))))); -#else - return APInt(BitWidth, - uint64_t(::sqrt(double(isSingleWord()?VAL:pVal[0])) + 0.5)); -#endif } // Okay, all the short cuts are exhausted. We must compute it. The following @@ -1508,21 +1511,18 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, assert(u && "Must provide dividend"); assert(v && "Must provide divisor"); assert(q && "Must provide quotient"); - assert(u != v && u != q && v != q && "Must us different memory"); + assert(u != v && u != q && v != q && "Must use different memory"); assert(n>1 && "n must be > 1"); - // Knuth uses the value b as the base of the number system. In our case b - // is 2^31 so we just set it to -1u. - uint64_t b = uint64_t(1) << 32; + // b denotes the base of the number system. In our case b is 2^32. + LLVM_CONSTEXPR uint64_t b = uint64_t(1) << 32; -#if 0 DEBUG(dbgs() << "KnuthDiv: m=" << m << " n=" << n << '\n'); DEBUG(dbgs() << "KnuthDiv: original:"); DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]); DEBUG(dbgs() << " by"); DEBUG(for (int i = n; i >0; i--) dbgs() << " " << v[i-1]); DEBUG(dbgs() << '\n'); -#endif // D1. [Normalize.] Set d = b / (v[n-1] + 1) and multiply all the digits of // u and v by d. Note that we have taken Knuth's advice here to use a power // of 2 value for d such that d * v[n-1] >= b/2 (b is the base). A power of @@ -1547,13 +1547,12 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, } } u[m+n] = u_carry; -#if 0 + DEBUG(dbgs() << "KnuthDiv: normal:"); DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]); DEBUG(dbgs() << " by"); DEBUG(for (int i = n; i >0; i--) dbgs() << " " << v[i-1]); DEBUG(dbgs() << '\n'); -#endif // D2. [Initialize j.] Set j to m. This is the loop counter over the places. int j = m; @@ -1583,46 +1582,35 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, // (u[j+n]u[j+n-1]..u[j]) - qp * (v[n-1]...v[1]v[0]). This computation // consists of a simple multiplication by a one-place number, combined with // a subtraction. + // The digits (u[j+n]...u[j]) should be kept positive; if the result of + // this step is actually negative, (u[j+n]...u[j]) should be left as the + // true value plus b**(n+1), namely as the b's complement of + // the true value, and a "borrow" to the left should be remembered. bool isNeg = false; for (unsigned i = 0; i < n; ++i) { - uint64_t u_tmp = uint64_t(u[j+i]) | (uint64_t(u[j+i+1]) << 32); + uint64_t u_tmp = (uint64_t(u[j+i+1]) << 32) | uint64_t(u[j+i]); uint64_t subtrahend = uint64_t(qp) * uint64_t(v[i]); bool borrow = subtrahend > u_tmp; - DEBUG(dbgs() << "KnuthDiv: u_tmp == " << u_tmp - << ", subtrahend == " << subtrahend + DEBUG(dbgs() << "KnuthDiv: u_tmp = " << u_tmp + << ", subtrahend = " << subtrahend << ", borrow = " << borrow << '\n'); uint64_t result = u_tmp - subtrahend; unsigned k = j + i; - u[k++] = (unsigned)(result & (b-1)); // subtract low word - u[k++] = (unsigned)(result >> 32); // subtract high word - while (borrow && k <= m+n) { // deal with borrow to the left + u[k++] = (unsigned)result; // subtraction low word + u[k++] = (unsigned)(result >> 32); // subtraction high word + while (borrow && k <= m+n) { // deal with borrow to the left borrow = u[k] == 0; u[k]--; k++; } isNeg |= borrow; - DEBUG(dbgs() << "KnuthDiv: u[j+i] == " << u[j+i] << ", u[j+i+1] == " << - u[j+i+1] << '\n'); + DEBUG(dbgs() << "KnuthDiv: u[j+i] = " << u[j+i] + << ", u[j+i+1] = " << u[j+i+1] << '\n'); } DEBUG(dbgs() << "KnuthDiv: after subtraction:"); DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]); DEBUG(dbgs() << '\n'); - // The digits (u[j+n]...u[j]) should be kept positive; if the result of - // this step is actually negative, (u[j+n]...u[j]) should be left as the - // true value plus b**(n+1), namely as the b's complement of - // the true value, and a "borrow" to the left should be remembered. - // - if (isNeg) { - bool carry = true; // true because b's complement is "complement + 1" - for (unsigned i = 0; i <= m+n; ++i) { - u[i] = ~u[i] + carry; // b's complement - carry = carry && u[i] == 0; - } - } - DEBUG(dbgs() << "KnuthDiv: after complement:"); - DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]); - DEBUG(dbgs() << '\n'); // D5. [Test remainder.] Set q[j] = qp. If the result of step D4 was // negative, go to step D6; otherwise go on to step D7. @@ -1644,7 +1632,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, u[j+n] += carry; } DEBUG(dbgs() << "KnuthDiv: after correction:"); - DEBUG(for (int i = m+n; i >=0; i--) dbgs() <<" " << u[i]); + DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]); DEBUG(dbgs() << "\nKnuthDiv: digit result = " << q[j] << '\n'); // D7. [Loop on j.] Decrease j by one. Now if j >= 0, go back to D3. @@ -1677,9 +1665,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, } DEBUG(dbgs() << '\n'); } -#if 0 DEBUG(dbgs() << '\n'); -#endif } void APInt::divide(const APInt LHS, unsigned lhsWords, @@ -1803,6 +1789,8 @@ void APInt::divide(const APInt LHS, unsigned lhsWords, // The quotient is in Q. Reconstitute the quotient into Quotient's low // order words. + // This case is currently dead as all users of divide() handle trivial cases + // earlier. if (lhsWords == 1) { uint64_t tmp = uint64_t(Q[0]) | (uint64_t(Q[1]) << (APINT_BITS_PER_WORD / 2)); @@ -2296,13 +2284,13 @@ void APInt::dump() const { this->toStringUnsigned(U); this->toStringSigned(S); dbgs() << "APInt(" << BitWidth << "b, " - << U.str() << "u " << S.str() << "s)"; + << U << "u " << S << "s)"; } void APInt::print(raw_ostream &OS, bool isSigned) const { SmallString<40> S; this->toString(S, 10, isSigned, /* formatAsCLiteral = */false); - OS << S.str(); + OS << S; } // This implements a variety of operations on a representation of diff --git a/lib/Support/Allocator.cpp b/lib/Support/Allocator.cpp index 7c306b2..f48edac 100644 --- a/lib/Support/Allocator.cpp +++ b/lib/Support/Allocator.cpp @@ -12,12 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Allocator.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/DataTypes.h" -#include "llvm/Support/Memory.h" -#include "llvm/Support/Recycler.h" #include "llvm/Support/raw_ostream.h" -#include <cstring> namespace llvm { diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk index 34448a7..4d1f526 100644 --- a/lib/Support/Android.mk +++ b/lib/Support/Android.mk @@ -35,8 +35,6 @@ support_SRC_FILES := \ IntervalMap.cpp \ IntEqClasses.cpp \ IntrusiveRefCntPtr.cpp \ - IsInf.cpp \ - IsNAN.cpp \ LEB128.cpp \ LineIterator.cpp \ Locale.cpp \ diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index a44c1a3..684afa9 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -58,8 +58,6 @@ add_llvm_library(LLVMSupport IntEqClasses.cpp IntervalMap.cpp IntrusiveRefCntPtr.cpp - IsInf.cpp - IsNAN.cpp LEB128.cpp LineIterator.cpp Locale.cpp diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index b49ec36..af6c605 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm-c/Support.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" @@ -32,10 +33,8 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <cerrno> #include <cstdlib> #include <map> -#include <system_error> using namespace llvm; using namespace cl; @@ -1463,10 +1462,9 @@ void basic_parser_impl::printOptionNoValue(const Option &O, // -help and -help-hidden option implementation // -static int OptNameCompare(const void *LHS, const void *RHS) { - typedef std::pair<const char *, Option *> pair_ty; - - return strcmp(((const pair_ty *)LHS)->first, ((const pair_ty *)RHS)->first); +static int OptNameCompare(const std::pair<const char *, Option *> *LHS, + const std::pair<const char *, Option *> *RHS) { + return strcmp(LHS->first, RHS->first); } // Copy Options into a vector so we can sort them as we like. @@ -1494,7 +1492,7 @@ static void sortOpts(StringMap<Option *> &OptMap, } // Sort the options list alphabetically. - qsort(Opts.data(), Opts.size(), sizeof(Opts[0]), OptNameCompare); + array_pod_sort(Opts.begin(), Opts.end(), OptNameCompare); } namespace { @@ -1516,7 +1514,7 @@ public: // Invoke the printer. void operator=(bool Value) { - if (Value == false) + if (!Value) return; StrOptionPairVector Opts; @@ -1562,10 +1560,11 @@ public: explicit CategorizedHelpPrinter(bool showHidden) : HelpPrinter(showHidden) {} // Helper function for printOptions(). - // It shall return true if A's name should be lexographically - // ordered before B's name. It returns false otherwise. - static bool OptionCategoryCompare(OptionCategory *A, OptionCategory *B) { - return strcmp(A->getName(), B->getName()) < 0; + // It shall return a negative value if A's name should be lexicographically + // ordered before B's name. It returns a value greater equal zero otherwise. + static int OptionCategoryCompare(OptionCategory *const *A, + OptionCategory *const *B) { + return strcmp((*A)->getName(), (*B)->getName()); } // Make sure we inherit our base class's operator=() @@ -1586,8 +1585,8 @@ protected: // Sort the different option categories alphabetically. assert(SortedCategories.size() > 0 && "No option categories registered!"); - std::sort(SortedCategories.begin(), SortedCategories.end(), - OptionCategoryCompare); + array_pod_sort(SortedCategories.begin(), SortedCategories.end(), + OptionCategoryCompare); // Create map to empty vectors. for (std::vector<OptionCategory *>::const_iterator @@ -1716,7 +1715,7 @@ static cl::opt<bool> PrintAllOptions( cl::init(false), cl::cat(GenericCategory)); void HelpPrinterWrapper::operator=(bool Value) { - if (Value == false) + if (!Value) return; // Decide which printer to invoke. If more than one option category is diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp index 17ae295..b54613e 100644 --- a/lib/Support/Compression.cpp +++ b/lib/Support/Compression.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Compression.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" #include "llvm/Support/Compiler.h" diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index 9b0e443..aba0f1d 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/lib/Support/CrashRecoveryContext.cpp @@ -8,13 +8,11 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/CrashRecoveryContext.h" -#include "llvm/ADT/SmallString.h" #include "llvm/Config/config.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/ThreadLocal.h" -#include <cstdio> #include <setjmp.h> using namespace llvm; diff --git a/lib/Support/DAGDeltaAlgorithm.cpp b/lib/Support/DAGDeltaAlgorithm.cpp index 0d504ee..f1a334b 100644 --- a/lib/Support/DAGDeltaAlgorithm.cpp +++ b/lib/Support/DAGDeltaAlgorithm.cpp @@ -63,9 +63,6 @@ private: DAGDeltaAlgorithm &DDA; - const changeset_ty &Changes; - const std::vector<edge_ty> &Dependencies; - std::vector<change_ty> Roots; /// Cache of failed test results. Successful test results are never cached @@ -139,9 +136,8 @@ private: } public: - DAGDeltaAlgorithmImpl(DAGDeltaAlgorithm &_DDA, - const changeset_ty &_Changes, - const std::vector<edge_ty> &_Dependencies); + DAGDeltaAlgorithmImpl(DAGDeltaAlgorithm &DDA, const changeset_ty &Changes, + const std::vector<edge_ty> &Dependencies); changeset_ty Run(); @@ -174,21 +170,17 @@ protected: } public: - DeltaActiveSetHelper(DAGDeltaAlgorithmImpl &_DDAI, - const changeset_ty &_Required) - : DDAI(_DDAI), Required(_Required) {} + DeltaActiveSetHelper(DAGDeltaAlgorithmImpl &DDAI, + const changeset_ty &Required) + : DDAI(DDAI), Required(Required) {} }; } -DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl(DAGDeltaAlgorithm &_DDA, - const changeset_ty &_Changes, - const std::vector<edge_ty> - &_Dependencies) - : DDA(_DDA), - Changes(_Changes), - Dependencies(_Dependencies) -{ +DAGDeltaAlgorithmImpl::DAGDeltaAlgorithmImpl( + DAGDeltaAlgorithm &DDA, const changeset_ty &Changes, + const std::vector<edge_ty> &Dependencies) + : DDA(DDA) { for (changeset_ty::const_iterator it = Changes.begin(), ie = Changes.end(); it != ie; ++it) { Predecessors.insert(std::make_pair(*it, std::vector<change_ty>())); diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index dbf6465..a44b958 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -18,8 +18,6 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" -#include <cerrno> -#include <cstdio> #include <string> #include <system_error> #if !defined(_MSC_VER) && !defined(__MINGW32__) diff --git a/lib/Support/Debug.cpp b/lib/Support/Debug.cpp index 9c58ae8..a88b18e 100644 --- a/lib/Support/Debug.cpp +++ b/lib/Support/Debug.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/circular_raw_ostream.h" +#include "llvm/Support/raw_ostream.h" #undef isCurrentDebugType #undef setCurrentDebugType diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index b176a8b..307ff09 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -11,11 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Errc.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/Support/FileOutputBuffer.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Errc.h" #include <system_error> #if !defined(_MSC_VER) && !defined(__MINGW32__) @@ -77,9 +76,16 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size, if (EC) return EC; +#ifndef LLVM_ON_WIN32 + // On Windows, CreateFileMapping (the mmap function on Windows) + // automatically extends the underlying file. We don't need to + // extend the file beforehand. _chsize (ftruncate on Windows) is + // pretty slow just like it writes specified amount of bytes, + // so we should avoid calling that. EC = sys::fs::resize_file(FD, Size); if (EC) return EC; +#endif auto MappedFile = llvm::make_unique<mapped_file_region>( FD, mapped_file_region::readwrite, Size, 0, EC); diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp index 4635114..80d2aef 100644 --- a/lib/Support/FoldingSet.cpp +++ b/lib/Support/FoldingSet.cpp @@ -101,6 +101,8 @@ void FoldingSetNodeID::AddString(StringRef String) { // Otherwise do it the hard way. // To be compatible with above bulk transfer, we need to take endianness // into account. + static_assert(sys::IsBigEndianHost || sys::IsLittleEndianHost, + "Unexpected host endianness"); if (sys::IsBigEndianHost) { for (Pos += 4; Pos <= Size; Pos += 4) { unsigned V = ((unsigned char)String[Pos - 4] << 24) | @@ -109,8 +111,7 @@ void FoldingSetNodeID::AddString(StringRef String) { (unsigned char)String[Pos - 1]; Bits.push_back(V); } - } else { - assert(sys::IsLittleEndianHost && "Unexpected host endianness"); + } else { // Little-endian host for (Pos += 4; Pos <= Size; Pos += 4) { unsigned V = ((unsigned char)String[Pos - 1] << 24) | ((unsigned char)String[Pos - 2] << 16) | @@ -222,6 +223,8 @@ static void **AllocateBuckets(unsigned NumBuckets) { //===----------------------------------------------------------------------===// // FoldingSetImpl Implementation +void FoldingSetImpl::anchor() {} + FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) { assert(5 < Log2InitSize && Log2InitSize < 32 && "Initial hash table size out of range"); diff --git a/lib/Support/FormattedStream.cpp b/lib/Support/FormattedStream.cpp index 618ec26..2ed71c7 100644 --- a/lib/Support/FormattedStream.cpp +++ b/lib/Support/FormattedStream.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> using namespace llvm; diff --git a/lib/Support/GraphWriter.cpp b/lib/Support/GraphWriter.cpp index 054df52..fd4ce54 100644 --- a/lib/Support/GraphWriter.cpp +++ b/lib/Support/GraphWriter.cpp @@ -15,7 +15,6 @@ #include "llvm/Config/config.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/Path.h" #include "llvm/Support/Program.h" using namespace llvm; @@ -98,6 +97,7 @@ static bool ExecGraphViewer(StringRef ExecPath, std::vector<const char *> &args, return false; } +namespace { struct GraphSession { std::string LogBuffer; bool TryFindProgram(StringRef Names, std::string &ProgramPath) { @@ -114,6 +114,7 @@ struct GraphSession { return false; } }; +} // namespace static const char *getProgramName(GraphProgram::Name program) { switch (program) { diff --git a/lib/Support/Host.cpp b/lib/Support/Host.cpp index 42bc342..0e9a62e 100644 --- a/lib/Support/Host.cpp +++ b/lib/Support/Host.cpp @@ -357,10 +357,16 @@ StringRef sys::getHostCPUName() { case 63: case 69: case 70: - // Not all Haswell processors support AVX too (such as the Pentium + // Not all Haswell processors support AVX2 (such as the Pentium // versions instead of the i7 versions). return HasAVX2 ? "core-avx2" : "corei7"; + // Broadwell: + case 61: + // Not all Broadwell processors support AVX2 (such as the Pentium + // versions instead of the i7 versions). + return HasAVX2 ? "broadwell" : "corei7"; + case 28: // Most 45 nm Intel Atom processors case 38: // 45 nm Atom Lincroft case 39: // 32 nm Atom Medfield diff --git a/lib/Support/IsInf.cpp b/lib/Support/IsInf.cpp deleted file mode 100644 index d6da0c9..0000000 --- a/lib/Support/IsInf.cpp +++ /dev/null @@ -1,49 +0,0 @@ -//===-- IsInf.cpp - Platform-independent wrapper around C99 isinf() -------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Platform-independent wrapper around C99 isinf() -// -//===----------------------------------------------------------------------===// - -#include "llvm/Config/config.h" - -#if HAVE_ISINF_IN_MATH_H -# include <math.h> -#elif HAVE_ISINF_IN_CMATH -# include <cmath> -#elif HAVE_STD_ISINF_IN_CMATH -# include <cmath> -using std::isinf; -#elif HAVE_FINITE_IN_IEEEFP_H -// A handy workaround I found at http://www.unixguide.net/sun/faq ... -// apparently this has been a problem with Solaris for years. -# include <ieeefp.h> -static int isinf(double x) { return !finite(x) && x==x; } -#elif defined(_MSC_VER) -#include <float.h> -#define isinf(X) (!_finite(X)) -#elif defined(_AIX) && defined(__GNUC__) -// GCC's fixincludes seems to be removing the isinf() declaration from the -// system header /usr/include/math.h -# include <math.h> -static int isinf(double x) { return !finite(x) && x==x; } -#elif defined(__hpux) -// HP-UX is "special" -#include <math.h> -static int isinf(double x) { return ((x) == INFINITY) || ((x) == -INFINITY); } -#else -# error "Don't know how to get isinf()" -#endif - -namespace llvm { - -int IsInf(float f) { return isinf(f); } -int IsInf(double d) { return isinf(d); } - -} // end namespace llvm; diff --git a/lib/Support/IsNAN.cpp b/lib/Support/IsNAN.cpp deleted file mode 100644 index bdfdfbf..0000000 --- a/lib/Support/IsNAN.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===-- IsNAN.cpp ---------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Platform-independent wrapper around C99 isnan(). -// -//===----------------------------------------------------------------------===// - -#include "llvm/Config/config.h" - -#if HAVE_ISNAN_IN_MATH_H -# include <math.h> -#elif HAVE_ISNAN_IN_CMATH -# include <cmath> -#elif HAVE_STD_ISNAN_IN_CMATH -# include <cmath> -using std::isnan; -#elif defined(_MSC_VER) -#include <float.h> -#define isnan _isnan -#else -# error "Don't know how to get isnan()" -#endif - -namespace llvm { - int IsNAN(float f) { return isnan(f); } - int IsNAN(double d) { return isnan(d); } -} // end namespace llvm; diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index ec3158c..d07c5f0 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -7,12 +7,10 @@ // //===----------------------------------------------------------------------===// #include "llvm/Support/LockFileManager.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Errc.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <sys/stat.h> #include <sys/types.h> @@ -91,7 +89,7 @@ LockFileManager::LockFileManager(StringRef FileName) UniqueLockFileName += "-%%%%%%%%"; int UniqueLockFileID; if (std::error_code EC = sys::fs::createUniqueFile( - UniqueLockFileName.str(), UniqueLockFileID, UniqueLockFileName)) { + UniqueLockFileName, UniqueLockFileID, UniqueLockFileName)) { Error = EC; return; } @@ -116,7 +114,7 @@ LockFileManager::LockFileManager(StringRef FileName) // We failed to write out PID, so make up an excuse, remove the // unique lock file, and fail. Error = make_error_code(errc::no_space_on_device); - sys::fs::remove(UniqueLockFileName.c_str()); + sys::fs::remove(UniqueLockFileName); return; } } @@ -124,7 +122,7 @@ LockFileManager::LockFileManager(StringRef FileName) while (1) { // Create a link from the lock file name. If this succeeds, we're done. std::error_code EC = - sys::fs::create_link(UniqueLockFileName.str(), LockFileName.str()); + sys::fs::create_link(UniqueLockFileName, LockFileName); if (!EC) return; @@ -137,11 +135,11 @@ LockFileManager::LockFileManager(StringRef FileName) // from the lock file. if ((Owner = readLockFile(LockFileName))) { // Wipe out our unique lock file (it's useless now) - sys::fs::remove(UniqueLockFileName.str()); + sys::fs::remove(UniqueLockFileName); return; } - if (!sys::fs::exists(LockFileName.str())) { + if (!sys::fs::exists(LockFileName)) { // The previous owner released the lock file before we could read it. // Try to get ownership again. continue; @@ -149,7 +147,7 @@ LockFileManager::LockFileManager(StringRef FileName) // There is a lock file that nobody owns; try to clean it up and get // ownership. - if ((EC = sys::fs::remove(LockFileName.str()))) { + if ((EC = sys::fs::remove(LockFileName))) { Error = EC; return; } @@ -171,8 +169,8 @@ LockFileManager::~LockFileManager() { return; // Since we own the lock, remove the lock file and our own unique lock file. - sys::fs::remove(LockFileName.str()); - sys::fs::remove(UniqueLockFileName.str()); + sys::fs::remove(LockFileName); + sys::fs::remove(UniqueLockFileName); } LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() { @@ -186,8 +184,9 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() { Interval.tv_sec = 0; Interval.tv_nsec = 1000000; #endif - // Don't wait more than one minute for the file to appear. - const unsigned MaxSeconds = 60; + // Don't wait more than five minutes per iteration. Total timeout for the file + // to appear is ~8.5 mins. + const unsigned MaxSeconds = 5*60; do { // Sleep for the designated interval, to allow the owning process time to // finish up and remove the lock file. @@ -202,7 +201,7 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() { if (sys::fs::access(LockFileName.c_str(), sys::fs::AccessMode::Exist) == errc::no_such_file_or_directory) { // If the original file wasn't created, somone thought the lock was dead. - if (!sys::fs::exists(FileName.str())) + if (!sys::fs::exists(FileName)) return Res_OwnerDied; return Res_Success; } @@ -235,5 +234,5 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() { } std::error_code LockFileManager::unsafeRemoveLockFile() { - return sys::fs::remove(LockFileName.str()); + return sys::fs::remove(LockFileName); } diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 379db88..98862e9 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -23,7 +23,6 @@ #include "llvm/Support/Program.h" #include <cassert> #include <cerrno> -#include <cstdio> #include <cstring> #include <new> #include <sys/types.h> diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index a11bb7f..cf467381 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -19,9 +19,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include <cctype> -#include <cstdio> #include <cstring> -#include <fcntl.h> #if !defined(_MSC_VER) && !defined(__MINGW32__) #include <unistd.h> @@ -30,6 +28,7 @@ #endif using namespace llvm; +using namespace llvm::support::endian; namespace { using llvm::StringRef; @@ -48,7 +47,6 @@ namespace { // * empty (in this case we return an empty string) // * either C: or {//,\\}net. // * {/,\} - // * {.,..} // * {file,directory}name if (path.empty()) @@ -75,12 +73,6 @@ namespace { if (is_separator(path[0])) return path.substr(0, 1); - if (path.startswith("..")) - return path.substr(0, 2); - - if (path[0] == '.') - return path.substr(0, 1); - // * {file,directory}name size_t end = path.find_first_of(separators); return path.substr(0, end); @@ -917,7 +909,7 @@ file_magic identify_magic(StringRef Magic) { if (Magic.size() < MinSize) return file_magic::coff_import_library; - int BigObjVersion = *reinterpret_cast<const support::ulittle16_t*>( + int BigObjVersion = read16le( Magic.data() + offsetof(COFF::BigObjHeader, Version)); if (BigObjVersion < COFF::BigObjHeader::MinBigObjectVersion) return file_magic::coff_import_library; @@ -1034,8 +1026,7 @@ file_magic identify_magic(StringRef Magic) { case 'M': // Possible MS-DOS stub on Windows PE file if (Magic[1] == 'Z') { - uint32_t off = - *reinterpret_cast<const support::ulittle32_t*>(Magic.data() + 0x3c); + uint32_t off = read32le(Magic.data() + 0x3c); // PE/COFF file, either EXE or DLL. if (off < Magic.size() && memcmp(Magic.data()+off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0) diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index ad67e1b..d0c1748 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -13,8 +13,8 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" diff --git a/lib/Support/Program.cpp b/lib/Support/Program.cpp index b84b82b..34e336b 100644 --- a/lib/Support/Program.cpp +++ b/lib/Support/Program.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Program.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" #include <system_error> using namespace llvm; diff --git a/lib/Support/RandomNumberGenerator.cpp b/lib/Support/RandomNumberGenerator.cpp index 2943137..81d0411 100644 --- a/lib/Support/RandomNumberGenerator.cpp +++ b/lib/Support/RandomNumberGenerator.cpp @@ -13,13 +13,15 @@ // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "rng" +#include "llvm/Support/RandomNumberGenerator.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/RandomNumberGenerator.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; +#define DEBUG_TYPE "rng" + // Tracking BUG: 19665 // http://llvm.org/bugs/show_bug.cgi?id=19665 // diff --git a/lib/Support/Regex.cpp b/lib/Support/Regex.cpp index f7fe1e4..d3e29ac 100644 --- a/lib/Support/Regex.cpp +++ b/lib/Support/Regex.cpp @@ -14,8 +14,7 @@ #include "llvm/Support/Regex.h" #include "regex_impl.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/ADT/StringRef.h" #include <string> using namespace llvm; diff --git a/lib/Support/ScaledNumber.cpp b/lib/Support/ScaledNumber.cpp index 6f6699c..987c2d8 100644 --- a/lib/Support/ScaledNumber.cpp +++ b/lib/Support/ScaledNumber.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/ScaledNumber.h" #include "llvm/ADT/APFloat.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace llvm::ScaledNumbers; diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index b50a66b..d5e3157 100644 --- a/lib/Support/SourceMgr.cpp +++ b/lib/Support/SourceMgr.cpp @@ -14,13 +14,11 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/SourceMgr.h" -#include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Locale.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <system_error> using namespace llvm; static const size_t TabStop = 8; diff --git a/lib/Support/SpecialCaseList.cpp b/lib/Support/SpecialCaseList.cpp index c312cc1..ea417c4 100644 --- a/lib/Support/SpecialCaseList.cpp +++ b/lib/Support/SpecialCaseList.cpp @@ -15,13 +15,11 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/SpecialCaseList.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Regex.h" -#include "llvm/Support/raw_ostream.h" #include <string> #include <system_error> #include <utility> diff --git a/lib/Support/StreamingMemoryObject.cpp b/lib/Support/StreamingMemoryObject.cpp index f39bc56..90f3ed8 100644 --- a/lib/Support/StreamingMemoryObject.cpp +++ b/lib/Support/StreamingMemoryObject.cpp @@ -8,12 +8,9 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/StreamingMemoryObject.h" -#include "llvm/Support/Compiler.h" #include <cassert> #include <cstddef> #include <cstring> - - using namespace llvm; namespace { diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp index d77ad7f..3e2420f 100644 --- a/lib/Support/StringExtras.cpp +++ b/lib/Support/StringExtras.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" using namespace llvm; diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp index 2036364..7fa6ae3 100644 --- a/lib/Support/SystemUtils.cpp +++ b/lib/Support/SystemUtils.cpp @@ -13,8 +13,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/SystemUtils.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp index f691883..3ca8572 100644 --- a/lib/Support/TargetRegistry.cpp +++ b/lib/Support/TargetRegistry.cpp @@ -10,7 +10,6 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/Host.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <vector> diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index e1a531a..d7b6515 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -14,12 +14,10 @@ #include "llvm/Support/Timer.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index e74b23c..d4b150a 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -141,6 +141,7 @@ const char *Triple::getOSTypeName(OSType Kind) { switch (Kind) { case UnknownOS: return "unknown"; + case CloudABI: return "cloudabi"; case Darwin: return "darwin"; case DragonFly: return "dragonfly"; case FreeBSD: return "freebsd"; @@ -280,6 +281,7 @@ static Triple::ArchType parseARMArch(StringRef ArchName) { .Cases("v7", "v7a", "v7em", "v7l", arch) .Cases("v7m", "v7r", "v7s", arch) .Cases("v8", "v8a", arch) + .Cases("v8.1", "v8.1a", arch) .Default(Triple::UnknownArch); } @@ -345,6 +347,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { static Triple::OSType parseOS(StringRef OSName) { return StringSwitch<Triple::OSType>(OSName) + .StartsWith("cloudabi", Triple::CloudABI) .StartsWith("darwin", Triple::Darwin) .StartsWith("dragonfly", Triple::DragonFly) .StartsWith("freebsd", Triple::FreeBSD) @@ -401,6 +404,7 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) { SubArchName = SubArchName.substr(0, SubArchName.size() - 2); return StringSwitch<Triple::SubArchType>(SubArchName) + .EndsWith("v8.1a", Triple::ARMSubArch_v8_1a) .EndsWith("v8", Triple::ARMSubArch_v8) .EndsWith("v8a", Triple::ARMSubArch_v8) .EndsWith("v7", Triple::ARMSubArch_v7) @@ -413,6 +417,7 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) { .EndsWith("v6", Triple::ARMSubArch_v6) .EndsWith("v6m", Triple::ARMSubArch_v6m) .EndsWith("v6sm", Triple::ARMSubArch_v6m) + .EndsWith("v6k", Triple::ARMSubArch_v6k) .EndsWith("v6t2", Triple::ARMSubArch_v6t2) .EndsWith("v5", Triple::ARMSubArch_v5) .EndsWith("v5e", Triple::ARMSubArch_v5) @@ -436,6 +441,30 @@ static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) { } static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { + switch (T.getArch()) { + default: + break; + case Triple::hexagon: + case Triple::mips: + case Triple::mipsel: + case Triple::mips64: + case Triple::mips64el: + case Triple::r600: + case Triple::amdgcn: + case Triple::sparc: + case Triple::sparcv9: + case Triple::systemz: + case Triple::xcore: + case Triple::ppc64le: + return Triple::ELF; + + case Triple::ppc: + case Triple::ppc64: + if (T.isOSDarwin()) + return Triple::MachO; + return Triple::ELF; + } + if (T.isOSDarwin()) return Triple::MachO; else if (T.isOSWindows()) @@ -714,6 +743,14 @@ void Triple::getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const { StringRef OSName = getOSName(); + // For Android, we care about the Android version rather than the Linux + // version. + if (getEnvironment() == Android) { + OSName = getEnvironmentName().substr(strlen("android")); + if (OSName.startswith("eabi")) + OSName = OSName.substr(strlen("eabi")); + } + // Assume that the OS portion of the triple starts with the canonical name. StringRef OSTypeName = getOSTypeName(getOS()); if (OSName.startswith(OSTypeName)) @@ -839,7 +876,7 @@ void Triple::setArchName(StringRef Str) { Triple += getVendorName(); Triple += "-"; Triple += getOSAndEnvironmentName(); - setTriple(Triple.str()); + setTriple(Triple); } void Triple::setVendorName(StringRef Str) { @@ -1063,9 +1100,9 @@ const char *Triple::getARMCPUForArch(StringRef MArch) const { .Cases("v5", "v5t", "arm10tdmi") .Cases("v5e", "v5te", "arm1022e") .Case("v5tej", "arm926ej-s") - .Cases("v6", "v6k", "arm1136jf-s") + .Case("v6", "arm1136jf-s") .Case("v6j", "arm1136j-s") - .Cases("v6z", "v6zk", "arm1176jzf-s") + .Cases("v6k", "v6z", "v6zk", "arm1176jzf-s") .Case("v6t2", "arm1156t2-s") .Cases("v6m", "v6-m", "v6sm", "v6s-m", "cortex-m0") .Cases("v7", "v7a", "v7-a", "v7l", "v7-l", "cortex-a8") @@ -1074,6 +1111,7 @@ const char *Triple::getARMCPUForArch(StringRef MArch) const { .Cases("v7m", "v7-m", "cortex-m3") .Cases("v7em", "v7e-m", "cortex-m4") .Cases("v8", "v8a", "v8-a", "cortex-a53") + .Cases("v8.1a", "v8.1-a", "generic-armv8.1-a") .Default(nullptr); else result = llvm::StringSwitch<const char *>(MArch) @@ -1099,6 +1137,8 @@ const char *Triple::getARMCPUForArch(StringRef MArch) const { default: return "strongarm"; } + case llvm::Triple::NaCl: + return "cortex-a8"; default: switch (getEnvironment()) { case llvm::Triple::EABIHF: diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 56ed964..d2cc75b 100644 --- a/lib/Support/Twine.cpp +++ b/lib/Support/Twine.cpp @@ -28,13 +28,6 @@ void Twine::toVector(SmallVectorImpl<char> &Out) const { print(OS); } -StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const { - if (isSingleStringRef()) - return getSingleStringRef(); - toVector(Out); - return StringRef(Out.data(), Out.size()); -} - StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const { if (isUnary()) { switch (getLHSKind()) { @@ -72,6 +65,9 @@ void Twine::printOneChild(raw_ostream &OS, Child Ptr, case Twine::StringRefKind: OS << *Ptr.stringRef; break; + case Twine::SmallStringKind: + OS << *Ptr.smallString; + break; case Twine::CharKind: OS << Ptr.character; break; @@ -122,6 +118,10 @@ void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr, OS << "stringref:\"" << Ptr.stringRef << "\""; break; + case Twine::SmallStringKind:
+ OS << "smallstring:\""
+ << *Ptr.smallString << "\"";
+ break;
case Twine::CharKind: OS << "char:\"" << Ptr.character << "\""; break; diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc index baf2767..5816fb8 100644 --- a/lib/Support/Unix/Program.inc +++ b/lib/Support/Unix/Program.inc @@ -18,10 +18,11 @@ #include "Unix.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Config/config.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <llvm/Config/config.h> #if HAVE_SYS_STAT_H #include <sys/stat.h> #endif diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 665c7de..a9b48e0 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -14,6 +14,7 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Format.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/ManagedStatic.h" @@ -324,7 +325,8 @@ static bool findModulesAndOffsets(void **StackTrace, int Depth, } #endif -static bool printSymbolizedStackTrace(void **StackTrace, int Depth, FILE *FD) { +static bool printSymbolizedStackTrace(void **StackTrace, int Depth, + llvm::raw_ostream &OS) { // FIXME: Subtract necessary number from StackTrace entries to turn return addresses // into actual instruction addresses. // Use llvm-symbolizer tool to symbolize the stack traces. @@ -382,7 +384,7 @@ static bool printSymbolizedStackTrace(void **StackTrace, int Depth, FILE *FD) { int frame_no = 0; for (int i = 0; i < Depth; i++) { if (!Modules[i]) { - fprintf(FD, "#%d %p\n", frame_no++, StackTrace[i]); + OS << format("#%d %p\n", frame_no++, StackTrace[i]); continue; } // Read pairs of lines (function name and file/line info) until we @@ -393,17 +395,17 @@ static bool printSymbolizedStackTrace(void **StackTrace, int Depth, FILE *FD) { StringRef FunctionName = *CurLine++; if (FunctionName.empty()) break; - fprintf(FD, "#%d %p ", frame_no++, StackTrace[i]); + OS << format("#%d %p ", frame_no++, StackTrace[i]); if (!FunctionName.startswith("??")) - fprintf(FD, "%s ", FunctionName.str().c_str()); + OS << format("%s ", FunctionName.str().c_str()); if (CurLine == Lines.end()) return false; StringRef FileLineInfo = *CurLine++; if (!FileLineInfo.startswith("??")) - fprintf(FD, "%s", FileLineInfo.str().c_str()); + OS << format("%s", FileLineInfo.str().c_str()); else - fprintf(FD, "(%s+%p)", Modules[i], (void *)Offsets[i]); - fprintf(FD, "\n"); + OS << format("(%s+%p)", Modules[i], (void *)Offsets[i]); + OS << "\n"; } } return true; @@ -415,13 +417,13 @@ static bool printSymbolizedStackTrace(void **StackTrace, int Depth, FILE *FD) { // // On glibc systems we have the 'backtrace' function, which works nicely, but // doesn't demangle symbols. -void llvm::sys::PrintStackTrace(FILE *FD) { +void llvm::sys::PrintStackTrace(raw_ostream &OS) { #if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) static void* StackTrace[256]; // Use backtrace() to output a backtrace on Linux systems with glibc. int depth = backtrace(StackTrace, static_cast<int>(array_lengthof(StackTrace))); - if (printSymbolizedStackTrace(StackTrace, depth, FD)) + if (printSymbolizedStackTrace(StackTrace, depth, OS)) return; #if HAVE_DLFCN_H && __GNUG__ int width = 0; @@ -441,34 +443,34 @@ void llvm::sys::PrintStackTrace(FILE *FD) { Dl_info dlinfo; dladdr(StackTrace[i], &dlinfo); - fprintf(FD, "%-2d", i); + OS << format("%-2d", i); const char* name = strrchr(dlinfo.dli_fname, '/'); - if (!name) fprintf(FD, " %-*s", width, dlinfo.dli_fname); - else fprintf(FD, " %-*s", width, name+1); + if (!name) OS << format(" %-*s", width, dlinfo.dli_fname); + else OS << format(" %-*s", width, name+1); - fprintf(FD, " %#0*lx", - (int)(sizeof(void*) * 2) + 2, (unsigned long)StackTrace[i]); + OS << format(" %#0*lx", (int)(sizeof(void*) * 2) + 2, + (unsigned long)StackTrace[i]); if (dlinfo.dli_sname != nullptr) { - fputc(' ', FD); + OS << ' '; # if HAVE_CXXABI_H int res; char* d = abi::__cxa_demangle(dlinfo.dli_sname, nullptr, nullptr, &res); # else char* d = NULL; # endif - if (!d) fputs(dlinfo.dli_sname, FD); - else fputs(d, FD); + if (!d) OS << dlinfo.dli_sname; + else OS << d; free(d); // FIXME: When we move to C++11, use %t length modifier. It's not in // C++03 and causes gcc to issue warnings. Losing the upper 32 bits of // the stack offset for a stack dump isn't likely to cause any problems. - fprintf(FD, " + %u",(unsigned)((char*)StackTrace[i]- - (char*)dlinfo.dli_saddr)); + OS << format(" + %u",(unsigned)((char*)StackTrace[i]- + (char*)dlinfo.dli_saddr)); } - fputc('\n', FD); + OS << '\n'; } #else backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO); @@ -477,7 +479,7 @@ void llvm::sys::PrintStackTrace(FILE *FD) { } static void PrintStackTraceSignalHandler(void *) { - PrintStackTrace(stderr); + PrintStackTrace(llvm::errs()); } void llvm::sys::DisableSystemDialogsOnCrash() {} diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index d8b5702..d558ff5 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -599,8 +599,8 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &it, it.IterationHandle = intptr_t(FindHandle.take()); SmallString<128> directory_entry_path(path); - path::append(directory_entry_path, directory_entry_name_utf8.str()); - it.CurrentEntry = directory_entry(directory_entry_path.str()); + path::append(directory_entry_path, directory_entry_name_utf8); + it.CurrentEntry = directory_entry(directory_entry_path); return std::error_code(); } diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index 854eac7..5f9ce7f 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -329,6 +329,16 @@ class DefaultColors }; DefaultColors defaultColors; + +WORD fg_color(WORD color) { + return color & (FOREGROUND_BLUE | FOREGROUND_GREEN | + FOREGROUND_INTENSITY | FOREGROUND_RED); +} + +WORD bg_color(WORD color) { + return color & (BACKGROUND_BLUE | BACKGROUND_GREEN | + BACKGROUND_INTENSITY | BACKGROUND_RED); +} } bool Process::ColorNeedsFlush() { @@ -350,6 +360,7 @@ const char *Process::OutputBold(bool bg) { const char *Process::OutputColor(char code, bool bold, bool bg) { if (UseANSI) return colorcodes[bg?1:0][bold?1:0][code&7]; + WORD current = DefaultColors::GetCurrentColor(); WORD colors; if (bg) { colors = ((code&1) ? BACKGROUND_RED : 0) | @@ -357,12 +368,14 @@ const char *Process::OutputColor(char code, bool bold, bool bg) { ((code&4) ? BACKGROUND_BLUE : 0); if (bold) colors |= BACKGROUND_INTENSITY; + colors |= fg_color(current); } else { colors = ((code&1) ? FOREGROUND_RED : 0) | ((code&2) ? FOREGROUND_GREEN : 0 ) | ((code&4) ? FOREGROUND_BLUE : 0); if (bold) colors |= FOREGROUND_INTENSITY; + colors |= bg_color(current); } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors); return 0; diff --git a/lib/Support/Windows/Signals.inc b/lib/Support/Windows/Signals.inc index aa1aa72..de6bf1c 100644 --- a/lib/Support/Windows/Signals.inc +++ b/lib/Support/Windows/Signals.inc @@ -10,13 +10,15 @@ // This file provides the Win32 specific implementation of the Signals class. // //===----------------------------------------------------------------------===// - #include "llvm/Support/FileSystem.h" #include <algorithm> #include <signal.h> #include <stdio.h> #include <vector> +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" + // The Windows.h header must be after LLVM and standard headers. #include "WindowsSupport.h" @@ -172,6 +174,92 @@ static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL; // (such as CTRL/C) occurs. This causes concurrency issues with the above // globals which this critical section addresses. static CRITICAL_SECTION CriticalSection; +static bool CriticalSectionInitialized = false; + +static void PrintStackTraceForThread(llvm::raw_ostream &OS, HANDLE hProcess, + HANDLE hThread, STACKFRAME64 &StackFrame, + CONTEXT *Context) { + DWORD machineType; +#if defined(_M_X64) + machineType = IMAGE_FILE_MACHINE_AMD64; +#else + machineType = IMAGE_FILE_MACHINE_I386; +#endif + + // Initialize the symbol handler. + SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES); + SymInitialize(hProcess, NULL, TRUE); + + while (true) { + if (!StackWalk64(machineType, hProcess, hThread, &StackFrame, Context, NULL, + SymFunctionTableAccess64, SymGetModuleBase64, NULL)) { + break; + } + + if (StackFrame.AddrFrame.Offset == 0) + break; + + using namespace llvm; + // Print the PC in hexadecimal. + DWORD64 PC = StackFrame.AddrPC.Offset; +#if defined(_M_X64) + OS << format("0x%016llX", PC); +#elif defined(_M_IX86) + OS << format("0x%08lX", static_cast<DWORD>(PC)); +#endif + +// Print the parameters. Assume there are four. +#if defined(_M_X64) + OS << format(" (0x%016llX 0x%016llX 0x%016llX 0x%016llX)", + StackFrame.Params[0], StackFrame.Params[1], StackFrame.Params[2], + StackFrame.Params[3]); +#elif defined(_M_IX86) + OS << format(" (0x%08lX 0x%08lX 0x%08lX 0x%08lX)", + static_cast<DWORD>(StackFrame.Params[0]), + static_cast<DWORD>(StackFrame.Params[1]), + static_cast<DWORD>(StackFrame.Params[2]), + static_cast<DWORD>(StackFrame.Params[3])); +#endif + // Verify the PC belongs to a module in this process. + if (!SymGetModuleBase64(hProcess, PC)) { + OS << " <unknown module>\n"; + continue; + } + + // Print the symbol name. + char buffer[512]; + IMAGEHLP_SYMBOL64 *symbol = reinterpret_cast<IMAGEHLP_SYMBOL64 *>(buffer); + memset(symbol, 0, sizeof(IMAGEHLP_SYMBOL64)); + symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); + symbol->MaxNameLength = 512 - sizeof(IMAGEHLP_SYMBOL64); + + DWORD64 dwDisp; + if (!SymGetSymFromAddr64(hProcess, PC, &dwDisp, symbol)) { + OS << '\n'; + continue; + } + + buffer[511] = 0; + if (dwDisp > 0) + OS << format(", %s() + 0x%llX bytes(s)", (const char*)symbol->Name, + dwDisp); + else + OS << format(", %s", (const char*)symbol->Name); + + // Print the source file and line number information. + IMAGEHLP_LINE64 line; + DWORD dwLineDisp; + memset(&line, 0, sizeof(line)); + line.SizeOfStruct = sizeof(line); + if (SymGetLineFromAddr64(hProcess, PC, &dwLineDisp, &line)) { + OS << format(", %s, line %lu", line.FileName, line.LineNumber); + if (dwLineDisp > 0) + OS << format(" + 0x%lX byte(s)", dwLineDisp); + } + + OS << '\n'; + } +} namespace llvm { @@ -203,6 +291,16 @@ extern "C" void HandleAbort(int Sig) { } } +static void InitializeThreading() { + if (CriticalSectionInitialized) + return; + + // Now's the time to create the critical section. This is the first time + // through here, and there's only one thread. + InitializeCriticalSection(&CriticalSection); + CriticalSectionInitialized = true; +} + static void RegisterHandler() { #if __MINGW32__ && !defined(__MINGW64_VERSION_MAJOR) // On MinGW.org, we need to load up the symbols explicitly, because the @@ -221,9 +319,7 @@ static void RegisterHandler() { return; } - // Now's the time to create the critical section. This is the first time - // through here, and there's only one thread. - InitializeCriticalSection(&CriticalSection); + InitializeThreading(); // Enter it immediately. Now if someone hits CTRL/C, the console handler // can't proceed until the globals are updated. @@ -298,13 +394,37 @@ void sys::PrintStackTraceOnErrorSignal() { RegisterHandler(); LeaveCriticalSection(&CriticalSection); } +} + +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +// Provide a prototype for RtlCaptureContext, mingw32 from mingw.org is +// missing it but mingw-w64 has it. +extern "C" VOID WINAPI RtlCaptureContext(PCONTEXT ContextRecord); +#endif -void llvm::sys::PrintStackTrace(FILE *) { - // FIXME: Implement. +void llvm::sys::PrintStackTrace(raw_ostream &OS) { + + STACKFRAME64 StackFrame = {}; + CONTEXT Context = {0}; + ::RtlCaptureContext(&Context); +#if defined(_M_X64) + StackFrame.AddrPC.Offset = Context.Rip; + StackFrame.AddrStack.Offset = Context.Rsp; + StackFrame.AddrFrame.Offset = Context.Rbp; +#else + StackFrame.AddrPC.Offset = Context.Eip; + StackFrame.AddrStack.Offset = Context.Esp; + StackFrame.AddrFrame.Offset = Context.Ebp; +#endif + StackFrame.AddrPC.Mode = AddrModeFlat; + StackFrame.AddrStack.Mode = AddrModeFlat; + StackFrame.AddrFrame.Mode = AddrModeFlat; + PrintStackTraceForThread(OS, GetCurrentProcess(), GetCurrentThread(), + StackFrame, &Context); } -void sys::SetInterruptFunction(void (*IF)()) { +void llvm::sys::SetInterruptFunction(void (*IF)()) { RegisterHandler(); InterruptFunction = IF; LeaveCriticalSection(&CriticalSection); @@ -314,14 +434,13 @@ void sys::SetInterruptFunction(void (*IF)()) { /// AddSignalHandler - Add a function to be called when a signal is delivered /// to the process. The handler can have a cookie passed to it to identify /// what instance of the handler it is. -void sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { +void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { if (CallBacksToRun == 0) CallBacksToRun = new std::vector<std::pair<void(*)(void*), void*> >(); CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie)); RegisterHandler(); LeaveCriticalSection(&CriticalSection); } -} static void Cleanup() { EnterCriticalSection(&CriticalSection); @@ -346,6 +465,11 @@ static void Cleanup() { } void llvm::sys::RunInterruptHandlers() { + // The interrupt handler may be called from an interrupt, but it may also be + // called manually (such as the case of report_fatal_error with no registered + // error handler). We must ensure that the critical section is properly + // initialized. + InitializeThreading(); Cleanup(); } @@ -356,9 +480,7 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { STACKFRAME64 StackFrame; memset(&StackFrame, 0, sizeof(StackFrame)); - DWORD machineType; #if defined(_M_X64) - machineType = IMAGE_FILE_MACHINE_AMD64; StackFrame.AddrPC.Offset = ep->ContextRecord->Rip; StackFrame.AddrPC.Mode = AddrModeFlat; StackFrame.AddrStack.Offset = ep->ContextRecord->Rsp; @@ -366,7 +488,6 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { StackFrame.AddrFrame.Offset = ep->ContextRecord->Rbp; StackFrame.AddrFrame.Mode = AddrModeFlat; #elif defined(_M_IX86) - machineType = IMAGE_FILE_MACHINE_I386; StackFrame.AddrPC.Offset = ep->ContextRecord->Eip; StackFrame.AddrPC.Mode = AddrModeFlat; StackFrame.AddrStack.Offset = ep->ContextRecord->Esp; @@ -377,81 +498,8 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { HANDLE hProcess = GetCurrentProcess(); HANDLE hThread = GetCurrentThread(); - - // Initialize the symbol handler. - SymSetOptions(SYMOPT_DEFERRED_LOADS|SYMOPT_LOAD_LINES); - SymInitialize(hProcess, NULL, TRUE); - - while (true) { - if (!StackWalk64(machineType, hProcess, hThread, &StackFrame, - ep->ContextRecord, NULL, SymFunctionTableAccess64, - SymGetModuleBase64, NULL)) { - break; - } - - if (StackFrame.AddrFrame.Offset == 0) - break; - - // Print the PC in hexadecimal. - DWORD64 PC = StackFrame.AddrPC.Offset; -#if defined(_M_X64) - fprintf(stderr, "0x%016llX", PC); -#elif defined(_M_IX86) - fprintf(stderr, "0x%08lX", static_cast<DWORD>(PC)); -#endif - - // Print the parameters. Assume there are four. -#if defined(_M_X64) - fprintf(stderr, " (0x%016llX 0x%016llX 0x%016llX 0x%016llX)", - StackFrame.Params[0], - StackFrame.Params[1], - StackFrame.Params[2], - StackFrame.Params[3]); -#elif defined(_M_IX86) - fprintf(stderr, " (0x%08lX 0x%08lX 0x%08lX 0x%08lX)", - static_cast<DWORD>(StackFrame.Params[0]), - static_cast<DWORD>(StackFrame.Params[1]), - static_cast<DWORD>(StackFrame.Params[2]), - static_cast<DWORD>(StackFrame.Params[3])); -#endif - // Verify the PC belongs to a module in this process. - if (!SymGetModuleBase64(hProcess, PC)) { - fputs(" <unknown module>\n", stderr); - continue; - } - - // Print the symbol name. - char buffer[512]; - IMAGEHLP_SYMBOL64 *symbol = reinterpret_cast<IMAGEHLP_SYMBOL64 *>(buffer); - memset(symbol, 0, sizeof(IMAGEHLP_SYMBOL64)); - symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - symbol->MaxNameLength = 512 - sizeof(IMAGEHLP_SYMBOL64); - - DWORD64 dwDisp; - if (!SymGetSymFromAddr64(hProcess, PC, &dwDisp, symbol)) { - fputc('\n', stderr); - continue; - } - - buffer[511] = 0; - if (dwDisp > 0) - fprintf(stderr, ", %s() + 0x%llX bytes(s)", symbol->Name, dwDisp); - else - fprintf(stderr, ", %s", symbol->Name); - - // Print the source file and line number information. - IMAGEHLP_LINE64 line; - DWORD dwLineDisp; - memset(&line, 0, sizeof(line)); - line.SizeOfStruct = sizeof(line); - if (SymGetLineFromAddr64(hProcess, PC, &dwLineDisp, &line)) { - fprintf(stderr, ", %s, line %lu", line.FileName, line.LineNumber); - if (dwLineDisp > 0) - fprintf(stderr, " + 0x%lX byte(s)", dwLineDisp); - } - - fputc('\n', stderr); - } + PrintStackTraceForThread(llvm::errs(), hProcess, hThread, StackFrame, + ep->ContextRecord); _exit(ep->ExceptionRecord->ExceptionCode); } diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp index 6ae7945..93aec7c 100644 --- a/lib/Support/YAMLParser.cpp +++ b/lib/Support/YAMLParser.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/YAMLParser.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index 43a0e10..74e5414 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -7,13 +7,14 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Errc.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/YAMLParser.h" -#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include <cctype> #include <cstring> @@ -168,9 +169,17 @@ void Input::endMapping() { } unsigned Input::beginSequence() { - if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { + if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) return SQ->Entries.size(); + if (isa<EmptyHNode>(CurrentNode)) + return 0; + // Treat case where there's a scalar "null" value as an empty sequence. + if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) { + if (isNull(SN->value())) + return 0; } + // Any other type of HNode is an error. + setError(CurrentNode, "not a sequence"); return 0; } @@ -192,12 +201,7 @@ void Input::postflightElement(void *SaveInfo) { CurrentNode = reinterpret_cast<HNode *>(SaveInfo); } -unsigned Input::beginFlowSequence() { - if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { - return SQ->Entries.size(); - } - return 0; -} +unsigned Input::beginFlowSequence() { return beginSequence(); } bool Input::preflightFlowElement(unsigned index, void *&SaveInfo) { if (EC) |