mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Fix alignment.
This commit is contained in:
@@ -2371,7 +2371,12 @@ static inline void llvm_emit_deref(GenContext *c, BEValue *value, Expr *inner, T
|
||||
llvm_emit_expr(c, value, inner);
|
||||
llvm_value_rvalue(c, value);
|
||||
AlignSize alignment = type_abi_alignment(type);
|
||||
if (safe_mode_enabled() && !expr_is_const(inner))
|
||||
bool is_const = expr_is_const(inner);
|
||||
if (is_const)
|
||||
{
|
||||
alignment = type_min_alignment(inner->const_expr.ptr, alignment);
|
||||
}
|
||||
if (safe_mode_enabled() && !is_const)
|
||||
{
|
||||
LLVMValueRef check = LLVMBuildICmp(c->builder, LLVMIntEQ, value->value, llvm_get_zero(c, inner->type), "checknull");
|
||||
scratch_buffer_clear();
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
module main;
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
|
||||
fn void main()
|
||||
fn int main()
|
||||
{
|
||||
int x = *(int*)1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%0 = load i32, ptr inttoptr (i64 1 to ptr), align 1
|
||||
store i32 %0, ptr %x, align 4
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user