Skip to content

Commit 6143d88

Browse files
authored
Fix compile errors for LLVM 22 (#5097)
This fixes all compile errors and new deprecations with LLVM 22.1.1 on my Linux box. [There's still an unresolved symbol when trying to link ldc2.]
1 parent 7304871 commit 6143d88

File tree

9 files changed

+32
-14
lines changed

9 files changed

+32
-14
lines changed

driver/cl_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,11 @@ void createClashingOptions() {
798798
auto renameAndHide = [&map](const char *from, const char *to) {
799799
auto i = map.find(from);
800800
if (i != map.end()) {
801-
#if LDC_LLVM_VER >= 2300
801+
#if LDC_LLVM_VER >= 2200
802802
cl::Option *opt = i->second;
803803
#else
804804
cl::Option *opt = i->getValue();
805-
#endif
805+
#endif
806806
map.erase(i);
807807
if (to) {
808808
opt->setArgStr(to);

driver/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ void parseCommandLine(Strings &sourceFiles) {
310310
if (auto target = lookupTarget("", triple, errMsg)) {
311311
llvm::errs() << "Targeting " << target->getName() << ". ";
312312
// this prints the available CPUs and features of the target to stderr...
313-
#if LDC_LLVM_VER >= 2300
313+
#if LDC_LLVM_VER >= 2200
314314
target->createMCSubtargetInfo(triple, "help", "");
315315
#else
316316
target->createMCSubtargetInfo(cfg_triple, "help", "");
317-
#endif
317+
#endif
318318
} else {
319319
error(Loc(), "%s", errMsg.c_str());
320320
fatal();

driver/plugins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "llvm/Support/CommandLine.h"
2626
#include "llvm/Support/DynamicLibrary.h"
2727
#include "llvm/ADT/SmallVector.h"
28-
#if LDC_LLVM_VER >= 2300
28+
#if LDC_LLVM_VER >= 2200
2929
#include "llvm/Plugins/PassPlugin.h"
3030
#else
3131
#include "llvm/Passes/PassPlugin.h"

driver/targetmachine.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static std::string getTargetCPU(const llvm::Triple &triple) {
296296
static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU) {
297297
return llvm::StringSwitch<const char *>(CPU)
298298
.Case("strongarm", "v4")
299-
#if LDC_LLVM_VER >= 2300
299+
#if LDC_LLVM_VER >= 2200
300300
.Cases({"arm7tdmi", "arm7tdmi-s", "arm710t"}, "v4t")
301301
.Cases({"arm720t", "arm9", "arm9tdmi"}, "v4t")
302302
.Cases({"arm920", "arm920t", "arm922t"}, "v4t")
@@ -417,7 +417,11 @@ const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,
417417
}
418418
} else {
419419
std::string tempError;
420+
#if LDC_LLVM_VER >= 2200
421+
target = llvm::TargetRegistry::lookupTarget(triple, tempError);
422+
#else
420423
target = llvm::TargetRegistry::lookupTarget(triple.getTriple(), tempError);
424+
#endif
421425
if (!target) {
422426
errorMsg = "unable to get target for '" + triple.getTriple() +
423427
"', see -version and -mtriple.";

gen/ctfloat.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ void CTFloat::toAPFloat(const real_t src, APFloat &dst) {
8383
u.fp = src;
8484

8585
const unsigned sizeInBits = APFloat::getSizeInBits(*apSemantics);
86+
#if LDC_LLVM_VER >= 2200
87+
const APInt bits = APInt(sizeInBits, u.bits);
88+
#else
8689
const APInt bits = APInt(sizeInBits, numUint64Parts, u.bits);
90+
#endif
8791

8892
dst = APFloat(*apSemantics, bits);
8993
}

gen/pgo_ASTbased.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ llvm::cl::opt<bool, false, opts::FlagParser<bool>> enablePGOIndirectCalls(
3838
"pgo-indirect-calls", llvm::cl::ZeroOrMore, llvm::cl::Hidden,
3939
llvm::cl::desc("(*) Enable PGO of indirect calls"),
4040
llvm::cl::init(true));
41+
42+
uint64_t inLittleEndian(uint64_t x) {
43+
#if LDC_LLVM_VER >= 2200
44+
return llvm::support::endian::byte_swap<uint64_t>(x,
45+
llvm::endianness::little);
46+
#else
47+
return llvm::support::endian::byte_swap<uint64_t, llvm::endianness::little>(
48+
x);
49+
#endif
4150
}
51+
} // anonymous namespace
4252

4353
/// \brief Stable hasher for PGO region counters.
4454
///
@@ -115,9 +125,7 @@ class PGOHash {
115125

116126
// Pass through MD5 if enough work has built up.
117127
if (Count && Count % NumTypesPerWord == 0) {
118-
uint64_t Swapped =
119-
llvm::support::endian::byte_swap<uint64_t, llvm::endianness::little>(
120-
Working);
128+
uint64_t Swapped = inLittleEndian(Working);
121129
MD5.update(llvm::ArrayRef<uint8_t>((uint8_t *)&Swapped, sizeof(Swapped)));
122130
Working = 0;
123131
}
@@ -137,9 +145,7 @@ class PGOHash {
137145

138146
// Check for remaining work in Working.
139147
if (Working) {
140-
uint64_t Swapped =
141-
llvm::support::endian::byte_swap<uint64_t, llvm::endianness::little>(
142-
Working);
148+
uint64_t Swapped = inLittleEndian(Working);
143149
MD5.update(llvm::ArrayRef<uint8_t>((uint8_t *)&Swapped, sizeof(Swapped)));
144150
}
145151

runtime/druntime/src/ldc/intrinsics.di

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ else
2323
else version (LDC_LLVM_1901) enum LLVM_version = 1901;
2424
else version (LDC_LLVM_2001) enum LLVM_version = 2001;
2525
else version (LDC_LLVM_2101) enum LLVM_version = 2101;
26-
else version (LDC_LLVM_2200) enum LLVM_version = 2200;
26+
else version (LDC_LLVM_2201) enum LLVM_version = 2201;
2727
else version (LDC_LLVM_2300) enum LLVM_version = 2300;
2828
else static assert(false, "LDC LLVM version not supported");
2929

tests/plugins/addFuncEntryCall/addFuncEntryCallPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
#include "llvm/IR/Module.h"
1414
#include "llvm/IR/PassManager.h"
1515
#include "llvm/Passes/PassBuilder.h"
16+
#if LDC_LLVM_VER >= 2200
17+
#include "llvm/Plugins/PassPlugin.h"
18+
#else
1619
#include "llvm/Passes/PassPlugin.h"
20+
#endif
1721

1822
using namespace llvm;
1923

utils/split-file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ int main(int argc, const char **argv) {
183183
argc, argv,
184184
"Split input into multiple parts separated by regex '^(.|//)--- ' and "
185185
"extract the part specified by '^(.|//)--- <part>'\n",
186-
#if LDC_LLVM_VER >= 2300
186+
#if LDC_LLVM_VER >= 2200
187187
/*Errs*/nullptr,
188188
#endif
189189
/*VFS*/nullptr,

0 commit comments

Comments
 (0)