Files
c3c/test/test_suite/errors/general_error_regression.c3t

210 lines
5.6 KiB
C

// #target: macos-x64
module foo;
import std::io;
import libc;
fault Foo
{
X,
Y,
Z,
W,
W1
}
fault Foob
{
X1,
Y2
}
define Bar = distinct int;
enum MyEnum
{
A,
B
}
fn void Foo.hello(Foo *f)
{
io::printn("Hello from Foo");
}
fn void Bar.hello(Bar *b)
{
io::printn("Hello from Bar");
}
fn void MyEnum.hello(MyEnum *myenum)
{
io::printn("Hello from MyEnum");
}
fn void main()
{
Foo f = Foo.X;
Foo ef = Foo.Y;
anyerr x = f;
ulong z = (ulong)(x);
libc::printf("1: %p\n", z);
x = ef;
z = (ulong)(x);
libc::printf("2: %p\n", z);
x = Foo.W;
z = (ulong)(x);
libc::printf("21: %p\n", z);
x = Foo.W1;
z = (ulong)(x);
libc::printf("22: %p\n", z);
x = Foob.X1;
z = (ulong)(x);
libc::printf("3: %p\n", z);
x = Foob.Y2;
z = (ulong)(x);
libc::printf("4: %p\n", z);
Bar b;
MyEnum a = MyEnum.A;
f.hello();
b.hello();
a.hello();
}
/* #expect: foo.ll
define void @foo_Foo_hello(ptr %0) #0 {
entry:
%x = alloca ptr, align 8
%error_var = alloca i64, align 8
%retparam = alloca i64, align 8
%result = alloca %File, align 8
store ptr @.str.12, ptr %x, align 8
store i64 0, ptr %error_var, align 8
%1 = call ptr @std_io_stdout()
store ptr %1, ptr %result, align 8
%2 = load ptr, ptr %x, align 8
%3 = call i64 @std_io_File_printn(ptr %retparam, ptr %result, ptr %2, i64 14)
%not_err = icmp eq i64 %3, 0
br i1 %not_err, label %after_check, label %assign_optional
assign_optional: ; preds = %entry
store i64 %3, ptr %error_var, align 8
br label %noerr_block
after_check: ; preds = %entry
br label %noerr_block
noerr_block: ; preds = %after_check, %assign_optional
br label %voiderr
voiderr: ; preds = %noerr_block
ret void
}
define void @foo_Bar_hello(ptr %0) #0 {
entry:
%x = alloca ptr, align 8
%error_var = alloca i64, align 8
%retparam = alloca i64, align 8
%result = alloca %File, align 8
store ptr @.str.13, ptr %x, align 8
store i64 0, ptr %error_var, align 8
%1 = call ptr @std_io_stdout()
store ptr %1, ptr %result, align 8
%2 = load ptr, ptr %x, align 8
%3 = call i64 @std_io_File_printn(ptr %retparam, ptr %result, ptr %2, i64 14)
%not_err = icmp eq i64 %3, 0
br i1 %not_err, label %after_check, label %assign_optional
assign_optional: ; preds = %entry
store i64 %3, ptr %error_var, align 8
br label %noerr_block
after_check: ; preds = %entry
br label %noerr_block
noerr_block: ; preds = %after_check, %assign_optional
br label %voiderr
voiderr: ; preds = %noerr_block
ret void
}
define void @foo_MyEnum_hello(ptr %0) #0 {
entry:
%x = alloca ptr, align 8
%error_var = alloca i64, align 8
%retparam = alloca i64, align 8
%result = alloca %File, align 8
store ptr @.str.14, ptr %x, align 8
store i64 0, ptr %error_var, align 8
%1 = call ptr @std_io_stdout()
store ptr %1, ptr %result, align 8
%2 = load ptr, ptr %x, align 8
%3 = call i64 @std_io_File_printn(ptr %retparam, ptr %result, ptr %2, i64 17)
%not_err = icmp eq i64 %3, 0
br i1 %not_err, label %after_check, label %assign_optional
assign_optional: ; preds = %entry
store i64 %3, ptr %error_var, align 8
br label %noerr_block
after_check: ; preds = %entry
br label %noerr_block
noerr_block: ; preds = %after_check, %assign_optional
br label %voiderr
voiderr: ; preds = %noerr_block
ret void
}
define void @foo_main() #0 {
entry:
%f = alloca i64, align 8
%ef = alloca i64, align 8
%x = alloca i64, align 8
%z = alloca i64, align 8
%b = alloca i32, align 4
%a = alloca i32, align 4
store i64 ptrtoint (ptr @"foo_Foo$X" to i64), ptr %f, align 8
store i64 ptrtoint (ptr @"foo_Foo$Y" to i64), ptr %ef, align 8
%0 = load i64, ptr %f, align 8
store i64 %0, ptr %x, align 8
%1 = load i64, ptr %x, align 8
store i64 %1, ptr %z, align 8
%2 = load i64, ptr %z, align 8
%3 = call i32 (ptr, ...) @printf(ptr @.str, i64 %2)
%4 = load i64, ptr %ef, align 8
store i64 %4, ptr %x, align 8
%5 = load i64, ptr %x, align 8
store i64 %5, ptr %z, align 8
%6 = load i64, ptr %z, align 8
%7 = call i32 (ptr, ...) @printf(ptr @.str.7, i64 %6)
store i64 ptrtoint (ptr @"foo_Foo$W" to i64), ptr %x, align 8
%8 = load i64, ptr %x, align 8
store i64 %8, ptr %z, align 8
%9 = load i64, ptr %z, align 8
%10 = call i32 (ptr, ...) @printf(ptr @.str.8, i64 %9)
store i64 ptrtoint (ptr @"foo_Foo$W1" to i64), ptr %x, align 8
%11 = load i64, ptr %x, align 8
store i64 %11, ptr %z, align 8
%12 = load i64, ptr %z, align 8
%13 = call i32 (ptr, ...) @printf(ptr @.str.9, i64 %12)
store i64 ptrtoint (ptr @"foo_Foob$X1" to i64), ptr %x, align 8
%14 = load i64, ptr %x, align 8
store i64 %14, ptr %z, align 8
%15 = load i64, ptr %z, align 8
%16 = call i32 (ptr, ...) @printf(ptr @.str.10, i64 %15)
store i64 ptrtoint (ptr @"foo_Foob$Y2" to i64), ptr %x, align 8
%17 = load i64, ptr %x, align 8
store i64 %17, ptr %z, align 8
%18 = load i64, ptr %z, align 8
%19 = call i32 (ptr, ...) @printf(ptr @.str.11, i64 %18)
store i32 0, ptr %b, align 4
store i32 0, ptr %a, align 4
call void @foo_Foo_hello(ptr %f)
call void @foo_Bar_hello(ptr %b)
call void @foo_MyEnum_hello(ptr %a)
ret void
}