LLVM: Add source location for bitcast error

This commit is contained in:
Elad 2026-04-03 23:23:00 +03:00
parent ceb2168375
commit aa841ac332
3 changed files with 8 additions and 3 deletions

View File

@ -493,6 +493,10 @@ inline FT build_function_asm(std::string_view name, F&& builder, ::jit_runtime*
return reinterpret_cast<FT>(uptr(result)); return reinterpret_cast<FT>(uptr(result));
} }
#if defined(__INTELLISENSE__) && !defined(LLVM_AVAILABLE)
#define LLVM_AVAILABLE
#endif
#ifdef LLVM_AVAILABLE #ifdef LLVM_AVAILABLE
namespace llvm namespace llvm

View File

@ -210,7 +210,7 @@ void cpu_translator::initialize(llvm::LLVMContext& context, llvm::ExecutionEngin
#endif #endif
} }
llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type) const llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type, std::source_location src_loc) const
{ {
uint s1 = type->getScalarSizeInBits(); uint s1 = type->getScalarSizeInBits();
uint s2 = val->getType()->getScalarSizeInBits(); uint s2 = val->getType()->getScalarSizeInBits();
@ -222,7 +222,7 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type) const
if (s1 != s2) if (s1 != s2)
{ {
fmt::throw_exception("cpu_translator::bitcast(): incompatible type sizes (%u vs %u)", s1, s2); fmt::throw_exception("cpu_translator::bitcast(): incompatible type sizes (%u vs %u)\nCalled from: %s", s1, s2, src_loc);
} }
if (val->getType() == type) if (val->getType() == type)

View File

@ -43,6 +43,7 @@
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include <source_location>
// Helper function // Helper function
llvm::Value* peek_through_bitcasts(llvm::Value*); llvm::Value* peek_through_bitcasts(llvm::Value*);
@ -3239,7 +3240,7 @@ public:
} }
// Bitcast with immediate constant folding // Bitcast with immediate constant folding
llvm::Value* bitcast(llvm::Value* val, llvm::Type* type) const; llvm::Value* bitcast(llvm::Value* val, llvm::Type* type, std::source_location src_loc = std::source_location::current()) const;
template <typename T> template <typename T>
llvm::Value* bitcast(llvm::Value* val) llvm::Value* bitcast(llvm::Value* val)