Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -26,6 +26,7 @@ #include "clang/Driver/XRayArgs.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/llvm-config.h" Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -18,42 +18,43 @@ #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/MultilibBuilder.h" #include "clang/Driver/Options.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include using namespace llvm::opt; using namespace clang; using namespace clang::driver; using namespace clang::driver::tools; using namespace clang::driver::toolchains; static bool findRISCVMultilibs(const Driver &D, const llvm::Triple &TargetTriple, const ArgList &Args, DetectedMultilibs &Result) { Multilib::flags_list Flags; StringRef Arch = riscv::getRISCVArch(Args, TargetTriple); StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple); if (TargetTriple.isRISCV64()) { MultilibBuilder Imac = MultilibBuilder().flag("-march=rv64imac").flag("-mabi=lp64"); MultilibBuilder Imafdc = MultilibBuilder("/rv64imafdc/lp64d") .flag("-march=rv64imafdc") .flag("-mabi=lp64d"); // Multilib reuse bool UseImafdc = (Arch == "rv64imafdc") || (Arch == "rv64gc"); // gc => imafdc addMultilibFlag((Arch == "rv64imac"), "-march=rv64imac", Flags); addMultilibFlag(UseImafdc, "-march=rv64imafdc", Flags); addMultilibFlag(Abi == "lp64", "-mabi=lp64", Flags); addMultilibFlag(Abi == "lp64d", "-mabi=lp64d", Flags); Result.Multilibs = MultilibSetBuilder().Either(Imac, Imafdc).makeMultilibSet(); return Result.Multilibs.select(Flags, Result.SelectedMultilibs); Index: llvm/include/llvm/Support/Error.h =================================================================== --- llvm/include/llvm/Support/Error.h +++ llvm/include/llvm/Support/Error.h @@ -14,8 +14,6 @@ #define LLVM_SUPPORT_ERROR_H #include "llvm-c/Error.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/abi-breaking.h" #include "llvm/Support/AlignOf.h" @@ -1025,14 +1023,8 @@ /// Write all error messages (if any) in E to a string. The newline character /// is used to separate error messages. -inline std::string toString(Error E) { - SmallVector Errors; - handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { - Errors.push_back(EI.message()); - }); - return join(Errors.begin(), Errors.end(), "\n"); -} +std::string toString(Error E); /// Consume a Error without doing anything. This method should be used /// only where an error can be considered a reasonable and expected return /// value. Index: llvm/lib/Analysis/VectorUtils.cpp =================================================================== --- llvm/lib/Analysis/VectorUtils.cpp +++ llvm/lib/Analysis/VectorUtils.cpp @@ -12,6 +12,7 @@ #include "llvm/Analysis/VectorUtils.h" #include "llvm/ADT/EquivalenceClasses.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Analysis/DemandedBits.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopIterator.h" Index: llvm/lib/Support/Error.cpp =================================================================== --- llvm/lib/Support/Error.cpp +++ llvm/lib/Support/Error.cpp @@ -7,27 +7,29 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Error.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorHandling.h" #include using namespace llvm; namespace { enum class ErrorErrorCode : int { MultipleErrors = 1, FileError, InconvertibleError }; // FIXME: This class is only here to support the transition to llvm::Error. It // will be removed once this transition is complete. Clients should prefer to // deal with the Error value directly, rather than converting to error_code. class ErrorErrorCategory : public std::error_category { public: const char *name() const noexcept override { return "Error"; } std::string message(int condition) const override { switch (static_cast(condition)) { case ErrorErrorCode::MultipleErrors: @@ -70,17 +72,26 @@ }); } +/// Write all error messages (if any) in E to a string. The newline character +/// is used to separate error messages. +std::string toString(Error E) { + SmallVector Errors; + handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { + Errors.push_back(EI.message()); + }); + return join(Errors.begin(), Errors.end(), "\n"); +} std::error_code ErrorList::convertToErrorCode() const { return std::error_code(static_cast(ErrorErrorCode::MultipleErrors), getErrorErrorCat()); } std::error_code inconvertibleErrorCode() { return std::error_code(static_cast(ErrorErrorCode::InconvertibleError), getErrorErrorCat()); } std::error_code FileError::convertToErrorCode() const { std::error_code NestedEC = Err->convertToErrorCode(); if (NestedEC == inconvertibleErrorCode()) Index: llvm/lib/Transforms/IPO/Internalize.cpp =================================================================== --- llvm/lib/Transforms/IPO/Internalize.cpp +++ llvm/lib/Transforms/IPO/Internalize.cpp @@ -19,6 +19,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/IPO/Internalize.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringSet.h" #include "llvm/Analysis/CallGraph.h" Index: llvm/lib/Transforms/Scalar/MergeICmps.cpp =================================================================== --- llvm/lib/Transforms/Scalar/MergeICmps.cpp +++ llvm/lib/Transforms/Scalar/MergeICmps.cpp @@ -42,6 +42,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar/MergeICmps.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/Loads.h" Index: llvm/lib/Transforms/Utils/MemoryOpRemark.cpp =================================================================== --- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ llvm/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -11,22 +11,23 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/MemoryOpRemark.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include using namespace llvm; using namespace llvm::ore; MemoryOpRemark::~MemoryOpRemark() = default; bool MemoryOpRemark::canHandle(const Instruction *I, const TargetLibraryInfo &TLI) { if (isa(I)) return true; if (auto *II = dyn_cast(I)) { switch (II->getIntrinsicID()) { case Intrinsic::memcpy_inline: Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -12,6 +12,7 @@ #include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Analysis/VectorUtils.h" +#include "llvm/ADT/SmallString.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" @@ -19,15 +20,16 @@ #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/xxhash.h" + using namespace llvm; #define DEBUG_TYPE "moduleutils" static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F, int Priority, Constant *Data) { IRBuilder<> IRB(M.getContext()); FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false); // Get the current set of static global constructors and add the new ctor // to the list. SmallVector CurrentCtors; Index: llvm/tools/llvm-objdump/XCOFFDump.cpp =================================================================== --- llvm/tools/llvm-objdump/XCOFFDump.cpp +++ llvm/tools/llvm-objdump/XCOFFDump.cpp @@ -14,11 +14,12 @@ #include "XCOFFDump.h" #include "llvm-objdump.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Demangle/Demangle.h" using namespace llvm; using namespace llvm::object; Error objdump::getXCOFFRelocationValueString(const XCOFFObjectFile &Obj, const RelocationRef &Rel, SmallVectorImpl &Result) { Index: llvm/unittests/Support/CompressionTest.cpp =================================================================== --- llvm/unittests/Support/CompressionTest.cpp +++ llvm/unittests/Support/CompressionTest.cpp @@ -12,99 +12,100 @@ #include "llvm/Support/Compression.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" #include "llvm/Support/Error.h" #include "gtest/gtest.h" using namespace llvm; using namespace llvm::compression; namespace { #if LLVM_ENABLE_ZLIB static void testZlibCompression(StringRef Input, int Level) { SmallVector Compressed; SmallVector Uncompressed; zlib::compress(arrayRefFromStringRef(Input), Compressed, Level); // Check that uncompressed buffer is the same as original. Error E = zlib::decompress(Compressed, Uncompressed, Input.size()); EXPECT_FALSE(std::move(E)); EXPECT_EQ(Input, toStringRef(Uncompressed)); // decompress with Z dispatches to zlib::decompress. E = compression::decompress(DebugCompressionType::Zlib, Compressed, Uncompressed, Input.size()); EXPECT_FALSE(std::move(E)); EXPECT_EQ(Input, toStringRef(Uncompressed)); if (Input.size() > 0) { // Decompression fails if expected length is too short. E = zlib::decompress(Compressed, Uncompressed, Input.size() - 1); EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E))); } } TEST(CompressionTest, Zlib) { testZlibCompression("", zlib::DefaultCompression); testZlibCompression("hello, world!", zlib::NoCompression); testZlibCompression("hello, world!", zlib::BestSizeCompression); testZlibCompression("hello, world!", zlib::BestSpeedCompression); testZlibCompression("hello, world!", zlib::DefaultCompression); const size_t kSize = 1024; char BinaryData[kSize]; for (size_t i = 0; i < kSize; ++i) BinaryData[i] = i & 255; StringRef BinaryDataStr(BinaryData, kSize); testZlibCompression(BinaryDataStr, zlib::NoCompression); testZlibCompression(BinaryDataStr, zlib::BestSizeCompression); testZlibCompression(BinaryDataStr, zlib::BestSpeedCompression); testZlibCompression(BinaryDataStr, zlib::DefaultCompression); } #endif #if LLVM_ENABLE_ZSTD static void testZstdCompression(StringRef Input, int Level) { SmallVector Compressed; SmallVector Uncompressed; zstd::compress(arrayRefFromStringRef(Input), Compressed, Level); // Check that uncompressed buffer is the same as original. Error E = zstd::decompress(Compressed, Uncompressed, Input.size()); EXPECT_FALSE(std::move(E)); EXPECT_EQ(Input, toStringRef(Uncompressed)); // decompress with Zstd dispatches to zstd::decompress. E = compression::decompress(DebugCompressionType::Zstd, Compressed, Uncompressed, Input.size()); EXPECT_FALSE(std::move(E)); EXPECT_EQ(Input, toStringRef(Uncompressed)); if (Input.size() > 0) { // Decompression fails if expected length is too short. E = zstd::decompress(Compressed, Uncompressed, Input.size() - 1); EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E))); } } TEST(CompressionTest, Zstd) { testZstdCompression("", zstd::DefaultCompression); testZstdCompression("hello, world!", zstd::NoCompression); testZstdCompression("hello, world!", zstd::BestSizeCompression); testZstdCompression("hello, world!", zstd::BestSpeedCompression); testZstdCompression("hello, world!", zstd::DefaultCompression); const size_t kSize = 1024; char BinaryData[kSize]; for (size_t i = 0; i < kSize; ++i) BinaryData[i] = i & 255; StringRef BinaryDataStr(BinaryData, kSize); testZstdCompression(BinaryDataStr, zstd::NoCompression); testZstdCompression(BinaryDataStr, zstd::BestSizeCompression); testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);