Avoid deprecations with LLVM 18 wrt. renamed llvm::StringRef::{starts,ends}with()

This commit is contained in:
Martin Kinkelin 2024-03-28 15:22:21 +01:00
parent e728075594
commit 3beb68904f
9 changed files with 70 additions and 0 deletions

View file

@ -636,6 +636,10 @@ void ArgsBuilder::addLinker() {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void ArgsBuilder::addUserSwitches() { void ArgsBuilder::addUserSwitches() {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
// additional linker and cc switches (preserve order across both lists) // additional linker and cc switches (preserve order across both lists)
for (unsigned ilink = 0, icc = 0;;) { for (unsigned ilink = 0, icc = 0;;) {
unsigned linkpos = ilink < opts::linkerSwitches.size() unsigned linkpos = ilink < opts::linkerSwitches.size()
@ -664,6 +668,10 @@ void ArgsBuilder::addUserSwitches() {
break; break;
} }
} }
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -189,6 +189,10 @@ void tryParse(const llvm::SmallVectorImpl<const char *> &args, size_t i,
} }
bool tryParseLowmem(const llvm::SmallVectorImpl<const char *> &args) { bool tryParseLowmem(const llvm::SmallVectorImpl<const char *> &args) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
bool lowmem = false; bool lowmem = false;
for (size_t i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
if (args::isRunArg(args[i])) if (args::isRunArg(args[i]))
@ -206,6 +210,10 @@ bool tryParseLowmem(const llvm::SmallVectorImpl<const char *> &args) {
} }
} }
return lowmem; return lowmem;
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
const char * const char *

View file

@ -52,6 +52,10 @@
#include "gen/optimizer.h" #include "gen/optimizer.h"
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
#ifdef LDC_LLVM_SUPPORTS_MACHO_DWARF_LINE_AS_REGULAR_SECTION #ifdef LDC_LLVM_SUPPORTS_MACHO_DWARF_LINE_AS_REGULAR_SECTION
// LDC-LLVM >= 6.0.1: // LDC-LLVM >= 6.0.1:
// On Mac, emit __debug_line section in __DWARF segment as regular (non-debug) // On Mac, emit __debug_line section in __DWARF segment as regular (non-debug)

View file

@ -60,6 +60,10 @@ class ConstraintsBuilder {
// Appends a constraint string expression with an optional prefix. // Appends a constraint string expression with an optional prefix.
// Returns true if the string describes an indirect operand. // Returns true if the string describes an indirect operand.
bool append(Expression *e, char prefix = 0) { bool append(Expression *e, char prefix = 0) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
auto se = e->isStringExp(); auto se = e->isStringExp();
assert(se); assert(se);
llvm::StringRef code = peekString(se); llvm::StringRef code = peekString(se);
@ -90,6 +94,10 @@ class ConstraintsBuilder {
str << ','; str << ',';
return isIndirect; return isIndirect;
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
// Might set `isIndirect` to true (but never resets to false). // Might set `isIndirect` to true (but never resets to false).

View file

@ -393,6 +393,11 @@ public:
void visit(PragmaDeclaration *decl) override { void visit(PragmaDeclaration *decl) override {
const auto &triple = *global.params.targetTriple; const auto &triple = *global.params.targetTriple;
#if LDC_LLVM_VER >= 1800
#define endswith ends_with
#define startswith starts_with
#endif
if (decl->ident == Id::lib) { if (decl->ident == Id::lib) {
assert(!irs->dcomputetarget); assert(!irs->dcomputetarget);
llvm::StringRef name = getPragmaStringArg(decl); llvm::StringRef name = getPragmaStringArg(decl);
@ -466,6 +471,11 @@ public:
} }
} }
visit(static_cast<AttribDeclaration *>(decl)); visit(static_cast<AttribDeclaration *>(decl));
#if LDC_LLVM_VER >= 1800
#undef endswith
#undef startswith
#endif
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View file

@ -901,6 +901,10 @@ bool eraseDummyAfterReturnBB(llvm::BasicBlock *bb) {
* to be found. * to be found.
*/ */
void emulateWeakAnyLinkageForMSVC(IrFunction *irFunc, LINK linkage) { void emulateWeakAnyLinkageForMSVC(IrFunction *irFunc, LINK linkage) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
LLFunction *func = irFunc->getLLVMFunc(); LLFunction *func = irFunc->getLLVMFunc();
const bool isWin32 = global.params.targetTriple->isArch32Bit(); const bool isWin32 = global.params.targetTriple->isArch32Bit();
@ -952,6 +956,10 @@ void emulateWeakAnyLinkageForMSVC(IrFunction *irFunc, LINK linkage) {
// declaration // declaration
irFunc->setLLVMFunc(newFunc); irFunc->setLLVMFunc(newFunc);
func->replaceNonMetadataUsesWith(newFunc); func->replaceNonMetadataUsesWith(newFunc);
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
} // anonymous namespace } // anonymous namespace

View file

@ -315,6 +315,10 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
// The current implementation here does not do any checking of the specified // The current implementation here does not do any checking of the specified
// string and simply passes all to llvm. // string and simply passes all to llvm.
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
checkStructElems(sle, {Type::tstring}); checkStructElems(sle, {Type::tstring});
llvm::StringRef targetspec = getFirstElemString(sle); llvm::StringRef targetspec = getFirstElemString(sle);
@ -375,6 +379,10 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
llvm::join(features.begin(), features.end(), ",")); llvm::join(features.begin(), features.end(), ","));
irFunc->targetFeaturesOverridden = true; irFunc->targetFeaturesOverridden = true;
} }
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
void applyAttrAssumeUsed(IRState &irs, StructLiteralExp *sle, void applyAttrAssumeUsed(IRState &irs, StructLiteralExp *sle,

View file

@ -61,6 +61,10 @@ bool IrAggr::useDLLImport() const {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
LLConstant *IrAggr::getInitSymbol(bool define) { LLConstant *IrAggr::getInitSymbol(bool define) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
if (!init) { if (!init) {
const auto irMangle = getIRMangledInitSymbolName(aggrdecl); const auto irMangle = getIRMangledInitSymbolName(aggrdecl);
@ -107,6 +111,10 @@ LLConstant *IrAggr::getInitSymbol(bool define) {
} }
return init; return init;
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -104,6 +104,10 @@ inline bool isSpace_ldc(char C) {
} // namespace } // namespace
static int handle(MemoryBuffer &inputBuf, StringRef input) { static int handle(MemoryBuffer &inputBuf, StringRef input) {
#if LDC_LLVM_VER >= 1800
#define startswith starts_with
#endif
DenseMap<StringRef, Part> partToBegin; DenseMap<StringRef, Part> partToBegin;
StringRef lastPart, separator; StringRef lastPart, separator;
StringRef EOL = detectEOL(inputBuf.getBuffer()); StringRef EOL = detectEOL(inputBuf.getBuffer());
@ -174,6 +178,10 @@ static int handle(MemoryBuffer &inputBuf, StringRef input) {
for (std::unique_ptr<ToolOutputFile> &outputFile : outputFiles) for (std::unique_ptr<ToolOutputFile> &outputFile : outputFiles)
outputFile->keep(); outputFile->keep();
return 0; return 0;
#if LDC_LLVM_VER >= 1800
#undef startswith
#endif
} }
int main(int argc, const char **argv) { int main(int argc, const char **argv) {