fix LLVM assert in use_begin

This commit is contained in:
oltolm
2026-04-05 16:55:30 +02:00
committed by Elad
parent 09554c43ba
commit fb194241d5
+28 -5
View File
@@ -244,10 +244,13 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type, std::so
} }
} }
for (auto it = source_val->use_begin(); it != source_val->use_end(); ++it) // Skip use iteration for values that don't have use lists
#if LLVM_VERSION_MAJOR >= 21
if (source_val->hasUseList())
#endif
{
for (llvm::Value* it_val : source_val->uses())
{ {
llvm::Value* it_val = *it;
if (!it_val) if (!it_val)
{ {
continue; continue;
@@ -268,6 +271,14 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type, std::so
return bci; return bci;
} }
// Check if bci has use list before accessing use_begin()
#if LLVM_VERSION_MAJOR >= 21
if (!bci->hasUseList())
{
break;
}
#endif
if (bci->use_begin() == bci->use_end()) if (bci->use_begin() == bci->use_end())
{ {
break; break;
@@ -276,6 +287,7 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type, std::so
bci = llvm::dyn_cast_or_null<llvm::CastInst>(*bci->use_begin()); bci = llvm::dyn_cast_or_null<llvm::CastInst>(*bci->use_begin());
} }
} }
}
// Do bitcast on the source // Do bitcast on the source
@@ -553,14 +565,25 @@ void cpu_translator::erase_stores(llvm::ArrayRef<llvm::Value*> args)
{ {
for (auto v : args) for (auto v : args)
{ {
for (auto it = v->use_begin(); it != v->use_end(); ++it) // Skip use iteration for values that don't have use lists
#if LLVM_VERSION_MAJOR >= 21
if (!v->hasUseList())
continue;
#endif
for (llvm::Value* i : v->uses())
{ {
llvm::Value* i = *it;
llvm::CastInst* bci = nullptr; llvm::CastInst* bci = nullptr;
// Walk through bitcasts // Walk through bitcasts
while (i && (bci = llvm::dyn_cast<llvm::CastInst>(i)) && bci->getOpcode() == llvm::Instruction::BitCast) while (i && (bci = llvm::dyn_cast<llvm::CastInst>(i)) && bci->getOpcode() == llvm::Instruction::BitCast)
{ {
// Check if bci has use list before accessing use_begin()
#if LLVM_VERSION_MAJOR >= 21
if (!bci->hasUseList())
break;
#endif
i = *bci->use_begin(); i = *bci->use_begin();
} }