Index: include/llvm/ADT/StringRef.h =================================================================== --- include/llvm/ADT/StringRef.h +++ include/llvm/ADT/StringRef.h @@ -71,7 +71,7 @@ /// @{ /// Construct an empty string ref. - /*implicit*/ StringRef() : Data(nullptr), Length(0) {} + /*implicit*/ constexpr StringRef() : Data(nullptr), Length(0) {} /// Disable conversion from nullptr. This prevents things like /// if (S == nullptr) @@ -83,12 +83,9 @@ : Data(Str), Length(Str ? ::strlen(Str) : 0) {} /// Construct a string ref from a pointer and length. - LLVM_ATTRIBUTE_ALWAYS_INLINE + constexpr LLVM_ATTRIBUTE_ALWAYS_INLINE /*implicit*/ StringRef(const char *data, size_t length) - : Data(data), Length(length) { - assert((data || length == 0) && - "StringRef cannot be built from a NULL argument with non-null length"); - } + : Data(data), Length(data ? length : 0) {} /// Construct a string ref from an std::string. LLVM_ATTRIBUTE_ALWAYS_INLINE @@ -777,6 +774,14 @@ // StringRefs can be treated like a POD type. template struct isPodLike; template <> struct isPodLike { static const bool value = true; }; -} + + namespace operators { + /// User defined literal + /// Create a StringRef from a literal string. + constexpr llvm::StringRef operator"" _sr(const char *S, size_t Length) { + return llvm::StringRef(S, Length); + } + } // end namespace operators + } // end namespace llvm #endif Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -52,6 +52,7 @@ #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "asm-printer" @@ -1217,7 +1218,7 @@ OutStreamer->SwitchSection(ReadOnlySection); MCSymbol *AddrSymbol = - OutContext.getOrCreateSymbol(StringRef("__morestack_addr")); + OutContext.getOrCreateSymbol("__morestack_addr"_sr); OutStreamer->EmitLabel(AddrSymbol); unsigned PtrSize = M.getDataLayout().getPointerSize(0); Index: lib/CodeGen/AsmPrinter/DIEHash.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DIEHash.cpp +++ lib/CodeGen/AsmPrinter/DIEHash.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "dwarfdebug" @@ -37,7 +38,7 @@ if (V.getAttribute() == Attr) return V.getDIEString().getString(); - return StringRef(""); + return ""_sr; } /// \brief Adds the string in \p Str to the hash. This also hashes Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -43,6 +43,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetSubtargetInfo.h" using namespace llvm; +using namespace llvm::operators; using namespace dwarf; //===----------------------------------------------------------------------===// @@ -54,7 +55,7 @@ MachineModuleInfo *MMI) const { unsigned Encoding = getPersonalityEncoding(); if ((Encoding & 0x80) == dwarf::DW_EH_PE_indirect) - return getContext().getOrCreateSymbol(StringRef("DW.ref.") + + return getContext().getOrCreateSymbol("DW.ref."_sr + TM.getSymbol(GV, getMangler())->getName()); if ((Encoding & 0x70) == dwarf::DW_EH_PE_absptr) return TM.getSymbol(GV, getMangler()); @@ -556,7 +557,7 @@ Segment, Section, TAA, StubSize, SectionKind::getData()); Streamer.SwitchSection(S); Streamer.EmitLabel(getContext(). - getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO"))); + getOrCreateSymbol("L_OBJC_IMAGE_INFO"_sr)); Streamer.EmitIntValue(VersionVal, 4); Streamer.EmitIntValue(ImageInfoFlags, 4); Streamer.AddBlankLine(); Index: lib/CodeGen/TargetPassConfig.cpp =================================================================== --- lib/CodeGen/TargetPassConfig.cpp +++ lib/CodeGen/TargetPassConfig.cpp @@ -37,6 +37,7 @@ #include "llvm/Transforms/Utils/SymbolRewriter.h" using namespace llvm; +using namespace llvm::operators; static cl::opt DisablePostRA("disable-post-ra", cl::Hidden, cl::desc("Disable Post Regalloc")); @@ -575,7 +576,7 @@ !StringRef(PrintMachineInstrs.getValue()).equals("option-unspecified")) { const PassRegistry *PR = PassRegistry::getPassRegistry(); const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue()); - const PassInfo *IPI = PR->getPassInfo(StringRef("machineinstr-printer")); + const PassInfo *IPI = PR->getPassInfo("machineinstr-printer"_sr); assert (TPI && IPI && "Pass ID not registered!"); const char *TID = (const char *)(TPI->getTypeInfo()); const char *IID = (const char *)(IPI->getTypeInfo()); Index: lib/IR/Value.cpp =================================================================== --- lib/IR/Value.cpp +++ lib/IR/Value.cpp @@ -36,6 +36,7 @@ #include using namespace llvm; +using namespace llvm::operators; //===----------------------------------------------------------------------===// // Value Class @@ -193,7 +194,7 @@ // some clients want to call .data() on the result and expect it to be null // terminated. if (!hasName()) - return StringRef("", 0); + return ""_sr; return getValueName()->getKey(); } Index: lib/MC/MCAsmStreamer.cpp =================================================================== --- lib/MC/MCAsmStreamer.cpp +++ lib/MC/MCAsmStreamer.cpp @@ -36,6 +36,7 @@ #include using namespace llvm; +using namespace llvm::operators; namespace { @@ -346,12 +347,12 @@ StringRef c = T.getSingleStringRef(); if (c.equals(StringRef(MAI->getSeparatorString()))) return; - if (c.startswith(StringRef("//"))) { + if (c.startswith("//"_sr)) { ExplicitCommentToEmit.append("\t"); ExplicitCommentToEmit.append(MAI->getCommentString()); // drop // ExplicitCommentToEmit.append(c.slice(2, c.size()).str()); - } else if (c.startswith(StringRef("/*"))) { + } else if (c.startswith("/*"_sr)) { size_t p = 2, len = c.size() - 2; // emit each line in comment as separate newline. do { Index: lib/MC/MCDwarf.cpp =================================================================== --- lib/MC/MCDwarf.cpp +++ lib/MC/MCDwarf.cpp @@ -30,6 +30,7 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; +using namespace llvm::operators; static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) { unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment(); @@ -293,7 +294,7 @@ // First the directory table. for (unsigned i = 0; i < MCDwarfDirs.size(); i++) { MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName - MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string + MCOS->EmitBytes("\0"_sr); // the null term. of the string } MCOS->EmitIntValue(0, 1); // Terminate the directory list @@ -301,7 +302,7 @@ for (unsigned i = 1; i < MCDwarfFiles.size(); i++) { assert(!MCDwarfFiles[i].Name.empty()); MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName - MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string + MCOS->EmitBytes("\0"_sr); // the null term. of the string // the Directory num MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0) @@ -750,7 +751,7 @@ if (!DwarfDebugProducer.empty()) MCOS->EmitBytes(DwarfDebugProducer); else - MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")")); + MCOS->EmitBytes("llvm-mc (based on LLVM " PACKAGE_VERSION ")"_sr); MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2 Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -66,6 +66,7 @@ #include using namespace llvm; +using namespace llvm::operators; MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {} @@ -2717,7 +2718,7 @@ return true; getStreamer().EmitBytes(Data); if (ZeroTerminated) - getStreamer().EmitBytes(StringRef("\0", 1)); + getStreamer().EmitBytes("\0"_sr); return false; }; Index: lib/Object/MachOObjectFile.cpp =================================================================== --- lib/Object/MachOObjectFile.cpp +++ lib/Object/MachOObjectFile.cpp @@ -30,6 +30,7 @@ #include using namespace llvm; +using namespace llvm::operators; using namespace object; namespace { @@ -371,7 +372,7 @@ return malformedError("load command " + Twine(LoadCommandIndex) + " fileoff field in " + CmdName + " greater than vmsize field"); - IsPageZeroSegment |= StringRef("__PAGEZERO").equals(S.segname); + IsPageZeroSegment |= "__PAGEZERO"_sr.equals(S.segname); } else return SegOrErr.takeError(); Index: lib/Support/GraphWriter.cpp =================================================================== --- lib/Support/GraphWriter.cpp +++ lib/Support/GraphWriter.cpp @@ -17,6 +17,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" using namespace llvm; +using namespace llvm::operators; static cl::opt ViewBackground("view-background", cl::Hidden, cl::desc("Execute graph viewer in the background. Creates tmp file litter.")); @@ -260,7 +261,7 @@ args.push_back("/S"); args.push_back("/C"); StartArg = - (StringRef("start ") + (wait ? "/WAIT " : "") + OutputFilename).str(); + ("start "_sr + (wait ? "/WAIT " : "") + OutputFilename).str(); args.push_back(StartArg.c_str()); break; case VK_None: Index: lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- lib/Target/AArch64/AArch64ISelLowering.cpp +++ lib/Target/AArch64/AArch64ISelLowering.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetOptions.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "aarch64-lower" @@ -4795,7 +4796,7 @@ break; } } - if (StringRef("{cc}").equals_lower(Constraint)) + if ("{cc}"_sr.equals_lower(Constraint)) return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass); // Use the default implementation in TargetLowering to convert the register Index: lib/Target/ARM/ARMISelLowering.cpp =================================================================== --- lib/Target/ARM/ARMISelLowering.cpp +++ lib/Target/ARM/ARMISelLowering.cpp @@ -54,6 +54,7 @@ #include "llvm/Target/TargetOptions.h" #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "arm-isel" @@ -12264,7 +12265,7 @@ break; } } - if (StringRef("{cc}").equals_lower(Constraint)) + if ("{cc}"_sr.equals_lower(Constraint)) return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); Index: lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp =================================================================== --- lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -45,6 +45,7 @@ #include using namespace llvm; +using namespace llvm::operators; static std::string GetAEABIUnwindPersonalityName(unsigned Index) { assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && @@ -304,7 +305,7 @@ AttributeItem::NumericAttribute, Attribute, Value, - StringRef("") + ""_sr }; Contents.push_back(Item); } Index: lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp =================================================================== --- lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp +++ lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp @@ -45,6 +45,7 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; +using namespace llvm::operators; static cl::opt EnableFutureRegs("mfuture-regs", cl::desc("Enable future registers")); @@ -1667,13 +1668,13 @@ // Some or all of the zeros are replaced with the given immediate. if (is32bit) { std::string myImmStr = utohexstr(static_cast(Value)); - myCharStr = StringRef(".gnu.linkonce.l4.CONST_00000000") + myCharStr = ".gnu.linkonce.l4.CONST_00000000"_sr .drop_back(myImmStr.size()) .str() + myImmStr; } else { std::string myImmStr = utohexstr(Value); - myCharStr = StringRef(".gnu.linkonce.l8.CONST_0000000000000000") + myCharStr = ".gnu.linkonce.l8.CONST_0000000000000000"_sr .drop_back(myImmStr.size()) .str() + myImmStr; Index: lib/Target/NVPTX/NVPTXAsmPrinter.cpp =================================================================== --- lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -49,6 +49,7 @@ #include "llvm/Transforms/Utils/UnrollLoop.h" #include using namespace llvm; +using namespace llvm::operators; #define DEPOTNAME "__local_depot" @@ -443,7 +444,7 @@ void NVPTXAsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) const { AsmPrinter::EmitBasicBlockStart(MBB); if (isLoopHeaderOfNoUnroll(MBB)) - OutStreamer->EmitRawText(StringRef("\t.pragma \"nounroll\";\n")); + OutStreamer->EmitRawText("\t.pragma \"nounroll\";\n"_sr); } void NVPTXAsmPrinter::EmitFunctionEntryLabel() { @@ -480,7 +481,7 @@ void NVPTXAsmPrinter::EmitFunctionBodyStart() { VRegMapping.clear(); - OutStreamer->EmitRawText(StringRef("{\n")); + OutStreamer->EmitRawText("{\n"_sr); setAndEmitFunctionVirtualRegisters(*MF); SmallString<128> Str; @@ -490,7 +491,7 @@ } void NVPTXAsmPrinter::EmitFunctionBodyEnd() { - OutStreamer->EmitRawText(StringRef("}\n")); + OutStreamer->EmitRawText("}\n"_sr); VRegMapping.clear(); } Index: lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- lib/Target/PowerPC/PPCAsmPrinter.cpp +++ lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -59,6 +59,7 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetRegisterInfo.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "asmprinter" @@ -513,7 +514,7 @@ // blrl // This will return the pointer to _GLOBAL_OFFSET_TABLE_@local MCSymbol *GOTSymbol = - OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_")); + OutContext.getOrCreateSymbol("_GLOBAL_OFFSET_TABLE_"_sr); const MCExpr *OffsExpr = MCBinaryExpr::createSub(MCSymbolRefExpr::create(GOTSymbol, MCSymbolRefExpr::VK_PPC_LOCAL, @@ -807,7 +808,7 @@ } case PPC::PPC32PICGOT: { - MCSymbol *GOTSymbol = OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_")); + MCSymbol *GOTSymbol = OutContext.getOrCreateSymbol("_GLOBAL_OFFSET_TABLE_"_sr); MCSymbol *GOTRef = OutContext.createTempSymbol(); MCSymbol *NextInstr = OutContext.createTempSymbol(); @@ -836,7 +837,7 @@ } case PPC::PPC32GOT: { MCSymbol *GOTSymbol = - OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_")); + OutContext.getOrCreateSymbol("_GLOBAL_OFFSET_TABLE_"_sr); const MCExpr *SymGotTlsL = MCSymbolRefExpr::create( GOTSymbol, MCSymbolRefExpr::VK_PPC_LO, OutContext); const MCExpr *SymGotTlsHA = MCSymbolRefExpr::create( @@ -1108,7 +1109,7 @@ && !MF->getRegInfo().use_empty(PPC::X2)) { const PPCFunctionInfo *PPCFI = MF->getInfo(); - MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(".TOC.")); + MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(".TOC."_sr); MCSymbol *GlobalEPSymbol = PPCFI->getGlobalEPSymbol(); const MCExpr *TOCDeltaExpr = MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCSymbol, OutContext), @@ -1134,7 +1135,7 @@ // entry point. OutStreamer->EmitValue(MCSymbolRefExpr::create(Symbol1, OutContext), 8 /*size*/); - MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(StringRef(".TOC.")); + MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(".TOC."_sr); // Generates a R_PPC64_TOC relocation for TOC base insertion. OutStreamer->EmitValue( MCSymbolRefExpr::create(Symbol2, MCSymbolRefExpr::VK_PPC_TOCBASE, OutContext), @@ -1226,7 +1227,7 @@ MCSymbolRefExpr::create(GlobalEntryLabel, OutContext); if (TM.getCodeModel() != CodeModel::Large) { - MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(".TOC.")); + MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(".TOC."_sr); const MCExpr *TOCDeltaExpr = MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCSymbol, OutContext), GlobalEntryLabelExp, OutContext); Index: lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCISelLowering.cpp +++ lib/Target/PowerPC/PPCISelLowering.cpp @@ -45,6 +45,7 @@ #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "ppc-lowering" @@ -11696,7 +11697,7 @@ &PPC::G8RCRegClass); // GCC accepts 'cc' as an alias for 'cr0', and we need to do the same. - if (!R.second && StringRef("{cc}").equals_lower(Constraint)) { + if (!R.second && "{cc}"_sr.equals_lower(Constraint)) { R.first = PPC::CR0; R.second = &PPC::CRRCRegClass; } Index: lib/Target/X86/X86AsmPrinter.cpp =================================================================== --- lib/Target/X86/X86AsmPrinter.cpp +++ lib/Target/X86/X86AsmPrinter.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TargetRegistry.h" using namespace llvm; +using namespace llvm::operators; //===----------------------------------------------------------------------===// // Primitive Helper Functions. @@ -505,7 +506,7 @@ // Emit an absolute @feat.00 symbol. This appears to be some kind of // compiler features bitfield read by link.exe. if (TT.getArch() == Triple::x86) { - MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00")); + MCSymbol *S = MMI->getContext().getOrCreateSymbol("@feat.00"_sr); OutStreamer->BeginCOFFSymbolDef(S); OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC); OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL); Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -58,6 +58,7 @@ #include #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "x86-isel" @@ -32886,14 +32887,14 @@ } // GCC allows "st(0)" to be called just plain "st". - if (StringRef("{st}").equals_lower(Constraint)) { + if ("{st}"_sr.equals_lower(Constraint)) { Res.first = X86::FP0; Res.second = &X86::RFP80RegClass; return Res; } // flags -> EFLAGS - if (StringRef("{flags}").equals_lower(Constraint)) { + if ("{flags}"_sr.equals_lower(Constraint)) { Res.first = X86::EFLAGS; Res.second = &X86::CCRRegClass; return Res; Index: lib/Target/X86/X86MCInstLower.cpp =================================================================== --- lib/Target/X86/X86MCInstLower.cpp +++ lib/Target/X86/X86MCInstLower.cpp @@ -46,6 +46,7 @@ #include "llvm/Target/TargetLoweringObjectFile.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -1296,7 +1297,7 @@ case X86::EH_RETURN64: { // Lower these as normal, but add some comments. unsigned Reg = MI->getOperand(0).getReg(); - OutStreamer->AddComment(StringRef("eh_return, addr: %") + + OutStreamer->AddComment("eh_return, addr: %"_sr + X86ATTInstPrinter::getRegisterName(Reg)); break; } Index: lib/Target/XCore/XCoreAsmPrinter.cpp =================================================================== --- lib/Target/XCore/XCoreAsmPrinter.cpp +++ lib/Target/XCore/XCoreAsmPrinter.cpp @@ -45,6 +45,7 @@ #include #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "asm-printer" @@ -94,7 +95,7 @@ if (ArrayType *ATy = dyn_cast(GV->getValueType())) { MCSymbol *SymGlob = OutContext.getOrCreateSymbol( - Twine(Sym->getName() + StringRef(".globound"))); + Twine(Sym->getName() + ".globound"_sr)); OutStreamer->EmitSymbolAttribute(SymGlob, MCSA_Global); OutStreamer->EmitAssignment(SymGlob, MCConstantExpr::create(ATy->getNumElements(), Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -61,6 +61,7 @@ #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "asan" @@ -1786,7 +1787,7 @@ kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); // We insert an empty inline asm after __asan_report* to avoid callback merge. EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), - StringRef(""), StringRef(""), + ""_sr, ""_sr, /*hasSideEffects=*/true); } Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -116,6 +116,7 @@ #include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "msan" @@ -489,7 +490,7 @@ // We insert an empty inline asm after __msan_report* to avoid callback merge. EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), - StringRef(""), StringRef(""), + ""_sr, ""_sr, /*hasSideEffects=*/true); } Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -82,6 +82,7 @@ #include using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "pgo-instrumentation" @@ -1141,7 +1142,7 @@ std::move(ReaderOrErr.get()); if (!PGOReader) { Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(), - StringRef("Cannot get PGOReader"))); + "Cannot get PGOReader"_sr)); return false; } // TODO: might need to change the warning once the clang option is finalized. Index: lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -53,6 +53,7 @@ #include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; +using namespace llvm::operators; #define DEBUG_TYPE "sancov" @@ -294,7 +295,7 @@ // We insert an empty inline asm after cov callbacks to avoid callback merge. EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), - StringRef(""), StringRef(""), + ""_sr, ""_sr, /*hasSideEffects=*/true); SanCovTracePC = checkSanitizerInterfaceFunction( Index: tools/dsymutil/MachOUtils.cpp =================================================================== --- tools/dsymutil/MachOUtils.cpp +++ tools/dsymutil/MachOUtils.cpp @@ -23,6 +23,8 @@ #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" +using namespace llvm::operators; + namespace llvm { namespace dsymutil { namespace MachOUtils { @@ -228,12 +230,12 @@ const object::MachOObjectFile &Obj, MCObjectWriter &Writer, uint64_t LinkeditOffset, uint64_t LinkeditSize, uint64_t DwarfSegmentSize, uint64_t &GapForDwarf, uint64_t &EndAddress) { - if (StringRef("__DWARF") == Segment.segname) + if ("__DWARF"_sr == Segment.segname) return; Segment.fileoff = Segment.filesize = 0; - if (StringRef("__LINKEDIT") == Segment.segname) { + if ("__LINKEDIT"_sr == Segment.segname) { Segment.fileoff = LinkeditOffset; Segment.filesize = LinkeditSize; } @@ -300,7 +302,7 @@ static bool hasLinkEditSegment(const object::MachOObjectFile &Obj) { bool HasLinkEditSegment = false; iterateOnSegments(Obj, [&](const MachO::segment_command_64 &Segment) { - if (StringRef("__LINKEDIT") == Segment.segname) + if ("__LINKEDIT"_sr == Segment.segname) HasLinkEditSegment = true; }); return HasLinkEditSegment; @@ -377,7 +379,7 @@ Is64Bit ? sizeof(MachO::mach_header_64) : sizeof(MachO::mach_header); // We will copy every segment that isn't __DWARF. iterateOnSegments(InputBinary, [&](const MachO::segment_command_64 &Segment) { - if (StringRef("__DWARF") == Segment.segname) + if ("__DWARF"_sr == Segment.segname) return; ++NumLoadCommands; Index: tools/dsymutil/dsymutil.cpp =================================================================== --- tools/dsymutil/dsymutil.cpp +++ tools/dsymutil/dsymutil.cpp @@ -28,6 +28,7 @@ #include using namespace llvm::dsymutil; +using namespace llvm::operators; namespace { using namespace llvm::cl; @@ -218,7 +219,7 @@ // DWARF/ // std::string DwarfFile = - InputFile == "-" ? llvm::StringRef("a.out") : InputFile; + InputFile == "-" ? "a.out"_sr : InputFile; llvm::SmallString<128> BundleDir(OutputFileOpt); if (BundleDir.empty()) BundleDir = DwarfFile + ".dSYM"; Index: tools/llvm-pdbdump/LLVMOutputStyle.cpp =================================================================== --- tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -34,6 +34,7 @@ using namespace llvm; using namespace llvm::codeview; using namespace llvm::msf; +using namespace llvm::operators; using namespace llvm::pdb; namespace { @@ -692,9 +693,9 @@ LineInfo LI(N.Flags); P.printNumber("Offset", N.Offset); if (LI.isAlwaysStepInto()) - P.printString("StepInto", StringRef("Always")); + P.printString("StepInto", "Always"_sr); else if (LI.isNeverStepInto()) - P.printString("StepInto", StringRef("Never")); + P.printString("StepInto", "Never"_sr); else P.printNumber("LineNumberStart", LI.getStartLine()); P.printNumber("EndDelta", LI.getLineDelta()); Index: tools/llvm-readobj/ARMAttributeParser.cpp =================================================================== --- tools/llvm-readobj/ARMAttributeParser.cpp +++ tools/llvm-readobj/ARMAttributeParser.cpp @@ -15,6 +15,7 @@ using namespace llvm; using namespace llvm::ARMBuildAttrs; +using namespace llvm::operators; static const EnumEntry TagNames[] = { @@ -455,13 +456,13 @@ SW.printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false)); switch (Integer) { case 0: - SW.printString("Description", StringRef("No Specific Requirements")); + SW.printString("Description", "No Specific Requirements"_sr); break; case 1: - SW.printString("Description", StringRef("AEABI Conformant")); + SW.printString("Description", "AEABI Conformant"_sr); break; default: - SW.printString("Description", StringRef("AEABI Non-Conformant")); + SW.printString("Description", "AEABI Non-Conformant"_sr); break; } } Index: tools/llvm-readobj/ARMEHABIPrinter.h =================================================================== --- tools/llvm-readobj/ARMEHABIPrinter.h +++ tools/llvm-readobj/ARMEHABIPrinter.h @@ -22,6 +22,8 @@ #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/type_traits.h" +using namespace llvm::operators; + namespace llvm { namespace ARM { namespace EHABI { @@ -444,7 +446,7 @@ *reinterpret_cast(Contents->data() + TableEntryOffset); if (Word & 0x80000000) { - SW.printString("Model", StringRef("Compact")); + SW.printString("Model", "Compact"_sr); unsigned PersonalityIndex = (Word & 0x0f000000) >> 24; SW.printNumber("PersonalityIndex", PersonalityIndex); @@ -461,7 +463,7 @@ break; } } else { - SW.printString("Model", StringRef("Generic")); + SW.printString("Model", "Generic"_sr); uint64_t Address = PREL31(Word, EHT->sh_addr); SW.printHex("PersonalityRoutineAddress", Address); @@ -518,12 +520,12 @@ SW.printString("FunctionName", *Name); if (Word1 == EXIDX_CANTUNWIND) { - SW.printString("Model", StringRef("CantUnwind")); + SW.printString("Model", "CantUnwind"_sr); continue; } if (Word1 & 0x80000000) { - SW.printString("Model", StringRef("Compact (Inline)")); + SW.printString("Model", "Compact (Inline)"_sr); unsigned PersonalityIndex = (Word1 & 0x0f000000) >> 24; SW.printNumber("PersonalityIndex", PersonalityIndex); Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ tools/llvm-readobj/COFFDumper.cpp @@ -53,6 +53,7 @@ using namespace llvm; using namespace llvm::object; +using namespace llvm::operators; using namespace llvm::codeview; using namespace llvm::msf; using namespace llvm::support; @@ -929,9 +930,9 @@ ListScope PCScope(W, Buffer); LineInfo LI(LineData); if (LI.isAlwaysStepInto()) - W.printString("StepInto", StringRef("Always")); + W.printString("StepInto", "Always"_sr); else if (LI.isNeverStepInto()) - W.printString("StepInto", StringRef("Never")); + W.printString("StepInto", "Never"_sr); else W.printNumber("LineNumberStart", LI.getStartLine()); W.printNumber("LineNumberEndDelta", LI.getLineDelta()); @@ -1238,12 +1239,12 @@ return SectionName; } if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG) - return StringRef("IMAGE_SYM_DEBUG"); + return "IMAGE_SYM_DEBUG"_sr; if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE) - return StringRef("IMAGE_SYM_ABSOLUTE"); + return "IMAGE_SYM_ABSOLUTE"_sr; if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED) - return StringRef("IMAGE_SYM_UNDEFINED"); - return StringRef(""); + return "IMAGE_SYM_UNDEFINED"_sr; + return ""_sr; } void COFFDumper::printSymbol(const SymbolRef &Sym) { Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -33,6 +33,7 @@ using namespace llvm; using namespace llvm::object; +using namespace llvm::operators; using namespace ELF; #define LLVM_READOBJ_ENUM_CASE(ns, enum) \ @@ -638,7 +639,7 @@ if (!dot_gnu_version_sec) { // No version table. IsDefault = false; - return StringRef(""); + return ""_sr; } // Determine the position in the symbol table of this entry. @@ -655,7 +656,7 @@ if (version_index == ELF::VER_NDX_LOCAL || version_index == ELF::VER_NDX_GLOBAL) { IsDefault = false; - return StringRef(""); + return ""_sr; } // Lookup this symbol in the version table @@ -1994,13 +1995,13 @@ { DictScope D(W, "Entry"); printGotEntry(GOTShdr->sh_addr, GotBegin, It++); - W.printString("Purpose", StringRef("Lazy resolver")); + W.printString("Purpose", "Lazy resolver"_sr); } if (It != GotLocalEnd && (*It >> (sizeof(GOTEntry) * 8 - 1)) != 0) { DictScope D(W, "Entry"); printGotEntry(GOTShdr->sh_addr, GotBegin, It++); - W.printString("Purpose", StringRef("Module pointer (GNU extension)")); + W.printString("Purpose", "Module pointer (GNU extension)"_sr); } } { Index: tools/llvm-readobj/Win64EHDumper.cpp =================================================================== --- tools/llvm-readobj/Win64EHDumper.cpp +++ tools/llvm-readobj/Win64EHDumper.cpp @@ -15,6 +15,7 @@ using namespace llvm; using namespace llvm::object; +using namespace llvm::operators; using namespace llvm::Win64EH; static const EnumEntry UnwindFlags[] = { @@ -245,8 +246,8 @@ makeArrayRef(UnwindOpInfo)); SW.printHex("FrameOffset", UI.getFrameOffset()); } else { - SW.printString("FrameRegister", StringRef("-")); - SW.printString("FrameOffset", StringRef("-")); + SW.printString("FrameRegister", "-"_sr); + SW.printString("FrameOffset", "-"_sr); } SW.printNumber("UnwindCodeCount", UI.NumCodes); Index: unittests/ADT/APIntTest.cpp =================================================================== --- unittests/ADT/APIntTest.cpp +++ unittests/ADT/APIntTest.cpp @@ -14,6 +14,7 @@ #include using namespace llvm; +using namespace llvm::operators; namespace { @@ -950,7 +951,7 @@ EXPECT_DEATH(APInt(32, "-", 10), "String is only a sign, needs a value."); EXPECT_DEATH(APInt(1, "1234", 10), "Insufficient bit width"); EXPECT_DEATH(APInt(32, "\0", 10), "Invalid string length"); - EXPECT_DEATH(APInt(32, StringRef("1\02", 3), 10), "Invalid character in digit string"); + EXPECT_DEATH(APInt(32, "1\02"_sr, 10), "Invalid character in digit string"); EXPECT_DEATH(APInt(32, "1L", 10), "Invalid character in digit string"); } #endif Index: unittests/ADT/STLExtrasTest.cpp =================================================================== --- unittests/ADT/STLExtrasTest.cpp +++ unittests/ADT/STLExtrasTest.cpp @@ -13,6 +13,7 @@ #include using namespace llvm; +using namespace llvm::operators; namespace { @@ -229,7 +230,7 @@ }; TEST(STLExtrasTest, ApplyTupleVariadic) { - auto Items = std::make_tuple(1, llvm::StringRef("Test"), 'X'); + auto Items = std::make_tuple(1, "Test"_sr, 'X'); auto Values = apply_tuple(apply_variadic(), Items); EXPECT_EQ(2, std::get<0>(Values)); Index: unittests/ADT/StringRefTest.cpp =================================================================== --- unittests/ADT/StringRefTest.cpp +++ unittests/ADT/StringRefTest.cpp @@ -34,10 +34,14 @@ namespace { TEST(StringRefTest, Construction) { + using namespace llvm::operators; + EXPECT_EQ("", StringRef()); EXPECT_EQ("hello", StringRef("hello")); EXPECT_EQ("hello", StringRef("hello world", 5)); EXPECT_EQ("hello", StringRef(std::string("hello"))); + EXPECT_EQ("", ""_sr); + EXPECT_EQ("hello", "hello"_sr); } TEST(StringRefTest, Iteration) { Index: unittests/ADT/StringSwitchTest.cpp =================================================================== --- unittests/ADT/StringSwitchTest.cpp +++ unittests/ADT/StringSwitchTest.cpp @@ -11,6 +11,7 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; TEST(StringSwitchTest, Case) { auto Translate = [](StringRef S) { @@ -163,7 +164,7 @@ .Default(OSType::Unknown); }; - EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("wind\0ws", 7))); + EXPECT_EQ(OSType::Windows, Translate("wind\0ws"_sr)); EXPECT_EQ(OSType::Windows, Translate("win32")); EXPECT_EQ(OSType::Windows, Translate("winnt")); @@ -189,7 +190,7 @@ .Default(OSType::Unknown); }; - EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("WIND\0WS", 7))); + EXPECT_EQ(OSType::Windows, Translate("WIND\0WS"_sr)); EXPECT_EQ(OSType::Windows, Translate("WIN32")); EXPECT_EQ(OSType::Windows, Translate("WINNT")); @@ -198,7 +199,7 @@ EXPECT_EQ(OSType::Linux, Translate("*NIX")); EXPECT_EQ(OSType::Linux, Translate("POSIX")); - EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("wind\0ws", 7))); + EXPECT_EQ(OSType::Windows, Translate("wind\0ws"_sr)); EXPECT_EQ(OSType::Linux, Translate("linux")); EXPECT_EQ(OSType::Unknown, Translate("wind")); Index: unittests/ADT/TwineTest.cpp =================================================================== --- unittests/ADT/TwineTest.cpp +++ unittests/ADT/TwineTest.cpp @@ -12,6 +12,7 @@ #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -26,7 +27,7 @@ EXPECT_EQ("", Twine().str()); EXPECT_EQ("hi", Twine("hi").str()); EXPECT_EQ("hi", Twine(std::string("hi")).str()); - EXPECT_EQ("hi", Twine(StringRef("hi")).str()); + EXPECT_EQ("hi", Twine("hi"_sr).str()); EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str()); EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str()); EXPECT_EQ("hi", Twine(SmallString<4>("hi")).str()); @@ -85,7 +86,7 @@ SmallString<8> storage; EXPECT_EQ(0, *Twine("hello").toNullTerminatedStringRef(storage).end()); EXPECT_EQ(0, - *Twine(StringRef("hello")).toNullTerminatedStringRef(storage).end()); + *Twine("hello"_sr).toNullTerminatedStringRef(storage).end()); EXPECT_EQ(0, *Twine(SmallString<11>("hello")) .toNullTerminatedStringRef(storage) .end()); Index: unittests/Bitcode/BitstreamWriterTest.cpp =================================================================== --- unittests/Bitcode/BitstreamWriterTest.cpp +++ unittests/Bitcode/BitstreamWriterTest.cpp @@ -13,6 +13,7 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -20,7 +21,7 @@ SmallString<64> Buffer; BitstreamWriter W(Buffer); W.emitBlob("str", /* ShouldEmitSize */ false); - EXPECT_EQ(StringRef("str\0", 4), Buffer); + EXPECT_EQ("str\0"_sr, Buffer); } TEST(BitstreamWriterTest, emitBlobWithSize) { @@ -46,14 +47,14 @@ SmallString<64> Buffer; BitstreamWriter W(Buffer); W.emitBlob("", /* ShouldEmitSize */ false); - EXPECT_EQ(StringRef(""), Buffer); + EXPECT_EQ(""_sr, Buffer); } TEST(BitstreamWriterTest, emitBlob4ByteAligned) { SmallString<64> Buffer; BitstreamWriter W(Buffer); W.emitBlob("str0", /* ShouldEmitSize */ false); - EXPECT_EQ(StringRef("str0"), Buffer); + EXPECT_EQ("str0"_sr, Buffer); } } // end namespace Index: unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp =================================================================== --- unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp +++ unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp @@ -22,6 +22,7 @@ using namespace llvm; using namespace llvm::msf; +using namespace llvm::operators; namespace { @@ -97,7 +98,7 @@ StreamReader R(*S); StringRef Str = "ZYXWVUTSRQPONMLKJIHGFEDCBA"; EXPECT_NO_ERROR(R.readFixedString(Str, 1)); - EXPECT_EQ(Str, StringRef("A")); + EXPECT_EQ(Str, "A"_sr); EXPECT_EQ(0U, S->getNumBytesCopied()); } @@ -111,12 +112,12 @@ StreamReader R(*S); StringRef Str; EXPECT_NO_ERROR(R.readFixedString(Str, 2)); - EXPECT_EQ(Str, StringRef("AB")); + EXPECT_EQ(Str, "AB"_sr); EXPECT_EQ(0U, S->getNumBytesCopied()); R.setOffset(6); EXPECT_NO_ERROR(R.readFixedString(Str, 4)); - EXPECT_EQ(Str, StringRef("GHIJ")); + EXPECT_EQ(Str, "GHIJ"_sr); EXPECT_EQ(0U, S->getNumBytesCopied()); } @@ -130,7 +131,7 @@ StreamReader R(*S); StringRef Str; EXPECT_NO_ERROR(R.readFixedString(Str, 10)); - EXPECT_EQ(Str, StringRef("ABCDEFGHIJ")); + EXPECT_EQ(Str, "ABCDEFGHIJ"_sr); EXPECT_EQ(10U, S->getNumBytesCopied()); } @@ -184,7 +185,7 @@ StreamReader R(*S); StringRef Str; EXPECT_NO_ERROR(R.readFixedString(Str, 1)); - EXPECT_EQ(Str, StringRef("A")); + EXPECT_EQ(Str, "A"_sr); EXPECT_EQ(0U, S->getNumBytesCopied()); } @@ -199,12 +200,12 @@ StringRef Str1; StringRef Str2; EXPECT_NO_ERROR(R.readFixedString(Str1, 7)); - EXPECT_EQ(Str1, StringRef("ABCDEFG")); + EXPECT_EQ(Str1, "ABCDEFG"_sr); EXPECT_EQ(7U, S->getNumBytesCopied()); R.setOffset(2); EXPECT_NO_ERROR(R.readFixedString(Str2, 3)); - EXPECT_EQ(Str2, StringRef("CDE")); + EXPECT_EQ(Str2, "CDE"_sr); EXPECT_EQ(Str1.data() + 2, Str2.data()); EXPECT_EQ(7U, S->getNumBytesCopied()); } @@ -220,12 +221,12 @@ StringRef Str1; StringRef Str2; EXPECT_NO_ERROR(R.readFixedString(Str1, 6)); - EXPECT_EQ(Str1, StringRef("ABCDEF")); + EXPECT_EQ(Str1, "ABCDEF"_sr); EXPECT_EQ(6U, S->getNumBytesCopied()); R.setOffset(4); EXPECT_NO_ERROR(R.readFixedString(Str2, 4)); - EXPECT_EQ(Str2, StringRef("EFGH")); + EXPECT_EQ(Str2, "EFGH"_sr); EXPECT_EQ(10U, S->getNumBytesCopied()); } Index: unittests/IR/DebugInfoTest.cpp =================================================================== --- unittests/IR/DebugInfoTest.cpp +++ unittests/IR/DebugInfoTest.cpp @@ -11,6 +11,7 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -35,19 +36,19 @@ TEST(DINodeTest, getFlagString) { // Some valid flags. - EXPECT_EQ(StringRef("DIFlagPublic"), + EXPECT_EQ("DIFlagPublic"_sr, DINode::getFlagString(DINode::FlagPublic)); - EXPECT_EQ(StringRef("DIFlagProtected"), + EXPECT_EQ("DIFlagProtected"_sr, DINode::getFlagString(DINode::FlagProtected)); - EXPECT_EQ(StringRef("DIFlagPrivate"), + EXPECT_EQ("DIFlagPrivate"_sr, DINode::getFlagString(DINode::FlagPrivate)); - EXPECT_EQ(StringRef("DIFlagVector"), + EXPECT_EQ("DIFlagVector"_sr, DINode::getFlagString(DINode::FlagVector)); - EXPECT_EQ(StringRef("DIFlagRValueReference"), + EXPECT_EQ("DIFlagRValueReference"_sr, DINode::getFlagString(DINode::FlagRValueReference)); // FlagAccessibility actually equals FlagPublic. - EXPECT_EQ(StringRef("DIFlagPublic"), + EXPECT_EQ("DIFlagPublic"_sr, DINode::getFlagString(DINode::FlagAccessibility)); // Some other invalid flags. Index: unittests/IR/MDBuilderTest.cpp =================================================================== --- unittests/IR/MDBuilderTest.cpp +++ unittests/IR/MDBuilderTest.cpp @@ -14,6 +14,7 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -26,8 +27,8 @@ MDBuilder MDHelper(Context); MDString *Str0 = MDHelper.createString(""); MDString *Str1 = MDHelper.createString("string"); - EXPECT_EQ(Str0->getString(), StringRef("")); - EXPECT_EQ(Str1->getString(), StringRef("string")); + EXPECT_EQ(Str0->getString(), ""_sr); + EXPECT_EQ(Str1->getString(), "string"_sr); } TEST_F(MDBuilderTest, createFPMath) { MDBuilder MDHelper(Context); Index: unittests/ProfileData/InstrProfTest.cpp =================================================================== --- unittests/ProfileData/InstrProfTest.cpp +++ unittests/ProfileData/InstrProfTest.cpp @@ -18,6 +18,7 @@ #include using namespace llvm; +using namespace llvm::operators; static ::testing::AssertionResult NoError(Error E) { if (!E) @@ -77,7 +78,7 @@ auto I = Reader->begin(), E = Reader->end(); ASSERT_TRUE(I != E); - ASSERT_EQ(StringRef("foo"), I->Name); + ASSERT_EQ("foo"_sr, I->Name); ASSERT_EQ(0x1234U, I->Hash); ASSERT_EQ(4U, I->Counts.size()); ASSERT_EQ(1U, I->Counts[0]); @@ -276,9 +277,9 @@ ASSERT_EQ(1U, VD[2].Count); ASSERT_EQ(6U, TotalC); - ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3")); - ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2")); - ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), "callee3"_sr); + ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), "callee2"_sr); + ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), "callee1"_sr); } TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) { @@ -418,9 +419,9 @@ ASSERT_EQ(10U, VD[2].Count); ASSERT_EQ(60U, TotalC); - ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3")); - ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2")); - ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), "callee3"_sr); + ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), "callee2"_sr); + ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), "callee1"_sr); } TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) { @@ -465,9 +466,9 @@ std::unique_ptr VD = R->getValueForSite(IPVK_IndirectCallTarget, 0); - ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3")); - ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2")); - ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), "callee3"_sr); + ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), "callee2"_sr); + ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), "callee1"_sr); // Restore little endian default: Writer.setValueProfDataEndianness(support::little); @@ -548,38 +549,38 @@ std::unique_ptr VD = R->getValueForSite(IPVK_IndirectCallTarget, 0); - ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), "callee2"_sr); ASSERT_EQ(7U, VD[0].Count); - ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), "callee3"_sr); ASSERT_EQ(6U, VD[1].Count); - ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee4")); + ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), "callee4"_sr); ASSERT_EQ(4U, VD[2].Count); - ASSERT_EQ(StringRef((const char *)VD[3].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD[3].Value, 7), "callee1"_sr); ASSERT_EQ(1U, VD[3].Count); std::unique_ptr VD_2( R->getValueForSite(IPVK_IndirectCallTarget, 2)); - ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), "callee3"_sr); ASSERT_EQ(6U, VD_2[0].Count); - ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), StringRef("callee4")); + ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), "callee4"_sr); ASSERT_EQ(4U, VD_2[1].Count); - ASSERT_EQ(StringRef((const char *)VD_2[2].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD_2[2].Value, 7), "callee2"_sr); ASSERT_EQ(3U, VD_2[2].Count); - ASSERT_EQ(StringRef((const char *)VD_2[3].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD_2[3].Value, 7), "callee1"_sr); ASSERT_EQ(1U, VD_2[3].Count); std::unique_ptr VD_3( R->getValueForSite(IPVK_IndirectCallTarget, 3)); - ASSERT_EQ(StringRef((const char *)VD_3[0].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD_3[0].Value, 7), "callee1"_sr); ASSERT_EQ(1U, VD_3[0].Count); std::unique_ptr VD_4( R->getValueForSite(IPVK_IndirectCallTarget, 4)); - ASSERT_EQ(StringRef((const char *)VD_4[0].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_4[0].Value, 7), "callee3"_sr); ASSERT_EQ(6U, VD_4[0].Count); - ASSERT_EQ(StringRef((const char *)VD_4[1].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD_4[1].Value, 7), "callee2"_sr); ASSERT_EQ(4U, VD_4[1].Count); - ASSERT_EQ(StringRef((const char *)VD_4[2].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD_4[2].Value, 7), "callee1"_sr); ASSERT_EQ(2U, VD_4[2].Count); } @@ -636,7 +637,7 @@ ASSERT_EQ(1U, ReadRecord2->getNumValueSites(IPVK_IndirectCallTarget)); std::unique_ptr VD = ReadRecord2->getValueForSite(IPVK_IndirectCallTarget, 0); - ASSERT_EQ(StringRef("bar"), StringRef((const char *)VD[0].Value, 3)); + ASSERT_EQ("bar"_sr, StringRef((const char *)VD[0].Value, 3)); ASSERT_EQ(Max, VD[0].Count); } @@ -735,45 +736,45 @@ std::unique_ptr VD_0( Record.getValueForSite(IPVK_IndirectCallTarget, 0)); std::sort(&VD_0[0], &VD_0[5], Cmp); - ASSERT_EQ(StringRef((const char *)VD_0[0].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD_0[0].Value, 7), "callee2"_sr); ASSERT_EQ(1000U, VD_0[0].Count); - ASSERT_EQ(StringRef((const char *)VD_0[1].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_0[1].Value, 7), "callee3"_sr); ASSERT_EQ(500U, VD_0[1].Count); - ASSERT_EQ(StringRef((const char *)VD_0[2].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD_0[2].Value, 7), "callee1"_sr); ASSERT_EQ(400U, VD_0[2].Count); - ASSERT_EQ(StringRef((const char *)VD_0[3].Value, 7), StringRef("callee4")); + ASSERT_EQ(StringRef((const char *)VD_0[3].Value, 7), "callee4"_sr); ASSERT_EQ(300U, VD_0[3].Count); - ASSERT_EQ(StringRef((const char *)VD_0[4].Value, 7), StringRef("callee5")); + ASSERT_EQ(StringRef((const char *)VD_0[4].Value, 7), "callee5"_sr); ASSERT_EQ(100U, VD_0[4].Count); std::unique_ptr VD_1( Record.getValueForSite(IPVK_IndirectCallTarget, 1)); std::sort(&VD_1[0], &VD_1[4], Cmp); - ASSERT_EQ(StringRef((const char *)VD_1[0].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD_1[0].Value, 7), "callee2"_sr); ASSERT_EQ(2500U, VD_1[0].Count); - ASSERT_EQ(StringRef((const char *)VD_1[1].Value, 7), StringRef("callee1")); + ASSERT_EQ(StringRef((const char *)VD_1[1].Value, 7), "callee1"_sr); ASSERT_EQ(1300U, VD_1[1].Count); - ASSERT_EQ(StringRef((const char *)VD_1[2].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_1[2].Value, 7), "callee3"_sr); ASSERT_EQ(1000U, VD_1[2].Count); - ASSERT_EQ(StringRef((const char *)VD_1[3].Value, 7), StringRef("callee5")); + ASSERT_EQ(StringRef((const char *)VD_1[3].Value, 7), "callee5"_sr); ASSERT_EQ(800U, VD_1[3].Count); std::unique_ptr VD_2( Record.getValueForSite(IPVK_IndirectCallTarget, 2)); std::sort(&VD_2[0], &VD_2[3], Cmp); - ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), StringRef("callee4")); + ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), "callee4"_sr); ASSERT_EQ(5500U, VD_2[0].Count); - ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), "callee3"_sr); ASSERT_EQ(1000U, VD_2[1].Count); - ASSERT_EQ(StringRef((const char *)VD_2[2].Value, 7), StringRef("callee6")); + ASSERT_EQ(StringRef((const char *)VD_2[2].Value, 7), "callee6"_sr); ASSERT_EQ(800U, VD_2[2].Count); std::unique_ptr VD_3( Record.getValueForSite(IPVK_IndirectCallTarget, 3)); std::sort(&VD_3[0], &VD_3[2], Cmp); - ASSERT_EQ(StringRef((const char *)VD_3[0].Value, 7), StringRef("callee3")); + ASSERT_EQ(StringRef((const char *)VD_3[0].Value, 7), "callee3"_sr); ASSERT_EQ(2000U, VD_3[0].Count); - ASSERT_EQ(StringRef((const char *)VD_3[1].Value, 7), StringRef("callee2")); + ASSERT_EQ(StringRef((const char *)VD_3[1].Value, 7), "callee2"_sr); ASSERT_EQ(1800U, VD_3[1].Count); } @@ -861,17 +862,17 @@ InstrProfSymtab Symtab; Symtab.create(FuncNames); StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1")); - ASSERT_EQ(StringRef("func1"), R); + ASSERT_EQ("func1"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2")); - ASSERT_EQ(StringRef("func2"), R); + ASSERT_EQ("func2"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func3")); - ASSERT_EQ(StringRef("func3"), R); + ASSERT_EQ("func3"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar1")); - ASSERT_EQ(StringRef("bar1"), R); + ASSERT_EQ("bar1"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar2")); - ASSERT_EQ(StringRef("bar2"), R); + ASSERT_EQ("bar2"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3")); - ASSERT_EQ(StringRef("bar3"), R); + ASSERT_EQ("bar3"_sr, R); // negative tests R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar4")); @@ -888,23 +889,23 @@ // Check again R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_1")); - ASSERT_EQ(StringRef("blah_1"), R); + ASSERT_EQ("blah_1"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_2")); - ASSERT_EQ(StringRef("blah_2"), R); + ASSERT_EQ("blah_2"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_3")); - ASSERT_EQ(StringRef("blah_3"), R); + ASSERT_EQ("blah_3"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1")); - ASSERT_EQ(StringRef("func1"), R); + ASSERT_EQ("func1"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2")); - ASSERT_EQ(StringRef("func2"), R); + ASSERT_EQ("func2"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func3")); - ASSERT_EQ(StringRef("func3"), R); + ASSERT_EQ("func3"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar1")); - ASSERT_EQ(StringRef("bar1"), R); + ASSERT_EQ("bar1"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar2")); - ASSERT_EQ(StringRef("bar2"), R); + ASSERT_EQ("bar2"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3")); - ASSERT_EQ(StringRef("bar3"), R); + ASSERT_EQ("bar3"_sr, R); } // Testing symtab creator interface used by value profile transformer. @@ -990,9 +991,9 @@ // Now do the checks: // First sampling some data points: StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0])); - ASSERT_EQ(StringRef("func_0"), R); + ASSERT_EQ("func_0"_sr, R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1])); - ASSERT_EQ(StringRef("f oooooooooooooo_0"), R); + ASSERT_EQ("f oooooooooooooo_0"_sr, R); for (int I = 0; I < 3; I++) { std::string N[4]; N[0] = FuncNames1[2 * I]; Index: unittests/Support/CompressionTest.cpp =================================================================== --- unittests/Support/CompressionTest.cpp +++ unittests/Support/CompressionTest.cpp @@ -18,6 +18,7 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace llvm::operators; namespace { @@ -62,7 +63,7 @@ TEST(CompressionTest, ZlibCRC32) { EXPECT_EQ( 0x414FA339U, - zlib::crc32(StringRef("The quick brown fox jumps over the lazy dog"))); + zlib::crc32("The quick brown fox jumps over the lazy dog"_sr)); } #endif Index: unittests/Support/ConvertUTFTest.cpp =================================================================== --- unittests/Support/ConvertUTFTest.cpp +++ unittests/Support/ConvertUTFTest.cpp @@ -16,6 +16,7 @@ #include using namespace llvm; +using namespace llvm::operators; TEST(ConvertUTFTest, ConvertUTF16LittleEndianToUTF8String) { // Src is the look of disapproval. @@ -280,7 +281,7 @@ // U+0000 NULL EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( ConvertUTFResultContainer(conversionOK).withScalars(0x0000), - StringRef("\x00", 1))); + "\x00"_sr)); // U+0080 PADDING CHARACTER EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( @@ -1054,7 +1055,7 @@ // U+0000 NULL EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( ConvertUTFResultContainer(conversionOK).withScalars(0x0000), - StringRef("\x00", 1))); + "\x00"_sr)); // Overlong sequences of the above. EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( Index: unittests/Support/DwarfTest.cpp =================================================================== --- unittests/Support/DwarfTest.cpp +++ unittests/Support/DwarfTest.cpp @@ -12,6 +12,7 @@ using namespace llvm; using namespace llvm::dwarf; +using namespace llvm::operators; namespace { @@ -110,15 +111,15 @@ } TEST(DwarfTest, VirtualityString) { - EXPECT_EQ(StringRef("DW_VIRTUALITY_none"), + EXPECT_EQ("DW_VIRTUALITY_none"_sr, VirtualityString(DW_VIRTUALITY_none)); - EXPECT_EQ(StringRef("DW_VIRTUALITY_virtual"), + EXPECT_EQ("DW_VIRTUALITY_virtual"_sr, VirtualityString(DW_VIRTUALITY_virtual)); - EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"), + EXPECT_EQ("DW_VIRTUALITY_pure_virtual"_sr, VirtualityString(DW_VIRTUALITY_pure_virtual)); // DW_VIRTUALITY_max should be pure virtual. - EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"), + EXPECT_EQ("DW_VIRTUALITY_pure_virtual"_sr, VirtualityString(DW_VIRTUALITY_max)); // Invalid numbers shouldn't be stringified. Index: unittests/Support/Path.cpp =================================================================== --- unittests/Support/Path.cpp +++ unittests/Support/Path.cpp @@ -29,6 +29,7 @@ #endif using namespace llvm; +using namespace llvm::operators; using namespace llvm::sys; #define ASSERT_NO_ERROR(x) \ @@ -164,7 +165,7 @@ } TEST(Support, RelativePathIterator) { - SmallString<64> Path(StringRef("c/d/e/foo.txt")); + SmallString<64> Path("c/d/e/foo.txt"_sr); typedef SmallVector PathComponents; PathComponents ExpectedPathComponents; PathComponents ActualPathComponents; @@ -184,7 +185,7 @@ } TEST(Support, RelativePathDotIterator) { - SmallString<64> Path(StringRef(".c/.d/../.")); + SmallString<64> Path(".c/.d/../."_sr); typedef SmallVector PathComponents; PathComponents ExpectedPathComponents; PathComponents ActualPathComponents; @@ -204,7 +205,7 @@ } TEST(Support, AbsolutePathIterator) { - SmallString<64> Path(StringRef("/c/d/e/foo.txt")); + SmallString<64> Path("/c/d/e/foo.txt"_sr); typedef SmallVector PathComponents; PathComponents ExpectedPathComponents; PathComponents ActualPathComponents; @@ -227,7 +228,7 @@ } TEST(Support, AbsolutePathDotIterator) { - SmallString<64> Path(StringRef("/.c/.d/../.")); + SmallString<64> Path("/.c/.d/../."_sr); typedef SmallVector PathComponents; PathComponents ExpectedPathComponents; PathComponents ActualPathComponents; @@ -251,7 +252,7 @@ #ifdef LLVM_ON_WIN32 TEST(Support, AbsolutePathIteratorWin32) { - SmallString<64> Path(StringRef("c:\\c\\e\\foo.txt")); + SmallString<64> Path("c:\\c\\e\\foo.txt"_sr); typedef SmallVector PathComponents; PathComponents ExpectedPathComponents; PathComponents ActualPathComponents; Index: unittests/Support/TargetParserTest.cpp =================================================================== --- unittests/Support/TargetParserTest.cpp +++ unittests/Support/TargetParserTest.cpp @@ -14,6 +14,7 @@ #include using namespace llvm; +using namespace llvm::operators; namespace { static const unsigned kAArch64ArchExtKinds[] = { @@ -158,7 +159,7 @@ AK < ARM::ArchKind::AK_LAST; AK = static_cast(static_cast(AK) + 1)) EXPECT_EQ(kARMARCHNames[AK].DefaultFPU, - ARM::getDefaultFPU(StringRef("generic"), AK)); + ARM::getDefaultFPU("generic"_sr, AK)); for (const auto &ARMCPUName : kARMCPUNames) EXPECT_EQ(ARMCPUName.DefaultFPU, ARM::getDefaultFPU(ARMCPUName.Name, 0)); @@ -169,7 +170,7 @@ AK < ARM::ArchKind::AK_LAST; AK = static_cast(static_cast(AK) + 1)) EXPECT_EQ(kARMARCHNames[AK].ArchBaseExtensions, - ARM::getDefaultExtensions(StringRef("generic"), AK)); + ARM::getDefaultExtensions("generic"_sr, AK)); for (const auto &ARMCPUName : kARMCPUNames) { unsigned DefaultExt = @@ -409,7 +410,7 @@ for (unsigned AK = 0; AK < static_cast(AArch64::ArchKind::AK_LAST); AK++) EXPECT_EQ(kAArch64ARCHNames[AK].DefaultFPU, - AArch64::getDefaultFPU(StringRef("generic"), AK)); + AArch64::getDefaultFPU("generic"_sr, AK)); for (const auto &AArch64CPUName : kAArch64CPUNames) EXPECT_EQ(AArch64CPUName.DefaultFPU, @@ -421,7 +422,7 @@ for (unsigned AK = 0; AK < static_cast(AArch64::ArchKind::AK_LAST); AK++) EXPECT_EQ(kAArch64ARCHNames[AK].ArchBaseExtensions, - AArch64::getDefaultExtensions(StringRef("generic"), AK)); + AArch64::getDefaultExtensions("generic"_sr, AK)); for (const auto &AArch64CPUName : kAArch64CPUNames) EXPECT_EQ( Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/YAMLTraits.h" #include "gtest/gtest.h" +using namespace llvm::operators; using llvm::yaml::Input; using llvm::yaml::Output; @@ -1103,8 +1104,8 @@ { NameAndNumbers map; map.name = "hello"; - map.strings.push_back(llvm::StringRef("one")); - map.strings.push_back(llvm::StringRef("two")); + map.strings.push_back("one"_sr); + map.strings.push_back("two"_sr); map.single.push_back(1); map.numbers.push_back(10); map.numbers.push_back(-30); Index: utils/FileCheck/FileCheck.cpp =================================================================== --- utils/FileCheck/FileCheck.cpp +++ utils/FileCheck/FileCheck.cpp @@ -34,6 +34,7 @@ #include #include using namespace llvm; +using namespace llvm::operators; static cl::opt CheckFilename(cl::Positional, cl::desc(""), cl::Required); @@ -383,7 +384,7 @@ // The only supported expression is @LINE([\+-]\d+)? if (!Expr.startswith("@LINE")) return false; - Expr = Expr.substr(StringRef("@LINE").size()); + Expr = Expr.substr("@LINE"_sr.size()); int Offset = 0; if (!Expr.empty()) { if (Expr[0] == '+')