Skip to content

Commit aacda96

Browse files
committed
[LLVM 21] fix calls to llvm.lifetime.start
1 parent 9db6d95 commit aacda96

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

gen/llvmhelpers.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -897,30 +897,28 @@ void DtoVarDeclaration(VarDeclaration *vd) {
897897

898898
// We also allocate a variable for zero-sized variables, because they are technically not `null` when loaded.
899899
// The x86_64 ABI "loads" zero-sized function arguments, and without an allocation ASan will report an error (Github #4816).
900-
llvm::Value *allocainst;
901-
bool isRealAlloca = false;
902900
LLType *lltype = DtoType(type); // void for noreturn
903901
if (lltype->isVoidTy()) {
904-
allocainst = getNullPtr();
905-
} else if (type != vd->type) {
902+
irLocal->value = getNullPtr();
903+
return;
904+
}
905+
906+
llvm::AllocaInst *allocainst;
907+
908+
if (type != vd->type) {
906909
allocainst = DtoAlloca(type, vd->toChars());
907-
isRealAlloca = true;
908910
} else {
909911
allocainst = DtoAlloca(vd, vd->toChars());
910-
isRealAlloca = true;
911912
}
912913

913914
irLocal->value = allocainst;
914915

915916
if (!lltype->isVoidTy())
916917
gIR->DBuilder.EmitLocalVariable(allocainst, vd);
917918

918-
// Lifetime annotation is only valid on alloca.
919-
if (isRealAlloca) {
920-
// The lifetime of a stack variable starts from the point it is declared
921-
gIR->funcGen().localVariableLifetimeAnnotator.addLocalVariable(
922-
allocainst, DtoConstUlong(size(type)));
923-
}
919+
// The lifetime of a stack variable starts from the point it is declared
920+
gIR->funcGen().localVariableLifetimeAnnotator.addLocalVariable(
921+
allocainst, DtoConstUlong(size(type)));
924922
}
925923

926924
IF_LOG Logger::cout() << "llvm value for decl: " << *getIrLocal(vd)->value

gen/variable_lifetime.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ LocalVariableLifetimeAnnotator::LocalVariableLifetimeAnnotator(IRState &irs)
3737

3838
void LocalVariableLifetimeAnnotator::pushScope() { scopes.emplace_back(); }
3939

40-
void LocalVariableLifetimeAnnotator::addLocalVariable(llvm::Value *address,
40+
void LocalVariableLifetimeAnnotator::addLocalVariable(llvm::AllocaInst *address,
4141
llvm::Value *size) {
4242
assert(address);
4343
assert(size);
@@ -52,8 +52,13 @@ void LocalVariableLifetimeAnnotator::addLocalVariable(llvm::Value *address,
5252
scopes.back().variables.emplace_back(size, address);
5353

5454
// Emit lifetime start
55-
irs.CreateCallOrInvoke(getLLVMLifetimeStartFn(), {size, address}, "",
56-
true /*nothrow*/);
55+
irs.CreateCallOrInvoke(getLLVMLifetimeStartFn(),
56+
#if LDC_LLVM_VER >= 2100
57+
{address},
58+
#else
59+
{size, address},
60+
#endif
61+
"", true /*nothrow*/);
5762
}
5863

5964
// Emits end-of-lifetime annotation for all variables in current scope.
@@ -67,8 +72,14 @@ void LocalVariableLifetimeAnnotator::popScope() {
6772

6873
assert(address);
6974

70-
irs.CreateCallOrInvoke(getLLVMLifetimeEndFn(), {size, address}, "",
71-
true /*nothrow*/);
75+
irs.CreateCallOrInvoke(getLLVMLifetimeEndFn(),
76+
#if LDC_LLVM_VER >= 2100
77+
{address},
78+
#else
79+
{size, address},
80+
#endif
81+
"", true /*nothrow*/);
82+
7283
}
7384
scopes.pop_back();
7485
}

gen/variable_lifetime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ namespace llvm {
2121
class Function;
2222
class Type;
2323
class Value;
24+
class AllocaInst;
2425
}
2526
struct IRState;
2627

2728
struct LocalVariableLifetimeAnnotator {
2829
struct LocalVariableScope {
29-
std::vector<std::pair<llvm::Value *, llvm::Value *>> variables;
30+
std::vector<std::pair<llvm::Value *, llvm::AllocaInst *>> variables;
3031
};
3132
/// Stack of scopes, each scope can have multiple variables.
3233
std::vector<LocalVariableScope> scopes;
@@ -52,5 +53,5 @@ struct LocalVariableLifetimeAnnotator {
5253
void popScope();
5354

5455
/// Register a new local variable for lifetime annotation.
55-
void addLocalVariable(llvm::Value *address, llvm::Value *size);
56+
void addLocalVariable(llvm::AllocaInst *address, llvm::Value *size);
5657
};

runtime/druntime/src/ldc/intrinsics.di

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ else version (LDC_LLVM_1801) enum LLVM_version = 1801;
2727
else version (LDC_LLVM_1901) enum LLVM_version = 1901;
2828
else version (LDC_LLVM_2001) enum LLVM_version = 2001;
2929
else version (LDC_LLVM_2100) enum LLVM_version = 2100;
30+
else version (LDC_LLVM_2200) enum LLVM_version = 2200;
3031
else static assert(false, "LDC LLVM version not supported");
3132

3233
enum LLVM_atleast(int major) = (LLVM_version >= major * 100);

0 commit comments

Comments
 (0)