mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 05:08:14 +00:00
Minor fix to OdinLLVMBuildTransmute
This commit is contained in:
+13
-2
@@ -2856,10 +2856,21 @@ LLVMValueRef OdinLLVMBuildTransmute(lbProcedure *p, LLVMValueRef val, LLVMTypeRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LLVMIsALoadInst(val)) {
|
if (LLVMIsALoadInst(val) && src_size <= dst_size) {
|
||||||
LLVMValueRef val_ptr = LLVMGetOperand(val, 0);
|
LLVMValueRef val_ptr = LLVMGetOperand(val, 0);
|
||||||
val_ptr = LLVMBuildPointerCast(p->builder, val_ptr, LLVMPointerType(dst_type, 0), "");
|
val_ptr = LLVMBuildPointerCast(p->builder, val_ptr, LLVMPointerType(dst_type, 0), "");
|
||||||
return LLVMBuildLoad(p->builder, val_ptr, "");
|
LLVMValueRef loaded_val = LLVMBuildLoad(p->builder, val_ptr, "");
|
||||||
|
|
||||||
|
// TODO(bill): Figure out why this doesn't work
|
||||||
|
// unsigned srca = cast(unsigned)LLVMConstIntGetZExtValue(LLVMAlignOf(src_type));
|
||||||
|
// unsigned dsta = cast(unsigned)LLVMConstIntGetZExtValue(LLVMAlignOf(dst_type));
|
||||||
|
|
||||||
|
unsigned srca = cast(unsigned)lb_alignof(src_type);
|
||||||
|
unsigned dsta = cast(unsigned)lb_alignof(dst_type);
|
||||||
|
|
||||||
|
LLVMSetAlignment(loaded_val, gb_min(srca, dsta));
|
||||||
|
|
||||||
|
return loaded_val;
|
||||||
} else {
|
} else {
|
||||||
GB_ASSERT(p->decl_block != p->curr_block);
|
GB_ASSERT(p->decl_block != p->curr_block);
|
||||||
LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block);
|
LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block);
|
||||||
|
|||||||
Reference in New Issue
Block a user