Files
c3c/test/test_suite/safe/deref.c3t
Christoffer Lerno 79a4b6855b - Detect unaligned loads #1951.
- Fix issue where aligned bitstructs did not store/load with the given alignment.
2025-02-10 22:07:15 +01:00

61 lines
2.0 KiB
Plaintext

// #safe: yes
// #target: macos-x64
module foo;
fn void main()
{
int* x;
int y = *x;
}
/* #expect: foo.ll
define void @foo.main() #0 {
entry:
%x = alloca ptr, align 8
%y = alloca i32, align 4
%taddr = alloca i64, align 8
%taddr2 = alloca i64, align 8
%varargslots = alloca [2 x %any], align 16
%indirectarg = alloca %"any[]", align 8
store ptr null, ptr %x, align 8
%0 = load ptr, ptr %x, align 8
%checknull = icmp eq ptr %0, null
%1 = call i1 @llvm.expect.i1(i1 %checknull, i1 false)
br i1 %1, label %panic, label %checkok
checkok: ; preds = %entry
%2 = ptrtoint ptr %0 to i64
%3 = urem i64 %2, 4
%4 = icmp ne i64 %3, 0
%5 = call i1 @llvm.expect.i1(i1 %4, i1 false)
br i1 %5, label %panic1, label %checkok3
checkok3: ; preds = %checkok
%6 = load i32, ptr %0, align 4
store i32 %6, ptr %y, align 4
ret void
panic: ; preds = %entry
%7 = load ptr, ptr @std.core.builtin.panic, align 8
call void %7(ptr @.panic_msg, i64 42, ptr @.file, i64 8, ptr @.func, i64 4, i32 6) #2
unreachable
panic1: ; preds = %checkok
store i64 4, ptr %taddr, align 8
%8 = insertvalue %any undef, ptr %taddr, 0
%9 = insertvalue %any %8, i64 ptrtoint (ptr @"$ct.ulong" to i64), 1
store i64 %3, ptr %taddr2, align 8
%10 = insertvalue %any undef, ptr %taddr2, 0
%11 = insertvalue %any %10, i64 ptrtoint (ptr @"$ct.ulong" to i64), 1
store %any %9, ptr %varargslots, align 16
%ptradd = getelementptr inbounds i8, ptr %varargslots, i64 16
store %any %11, ptr %ptradd, align 16
%12 = insertvalue %"any[]" undef, ptr %varargslots, 0
%"$$temp" = insertvalue %"any[]" %12, i64 2, 1
store %"any[]" %"$$temp", ptr %indirectarg, align 8
call void @std.core.builtin.panicf(ptr @.panic_msg.1, i64 94, ptr @.file, i64 8, ptr @.func, i64 4, i32 6, ptr byval(%"any[]") align 8 %indirectarg) #2
unreachable
}