diff --git a/src/irgenerator/GenTargetDependent.cpp b/src/irgenerator/GenTargetDependent.cpp index aa58db7ae..741e9de92 100644 --- a/src/irgenerator/GenTargetDependent.cpp +++ b/src/irgenerator/GenTargetDependent.cpp @@ -15,11 +15,10 @@ std::string IRGenerator::getSysCallAsmString(uint8_t numRegs) const { if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) { static constexpr const char *regs[] = {"%rax", "%rdi", "%rsi", "%rdx", "%r10", "%r8", "%r9"}; for (uint8_t i = 0; i < numRegs; i++) { - // macOS syscall numbers are offset by 0x2000000 + asmString << "movq $" << std::to_string(i) << ", " << regs[i] << "\n"; + // macOS x86_64 syscall numbers are offset by 0x2000000 (BSD syscall class). "$$" emits a literal '$'. if (i == 0) - asmString << "movq $(" << std::to_string(0x2000000) << " + " << std::to_string(i) << "), " << regs[i] << "\n"; - else - asmString << "movq $" << std::to_string(i) << ", " << regs[i] << "\n"; + asmString << "addq $$" << std::to_string(0x2000000) << ", %rax\n"; } asmString << "syscall\n"; } else if (targetTriple.isAArch64()) { diff --git a/std/os/syscall_darwin_x86_64.spice b/std/os/syscall_darwin_x86_64.spice new file mode 100644 index 000000000..cce34771e --- /dev/null +++ b/std/os/syscall_darwin_x86_64.spice @@ -0,0 +1,29 @@ +// Syscall numbers +public const unsigned short SYSCALL_READ = 3us; +public const unsigned short SYSCALL_WRITE = 4us; +public const unsigned short SYSCALL_OPEN = 5us; +public const unsigned short SYSCALL_CLOSE = 6us; +public const unsigned short SYSCALL_WAIT4 = 7us; +public const unsigned short SYSCALL_LINK = 9us; +public const unsigned short SYSCALL_UNLINK = 10us; +public const unsigned short SYSCALL_CHDIR = 12us; +public const unsigned short SYSCALL_FCHDIR = 13us; +public const unsigned short SYSCALL_MKNOD = 14us; +public const unsigned short SYSCALL_CHMOD = 15us; +public const unsigned short SYSCALL_CHOWN = 16us; +public const unsigned short SYSCALL_GETFSSTAT = 18us; +public const unsigned short SYSCALL_GETDTABLESIZE = 19us; +public const unsigned short SYSCALL_DUP = 20us; +public const unsigned short SYSCALL_PIPE = 21us; +public const unsigned short SYSCALL_GETPID = 39us; +public const unsigned short SYSCALL_KILL = 37us; +public const unsigned short SYSCALL_CREATE = 57us; +public const unsigned short SYSCALL_REMOVE = 58us; +public const unsigned short SYSCALL_EXECVE = 59us; +public const unsigned short SYSCALL_CHDIR_ROOT = 61us; +public const unsigned short SYSCALL_FCNTL = 62us; +public const unsigned short SYSCALL_DUP2 = 90us; +public const unsigned short SYSCALL_READV = 120us; +public const unsigned short SYSCALL_WRITEV = 121us; +public const unsigned short SYSCALL_PREAD = 140us; +public const unsigned short SYSCALL_PWRITE = 141us; diff --git a/test/test-files/benchmark/success-pidigits/ir-code-macos-amd64.ll b/test/test-files/benchmark/success-pidigits/ir-code-macos-amd64.ll new file mode 100644 index 000000000..8d92362d9 --- /dev/null +++ b/test/test-files/benchmark/success-pidigits/ir-code-macos-amd64.ll @@ -0,0 +1,173 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [3 x i8] c"%d\00", align 4 +@printf.str.1 = private unnamed_addr constant [2 x i8] c".\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %q = alloca i64, align 8 + %q_new = alloca i64, align 8 + %r = alloca i64, align 8 + %r_new = alloca i64, align 8 + %t = alloca i64, align 8 + %t_new = alloca i64, align 8 + %k = alloca i64, align 8 + %k_new = alloca i64, align 8 + %m = alloca i64, align 8 + %x = alloca i64, align 8 + %iterations = alloca i32, align 4 + %printedDigits = alloca i32, align 4 + %i = alloca i32, align 4 + store i32 0, ptr %result, align 4 + store i64 1, ptr %q, align 8 + store i64 0, ptr %q_new, align 8 + store i64 0, ptr %r, align 8 + store i64 0, ptr %r_new, align 8 + store i64 1, ptr %t, align 8 + store i64 0, ptr %t_new, align 8 + store i64 1, ptr %k, align 8 + store i64 0, ptr %k_new, align 8 + store i64 3, ptr %m, align 8 + store i64 3, ptr %x, align 8 + store i32 20, ptr %iterations, align 4 + store i32 0, ptr %printedDigits, align 4 + store i32 0, ptr %i, align 4 + br label %for.head.L19 + +for.head.L19: ; preds = %for.tail.L19, %0 + %1 = load i32, ptr %i, align 4 + %2 = load i32, ptr %iterations, align 4 + %3 = icmp slt i32 %1, %2 + br i1 %3, label %for.body.L19, label %for.exit.L19 + +for.body.L19: ; preds = %for.head.L19 + %4 = load i64, ptr %q, align 8 + %5 = mul nsw i64 4, %4 + %6 = load i64, ptr %r, align 8 + %7 = add nsw i64 %5, %6 + %8 = load i64, ptr %t, align 8 + %9 = sub nsw i64 %7, %8 + %10 = load i64, ptr %m, align 8 + %11 = load i64, ptr %t, align 8 + %12 = mul nsw i64 %10, %11 + %13 = icmp slt i64 %9, %12 + br i1 %13, label %if.then.L20, label %if.else.L20 + +if.then.L20: ; preds = %for.body.L19 + %14 = load i64, ptr %m, align 8 + %15 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i64 noundef %14) + %16 = load i32, ptr %printedDigits, align 4 + %17 = icmp eq i32 %16, 0 + br i1 %17, label %if.then.L22, label %if.exit.L22 + +if.then.L22: ; preds = %if.then.L20 + %18 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1) + br label %if.exit.L22 + +if.exit.L22: ; preds = %if.then.L22, %if.then.L20 + %19 = load i32, ptr %printedDigits, align 4 + %20 = add nsw i32 %19, 1 + store i32 %20, ptr %printedDigits, align 4 + %21 = load i64, ptr %q, align 8 + %22 = mul nsw i64 10, %21 + store i64 %22, ptr %q_new, align 8 + %23 = load i64, ptr %m, align 8 + %24 = load i64, ptr %t, align 8 + %25 = mul nsw i64 %23, %24 + %26 = load i64, ptr %r, align 8 + %27 = sub nsw i64 %26, %25 + %28 = mul nsw i64 10, %27 + store i64 %28, ptr %r_new, align 8 + %29 = load i64, ptr %q, align 8 + %30 = mul nsw i64 3, %29 + %31 = load i64, ptr %r, align 8 + %32 = add nsw i64 %30, %31 + %33 = mul nsw i64 10, %32 + %34 = load i64, ptr %t, align 8 + %35 = sdiv i64 %33, %34 + %36 = load i64, ptr %m, align 8 + %37 = mul nsw i64 10, %36 + %38 = sub nsw i64 %35, %37 + store i64 %38, ptr %m, align 8 + %39 = load i64, ptr %q_new, align 8 + store i64 %39, ptr %q, align 8 + %40 = load i64, ptr %r_new, align 8 + store i64 %40, ptr %r, align 8 + br label %if.exit.L20 + +if.else.L20: ; preds = %for.body.L19 + %41 = load i64, ptr %q, align 8 + %42 = load i64, ptr %k, align 8 + %43 = mul nsw i64 %41, %42 + store i64 %43, ptr %q_new, align 8 + %44 = load i64, ptr %q, align 8 + %45 = mul nsw i64 2, %44 + %46 = load i64, ptr %r, align 8 + %47 = add nsw i64 %45, %46 + %48 = load i64, ptr %x, align 8 + %49 = mul nsw i64 %47, %48 + store i64 %49, ptr %r_new, align 8 + %50 = load i64, ptr %t, align 8 + %51 = load i64, ptr %x, align 8 + %52 = mul nsw i64 %50, %51 + store i64 %52, ptr %t_new, align 8 + %53 = load i64, ptr %k, align 8 + %54 = add nsw i64 %53, 1 + store i64 %54, ptr %k_new, align 8 + %55 = load i64, ptr %k, align 8 + %56 = mul nsw i64 7, %55 + %57 = add nsw i64 %56, 2 + %58 = load i64, ptr %q, align 8 + %59 = mul nsw i64 %58, %57 + %60 = load i64, ptr %r, align 8 + %61 = load i64, ptr %x, align 8 + %62 = mul nsw i64 %60, %61 + %63 = add nsw i64 %59, %62 + %64 = load i64, ptr %t, align 8 + %65 = load i64, ptr %x, align 8 + %66 = mul nsw i64 %64, %65 + %67 = sdiv i64 %63, %66 + store i64 %67, ptr %m, align 8 + %68 = load i64, ptr %x, align 8 + %69 = add nsw i64 %68, 2 + store i64 %69, ptr %x, align 8 + %70 = load i64, ptr %q_new, align 8 + store i64 %70, ptr %q, align 8 + %71 = load i64, ptr %r_new, align 8 + store i64 %71, ptr %r, align 8 + %72 = load i64, ptr %t_new, align 8 + store i64 %72, ptr %t, align 8 + %73 = load i64, ptr %k_new, align 8 + store i64 %73, ptr %k, align 8 + br label %if.exit.L20 + +if.exit.L20: ; preds = %if.else.L20, %if.exit.L22 + br label %for.tail.L19 + +for.tail.L19: ; preds = %if.exit.L20 + %74 = load i32, ptr %i, align 4 + %75 = add nsw i32 %74, 1 + store i32 %75, ptr %i, align 4 + br label %for.head.L19 + +for.exit.L19: ; preds = %for.head.L19 + %76 = load i32, ptr %result, align 4 + ret i32 %76 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/arrays/success-arrays-multidimensional/ir-code-macos-amd64.ll b/test/test-files/irgenerator/arrays/success-arrays-multidimensional/ir-code-macos-amd64.ll new file mode 100644 index 000000000..3719ebb62 --- /dev/null +++ b/test/test-files/irgenerator/arrays/success-arrays-multidimensional/ir-code-macos-amd64.ll @@ -0,0 +1,79 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [15 x i8] c"Cell [1,3]: %d\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %a = alloca [10 x [10 x i32]], align 4 + %i = alloca i32, align 4 + %j = alloca i32, align 4 + store i32 0, ptr %result, align 4 + store [10 x [10 x i32]] zeroinitializer, ptr %a, align 4 + store i32 0, ptr %i, align 4 + br label %for.head.L3 + +for.head.L3: ; preds = %for.tail.L3, %0 + %1 = load i32, ptr %i, align 4 + %2 = icmp slt i32 %1, 10 + br i1 %2, label %for.body.L3, label %for.exit.L3 + +for.body.L3: ; preds = %for.head.L3 + store i32 0, ptr %j, align 4 + br label %for.head.L4 + +for.head.L4: ; preds = %for.tail.L4, %for.body.L3 + %3 = load i32, ptr %j, align 4 + %4 = icmp slt i32 %3, 10 + br i1 %4, label %for.body.L4, label %for.exit.L4 + +for.body.L4: ; preds = %for.head.L4 + %5 = load i32, ptr %i, align 4 + %6 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i64 0, i32 %5 + %7 = load i32, ptr %j, align 4 + %8 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i32 %7 + %9 = load i32, ptr %i, align 4 + %10 = load i32, ptr %j, align 4 + %11 = mul nsw i32 %9, %10 + store i32 %11, ptr %8, align 4 + br label %for.tail.L4 + +for.tail.L4: ; preds = %for.body.L4 + %12 = load i32, ptr %j, align 4 + %13 = add nsw i32 %12, 1 + store i32 %13, ptr %j, align 4 + br label %for.head.L4 + +for.exit.L4: ; preds = %for.head.L4 + br label %for.tail.L3 + +for.tail.L3: ; preds = %for.exit.L4 + %14 = load i32, ptr %i, align 4 + %15 = add nsw i32 %14, 1 + store i32 %15, ptr %i, align 4 + br label %for.head.L3 + +for.exit.L3: ; preds = %for.head.L3 + %16 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i64 0, i32 1 + %17 = getelementptr inbounds [10 x i32], ptr %16, i64 0, i32 3 + %18 = load i32, ptr %17, align 4 + %19 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %18) + %20 = load i32, ptr %result, align 4 + ret i32 %20 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/builtins/success-typeid/ir-code-O2-macos-amd64.ll b/test/test-files/irgenerator/builtins/success-typeid/ir-code-O2-macos-amd64.ll new file mode 100644 index 000000000..4a4e13554 --- /dev/null +++ b/test/test-files/irgenerator/builtins/success-typeid/ir-code-O2-macos-amd64.ll @@ -0,0 +1,26 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() local_unnamed_addr #0 { + %1 = tail call noundef i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @printf.str.1, i64 noundef 5535379567501308475) + %2 = tail call noundef i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @printf.str.1, i64 noundef 5535379567501308475) + ret i32 0 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/builtins/success-typeid/ir-code-macos-amd64.ll b/test/test-files/irgenerator/builtins/success-typeid/ir-code-macos-amd64.ll new file mode 100644 index 000000000..06f7f6d3b --- /dev/null +++ b/test/test-files/irgenerator/builtins/success-typeid/ir-code-macos-amd64.ll @@ -0,0 +1,30 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4 +@printf.str.1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 + %1 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i64 noundef 5535379567501308475) + %2 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1, i64 noundef 5535379567501308475) + %3 = load i32, ptr %result, align 4 + ret i32 %3 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/generics/success-generic-functions2/ir-code-macos-amd64.ll b/test/test-files/irgenerator/generics/success-generic-functions2/ir-code-macos-amd64.ll new file mode 100644 index 000000000..8feeff897 --- /dev/null +++ b/test/test-files/irgenerator/generics/success-generic-functions2/ir-code-macos-amd64.ll @@ -0,0 +1,168 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [10 x i8] c"Data: %d\0A\00", align 4 +@anon.array.0 = private unnamed_addr constant [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7] +@anon.array.1 = private unnamed_addr constant [4 x i64] [i64 10, i64 12, i64 14, i64 16] +@printf.str.1 = private unnamed_addr constant [17 x i8] c"Results: %d, %d\0A\00", align 4 + +define private noundef i32 @_Z10sumNumbersIsEiPsl(ptr noundef %0, i64 noundef %1) { + %result = alloca i32, align 4 + %numberArray = alloca ptr, align 8 + %arrayLength = alloca i64, align 8 + %i = alloca i64, align 8 + store ptr %0, ptr %numberArray, align 8 + store i64 %1, ptr %arrayLength, align 8 + store i32 0, ptr %result, align 4 + store i64 0, ptr %i, align 8 + br label %for.head.L6 + +for.head.L6: ; preds = %for.tail.L6, %2 + %3 = load i64, ptr %i, align 8 + %4 = load i64, ptr %arrayLength, align 8 + %5 = icmp slt i64 %3, %4 + br i1 %5, label %for.body.L6, label %for.exit.L6 + +for.body.L6: ; preds = %for.head.L6 + %6 = load i64, ptr %i, align 8 + %7 = load ptr, ptr %numberArray, align 8 + %8 = getelementptr inbounds i16, ptr %7, i64 %6 + %9 = load i16, ptr %8, align 2 + %10 = sext i16 %9 to i32 + %11 = load i32, ptr %result, align 4 + %12 = add nsw i32 %11, %10 + store i32 %12, ptr %result, align 4 + br label %for.tail.L6 + +for.tail.L6: ; preds = %for.body.L6 + %13 = load i64, ptr %i, align 8 + %14 = add nsw i64 %13, 1 + store i64 %14, ptr %i, align 8 + br label %for.head.L6 + +for.exit.L6: ; preds = %for.head.L6 + %15 = load i32, ptr %result, align 4 + ret i32 %15 +} + +define private noundef i32 @_Z10sumNumbersIlEiPll(ptr noundef %0, i64 noundef %1) { + %result = alloca i32, align 4 + %numberArray = alloca ptr, align 8 + %arrayLength = alloca i64, align 8 + %i = alloca i64, align 8 + store ptr %0, ptr %numberArray, align 8 + store i64 %1, ptr %arrayLength, align 8 + store i32 0, ptr %result, align 4 + store i64 0, ptr %i, align 8 + br label %for.head.L6 + +for.head.L6: ; preds = %for.tail.L6, %2 + %3 = load i64, ptr %i, align 8 + %4 = load i64, ptr %arrayLength, align 8 + %5 = icmp slt i64 %3, %4 + br i1 %5, label %for.body.L6, label %for.exit.L6 + +for.body.L6: ; preds = %for.head.L6 + %6 = load i64, ptr %i, align 8 + %7 = load ptr, ptr %numberArray, align 8 + %8 = getelementptr inbounds i64, ptr %7, i64 %6 + %9 = load i64, ptr %8, align 8 + %10 = trunc i64 %9 to i32 + %11 = load i32, ptr %result, align 4 + %12 = add nsw i32 %11, %10 + store i32 %12, ptr %result, align 4 + br label %for.tail.L6 + +for.tail.L6: ; preds = %for.body.L6 + %13 = load i64, ptr %i, align 8 + %14 = add nsw i64 %13, 1 + store i64 %14, ptr %i, align 8 + br label %for.head.L6 + +for.exit.L6: ; preds = %for.head.L6 + %15 = load i32, ptr %result, align 4 + ret i32 %15 +} + +define private void @_Z9printDataIPiEvlPi(i64 noundef %0, ptr noundef %1) { + %arrayLength = alloca i64, align 8 + %list = alloca ptr, align 8 + %i = alloca i64, align 8 + store i64 %0, ptr %arrayLength, align 8 + store ptr %1, ptr %list, align 8 + store i64 0, ptr %i, align 8 + br label %for.head.L12 + +for.head.L12: ; preds = %for.tail.L12, %2 + %3 = load i64, ptr %i, align 8 + %4 = load i64, ptr %arrayLength, align 8 + %5 = icmp slt i64 %3, %4 + br i1 %5, label %for.body.L12, label %for.exit.L12 + +for.body.L12: ; preds = %for.head.L12 + %6 = load i64, ptr %i, align 8 + %7 = load ptr, ptr %list, align 8 + %8 = getelementptr inbounds i32, ptr %7, i64 %6 + %9 = load i32, ptr %8, align 4 + %10 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %9) + br label %for.tail.L12 + +for.tail.L12: ; preds = %for.body.L12 + %11 = load i64, ptr %i, align 8 + %12 = add nsw i64 %11, 1 + store i64 %12, ptr %i, align 8 + br label %for.head.L12 + +for.exit.L12: ; preds = %for.head.L12 + ret void +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #0 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #1 { + %result = alloca i32, align 4 + %numberList1 = alloca [7 x i16], align 2 + %result1 = alloca i32, align 4 + %numberList2 = alloca [4 x i64], align 8 + %result2 = alloca i32, align 4 + %1 = alloca [2 x i32], align 4 + %resultList = alloca [2 x i32], align 4 + store i32 0, ptr %result, align 4 + store [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7], ptr %numberList1, align 2 + %2 = getelementptr inbounds [7 x i16], ptr %numberList1, i64 0, i32 0 + %3 = call noundef i32 @_Z10sumNumbersIsEiPsl(ptr noundef %2, i64 noundef 7) + store i32 %3, ptr %result1, align 4 + store [4 x i64] [i64 10, i64 12, i64 14, i64 16], ptr %numberList2, align 8 + %4 = getelementptr inbounds [4 x i64], ptr %numberList2, i64 0, i32 0 + %5 = call noundef i32 @_Z10sumNumbersIlEiPll(ptr noundef %4, i64 noundef 4) + store i32 %5, ptr %result2, align 4 + %6 = getelementptr inbounds [2 x i32], ptr %1, i64 0 + %7 = load i32, ptr %result1, align 4 + store i32 %7, ptr %6, align 4 + %8 = load i32, ptr %result2, align 4 + %9 = getelementptr inbounds i32, ptr %6, i64 1 + store i32 %8, ptr %9, align 4 + %10 = load [2 x i32], ptr %1, align 4 + store [2 x i32] %10, ptr %resultList, align 4 + %11 = getelementptr inbounds [2 x i32], ptr %resultList, i64 0, i32 0 + call void @_Z9printDataIPiEvlPi(i64 noundef 2, ptr noundef %11) + %12 = load i32, ptr %result1, align 4 + %13 = load i32, ptr %result2, align 4 + %14 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1, i32 noundef %12, i32 noundef %13) + %15 = load i32, ptr %result, align 4 + ret i32 %15 +} + +attributes #0 = { nofree nounwind } +attributes #1 = { mustprogress noinline norecurse nounwind optnone uwtable } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/instrumentation/success-asan-and-dbg-info/ir-code-macos-amd64.ll b/test/test-files/irgenerator/instrumentation/success-asan-and-dbg-info/ir-code-macos-amd64.ll new file mode 100644 index 000000000..8afd5c634 --- /dev/null +++ b/test/test-files/irgenerator/instrumentation/success-asan-and-dbg-info/ir-code-macos-amd64.ll @@ -0,0 +1,418 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@__asan_option_detect_stack_use_after_return = external global i32 +@___asan_gen_stack = private unnamed_addr constant [16 x i8] c"1 32 8 6 iPtr:4\00", align 1 +@llvm.used = appending global [1 x ptr] [ptr @asan.module_ctor], section "llvm.metadata" +@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @asan.module_ctor, ptr null }] + +; Function Attrs: mustprogress noinline norecurse nounwind optnone sanitize_address uwtable +define dso_local noundef i32 @main() #0 !dbg !10 { + %result = alloca i32, align 4 + %asan_local_stack_base = alloca i64, align 8 + %1 = load i32, ptr @__asan_option_detect_stack_use_after_return, align 4 + %2 = icmp ne i32 %1, 0 + br i1 %2, label %3, label %5 + +3: ; preds = %0 + %4 = call i64 @__asan_stack_malloc_0(i64 64) + br label %5 + +5: ; preds = %0, %3 + %6 = phi i64 [ 0, %0 ], [ %4, %3 ] + %7 = inttoptr i64 %6 to ptr + %8 = icmp eq i64 %6, 0 + br i1 %8, label %9, label %10 + +9: ; preds = %5 + %MyAlloca = alloca i8, i64 64, align 32 + br label %10 + +10: ; preds = %5, %9 + %11 = phi ptr [ %7, %5 ], [ %MyAlloca, %9 ] + store ptr %11, ptr %asan_local_stack_base, align 8 + %12 = getelementptr i8, ptr %11, i64 32 + store i64 1102416563, ptr %11, align 8 + %13 = getelementptr i8, ptr %11, i64 8 + store i64 ptrtoint (ptr @___asan_gen_stack to i64), ptr %13, align 8 + %14 = getelementptr i8, ptr %11, i64 16 + store i64 ptrtoint (ptr @main to i64), ptr %14, align 8 + %15 = ptrtoint ptr %11 to i64 + %16 = lshr i64 %15, 3 + %17 = or i64 %16, 17592186044416 + %18 = add i64 %17, 0 + %19 = inttoptr i64 %18 to ptr + store i64 -868082052615769615, ptr %19, align 1 + call void @llvm.lifetime.start.p0(ptr %result), !dbg !16 + #dbg_declare(ptr %result, !17, !DIExpression(), !16) + store i32 0, ptr %result, align 4, !dbg !16 + %20 = call ptr @_Z12sAllocUnsafem(i64 4), !dbg !18 + %21 = ptrtoint ptr %20 to i64, !dbg !18 + %22 = lshr i64 %21, 3, !dbg !18 + %23 = or i64 %22, 17592186044416, !dbg !18 + %24 = inttoptr i64 %23 to ptr, !dbg !18 + %25 = load i8, ptr %24, align 1, !dbg !18 + %26 = icmp ne i8 %25, 0, !dbg !18 + br i1 %26, label %27, label %33, !dbg !18, !prof !19 + +27: ; preds = %10 + %28 = and i64 %21, 7, !dbg !18 + %29 = add i64 %28, 3, !dbg !18 + %30 = trunc i64 %29 to i8, !dbg !18 + %31 = icmp sge i8 %30, %25, !dbg !18 + br i1 %31, label %32, label %33, !dbg !18 + +32: ; preds = %27 + call void @__asan_report_store4(i64 %21) #4, !dbg !18 + unreachable + +33: ; preds = %27, %10 + store i32 0, ptr %20, align 4, !dbg !18 + %34 = add i64 %17, 4, !dbg !18 + %35 = inttoptr i64 %34 to ptr, !dbg !18 + store i8 0, ptr %35, align 1, !dbg !18 + store ptr %20, ptr %12, align 8, !dbg !18 + #dbg_declare(ptr %asan_local_stack_base, !20, !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 32), !22) + %36 = load ptr, ptr %12, align 8, !dbg !23 + %37 = ptrtoint ptr %36 to i64, !dbg !24 + %38 = lshr i64 %37, 3, !dbg !24 + %39 = or i64 %38, 17592186044416, !dbg !24 + %40 = inttoptr i64 %39 to ptr, !dbg !24 + %41 = load i8, ptr %40, align 1, !dbg !24 + %42 = icmp ne i8 %41, 0, !dbg !24 + br i1 %42, label %43, label %49, !dbg !24, !prof !19 + +43: ; preds = %33 + %44 = and i64 %37, 7, !dbg !24 + %45 = add i64 %44, 3, !dbg !24 + %46 = trunc i64 %45 to i8, !dbg !24 + %47 = icmp sge i8 %46, %41, !dbg !24 + br i1 %47, label %48, label %49, !dbg !24 + +48: ; preds = %43 + call void @__asan_report_store4(i64 %37) #4, !dbg !24 + unreachable + +49: ; preds = %43, %33 + store i32 123, ptr %36, align 4, !dbg !24 + call void @_Z8sDeallocRPh(ptr noundef %12), !dbg !25 + %50 = load ptr, ptr %12, align 8, !dbg !27 + %51 = ptrtoint ptr %50 to i64, !dbg !28 + %52 = lshr i64 %51, 3, !dbg !28 + %53 = or i64 %52, 17592186044416, !dbg !28 + %54 = inttoptr i64 %53 to ptr, !dbg !28 + %55 = load i8, ptr %54, align 1, !dbg !28 + %56 = icmp ne i8 %55, 0, !dbg !28 + br i1 %56, label %57, label %63, !dbg !28, !prof !19 + +57: ; preds = %49 + %58 = and i64 %51, 7, !dbg !28 + %59 = add i64 %58, 3, !dbg !28 + %60 = trunc i64 %59 to i8, !dbg !28 + %61 = icmp sge i8 %60, %55, !dbg !28 + br i1 %61, label %62, label %63, !dbg !28 + +62: ; preds = %57 + call void @__asan_report_store4(i64 %51) #4, !dbg !28 + unreachable + +63: ; preds = %57, %49 + store i32 321, ptr %50, align 4, !dbg !28 + call void @_Z8sDeallocRPh(ptr %12), !dbg !29 + %64 = add i64 %17, 4, !dbg !29 + %65 = inttoptr i64 %64 to ptr, !dbg !29 + store i8 -8, ptr %65, align 1, !dbg !29 + %66 = load i32, ptr %result, align 4, !dbg !29 + store i64 1172321806, ptr %11, align 8, !dbg !29 + %67 = icmp ne i64 %6, 0, !dbg !29 + br i1 %67, label %68, label %74, !dbg !29 + +68: ; preds = %63 + %69 = add i64 %17, 0, !dbg !29 + %70 = inttoptr i64 %69 to ptr, !dbg !29 + store i64 -723401728380766731, ptr %70, align 1, !dbg !29 + %71 = getelementptr i8, ptr %7, i64 56, !dbg !29 + %72 = load i64, ptr %71, align 8, !dbg !29 + %73 = inttoptr i64 %72 to ptr, !dbg !29 + store i8 0, ptr %73, align 1, !dbg !29 + br label %77, !dbg !29 + +74: ; preds = %63 + %75 = add i64 %17, 0, !dbg !29 + %76 = inttoptr i64 %75 to ptr, !dbg !29 + store i64 0, ptr %76, align 1, !dbg !29 + br label %77, !dbg !29 + +77: ; preds = %74, %68 + ret i32 %66, !dbg !29 +} + +; Function Attrs: nobuiltin nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.start.p0(ptr captures(none)) #1 + +declare ptr @_Z12sAllocUnsafem(i64) + +declare void @_Z8sDeallocRPh(ptr) + +; Function Attrs: nobuiltin nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.end.p0(ptr captures(none)) #1 + +declare void @__asan_report_load_n(i64, i64) + +declare void @__asan_loadN(i64, i64) + +declare void @__asan_report_load1(i64) + +declare void @__asan_load1(i64) + +declare void @__asan_report_load2(i64) + +declare void @__asan_load2(i64) + +declare void @__asan_report_load4(i64) + +declare void @__asan_load4(i64) + +declare void @__asan_report_load8(i64) + +declare void @__asan_load8(i64) + +declare void @__asan_report_load16(i64) + +declare void @__asan_load16(i64) + +declare void @__asan_report_store_n(i64, i64) + +declare void @__asan_storeN(i64, i64) + +declare void @__asan_report_store1(i64) + +declare void @__asan_store1(i64) + +declare void @__asan_report_store2(i64) + +declare void @__asan_store2(i64) + +declare void @__asan_report_store4(i64) + +declare void @__asan_store4(i64) + +declare void @__asan_report_store8(i64) + +declare void @__asan_store8(i64) + +declare void @__asan_report_store16(i64) + +declare void @__asan_store16(i64) + +declare void @__asan_report_exp_load_n(i64, i64, i32) + +declare void @__asan_exp_loadN(i64, i64, i32) + +declare void @__asan_report_exp_load1(i64, i32) + +declare void @__asan_exp_load1(i64, i32) + +declare void @__asan_report_exp_load2(i64, i32) + +declare void @__asan_exp_load2(i64, i32) + +declare void @__asan_report_exp_load4(i64, i32) + +declare void @__asan_exp_load4(i64, i32) + +declare void @__asan_report_exp_load8(i64, i32) + +declare void @__asan_exp_load8(i64, i32) + +declare void @__asan_report_exp_load16(i64, i32) + +declare void @__asan_exp_load16(i64, i32) + +declare void @__asan_report_exp_store_n(i64, i64, i32) + +declare void @__asan_exp_storeN(i64, i64, i32) + +declare void @__asan_report_exp_store1(i64, i32) + +declare void @__asan_exp_store1(i64, i32) + +declare void @__asan_report_exp_store2(i64, i32) + +declare void @__asan_exp_store2(i64, i32) + +declare void @__asan_report_exp_store4(i64, i32) + +declare void @__asan_exp_store4(i64, i32) + +declare void @__asan_report_exp_store8(i64, i32) + +declare void @__asan_exp_store8(i64, i32) + +declare void @__asan_report_exp_store16(i64, i32) + +declare void @__asan_exp_store16(i64, i32) + +declare ptr @__asan_memmove(ptr, ptr, i64) + +declare ptr @__asan_memcpy(ptr, ptr, i64) + +declare ptr @__asan_memset(ptr, i32, i64) + +declare void @__asan_handle_no_return() + +declare void @__sanitizer_ptr_cmp(i64, i64) + +declare void @__sanitizer_ptr_sub(i64, i64) + +; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) +declare i1 @llvm.amdgcn.is.shared(ptr) #2 + +; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) +declare i1 @llvm.amdgcn.is.private(ptr) #2 + +declare i64 @__asan_stack_malloc_0(i64) + +declare void @__asan_stack_free_0(i64, i64) + +declare i64 @__asan_stack_malloc_1(i64) + +declare void @__asan_stack_free_1(i64, i64) + +declare i64 @__asan_stack_malloc_2(i64) + +declare void @__asan_stack_free_2(i64, i64) + +declare i64 @__asan_stack_malloc_3(i64) + +declare void @__asan_stack_free_3(i64, i64) + +declare i64 @__asan_stack_malloc_4(i64) + +declare void @__asan_stack_free_4(i64, i64) + +declare i64 @__asan_stack_malloc_5(i64) + +declare void @__asan_stack_free_5(i64, i64) + +declare i64 @__asan_stack_malloc_6(i64) + +declare void @__asan_stack_free_6(i64, i64) + +declare i64 @__asan_stack_malloc_7(i64) + +declare void @__asan_stack_free_7(i64, i64) + +declare i64 @__asan_stack_malloc_8(i64) + +declare void @__asan_stack_free_8(i64, i64) + +declare i64 @__asan_stack_malloc_9(i64) + +declare void @__asan_stack_free_9(i64, i64) + +declare i64 @__asan_stack_malloc_10(i64) + +declare void @__asan_stack_free_10(i64, i64) + +declare void @__asan_poison_stack_memory(i64, i64) + +declare void @__asan_unpoison_stack_memory(i64, i64) + +declare void @__asan_set_shadow_00(i64, i64) + +declare void @__asan_set_shadow_01(i64, i64) + +declare void @__asan_set_shadow_02(i64, i64) + +declare void @__asan_set_shadow_03(i64, i64) + +declare void @__asan_set_shadow_04(i64, i64) + +declare void @__asan_set_shadow_05(i64, i64) + +declare void @__asan_set_shadow_06(i64, i64) + +declare void @__asan_set_shadow_07(i64, i64) + +declare void @__asan_set_shadow_f1(i64, i64) + +declare void @__asan_set_shadow_f2(i64, i64) + +declare void @__asan_set_shadow_f3(i64, i64) + +declare void @__asan_set_shadow_f5(i64, i64) + +declare void @__asan_set_shadow_f8(i64, i64) + +declare void @__asan_alloca_poison(i64, i64) + +declare void @__asan_allocas_unpoison(i64, i64) + +declare void @__asan_before_dynamic_init(i64) + +declare void @__asan_after_dynamic_init() + +declare void @__asan_register_globals(i64, i64) + +declare void @__asan_unregister_globals(i64, i64) + +declare void @__asan_register_image_globals(i64) + +declare void @__asan_unregister_image_globals(i64) + +declare void @__asan_register_elf_globals(i64, i64, i64) + +declare void @__asan_unregister_elf_globals(i64, i64, i64) + +declare void @__asan_init() + +; Function Attrs: nounwind uwtable +define internal void @asan.module_ctor() #3 { + call void @__asan_init() + call void @__asan_version_mismatch_check_v8() + ret void +} + +declare void @__asan_version_mismatch_check_v8() + +attributes #0 = { mustprogress noinline norecurse nounwind optnone sanitize_address uwtable } +attributes #1 = { nobuiltin nocallback nofree nosync nounwind willreturn } +attributes #2 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) } +attributes #3 = { nounwind uwtable "frame-pointer"="all" } +attributes #4 = { nomerge } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6} +!llvm.ident = !{!7} +!llvm.dbg.cu = !{!8} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{i32 7, !"Dwarf Version", i32 5} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = !{i32 4, !"nosanitize_address", i32 1} +!7 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !9, producer: "spice version dev (https://github.com/spicelang/spice)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!9 = !DIFile(filename: "/home/marc/Documents/Dev/spice/cmake-build-debug/test/./test-files/irgenerator/instrumentation/success-asan-and-dbg-info/source.spice", directory: "./test-files/irgenerator/instrumentation/success-asan-and-dbg-info") +!10 = distinct !DISubprogram(name: "main", linkageName: "_Z4mainv", scope: !11, file: !11, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !8, retainedNodes: !15) +!11 = !DIFile(filename: "source.spice", directory: "./test-files/irgenerator/instrumentation/success-asan-and-dbg-info") +!12 = !DISubroutineType(types: !13) +!13 = !{!14} +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !{} +!16 = !DILocation(line: 3, column: 1, scope: !10) +!17 = !DILocalVariable(name: "result", scope: !10, file: !11, line: 3, type: !14) +!18 = !DILocation(line: 4, column: 22, scope: !10) +!19 = !{!"branch_weights", i32 1, i32 1048575} +!20 = !DILocalVariable(name: "iPtr", scope: !10, file: !11, line: 4, type: !21) +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) +!22 = !DILocation(line: 4, column: 5, scope: !10) +!23 = !DILocation(line: 5, column: 6, scope: !10) +!24 = !DILocation(line: 5, column: 13, scope: !10) +!25 = !DILocation(line: 7, column: 35, scope: !26) +!26 = distinct !DILexicalBlock(scope: !10, file: !11, line: 6, column: 5) +!27 = !DILocation(line: 9, column: 6, scope: !10) +!28 = !DILocation(line: 9, column: 13, scope: !10) +!29 = !DILocation(line: 10, column: 1, scope: !10) diff --git a/test/test-files/irgenerator/instrumentation/success-asan/ir-code-macos-amd64.ll b/test/test-files/irgenerator/instrumentation/success-asan/ir-code-macos-amd64.ll new file mode 100644 index 000000000..6a8d3ca40 --- /dev/null +++ b/test/test-files/irgenerator/instrumentation/success-asan/ir-code-macos-amd64.ll @@ -0,0 +1,204 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@llvm.used = appending global [1 x ptr] [ptr @asan.module_ctor], section "llvm.metadata" +@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @asan.module_ctor, ptr null }] + +; Function Attrs: mustprogress noinline norecurse nounwind optnone sanitize_address uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %iPtr = alloca ptr, align 8 + call void @llvm.lifetime.start.p0(ptr %result) + store i32 0, ptr %result, align 4 + call void @llvm.lifetime.start.p0(ptr %iPtr) + store ptr null, ptr %iPtr, align 8 + %1 = load ptr, ptr %iPtr, align 8 + %2 = ptrtoint ptr %1 to i64 + %3 = lshr i64 %2, 3 + %4 = or i64 %3, 17592186044416 + %5 = inttoptr i64 %4 to ptr + %6 = load i8, ptr %5, align 1 + %7 = icmp ne i8 %6, 0 + br i1 %7, label %8, label %14, !prof !6 + +8: ; preds = %0 + %9 = and i64 %2, 7 + %10 = add i64 %9, 3 + %11 = trunc i64 %10 to i8 + %12 = icmp sge i8 %11, %6 + br i1 %12, label %13, label %14 + +13: ; preds = %8 + call void @__asan_report_store4(i64 %2) #4 + unreachable + +14: ; preds = %8, %0 + store i32 123, ptr %1, align 4 + call void @llvm.lifetime.end.p0(ptr %iPtr) + %15 = load i32, ptr %result, align 4 + ret i32 %15 +} + +; Function Attrs: nobuiltin nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.start.p0(ptr captures(none)) #1 + +; Function Attrs: nobuiltin nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.end.p0(ptr captures(none)) #1 + +declare void @__asan_report_load_n(i64, i64) + +declare void @__asan_loadN(i64, i64) + +declare void @__asan_report_load1(i64) + +declare void @__asan_load1(i64) + +declare void @__asan_report_load2(i64) + +declare void @__asan_load2(i64) + +declare void @__asan_report_load4(i64) + +declare void @__asan_load4(i64) + +declare void @__asan_report_load8(i64) + +declare void @__asan_load8(i64) + +declare void @__asan_report_load16(i64) + +declare void @__asan_load16(i64) + +declare void @__asan_report_store_n(i64, i64) + +declare void @__asan_storeN(i64, i64) + +declare void @__asan_report_store1(i64) + +declare void @__asan_store1(i64) + +declare void @__asan_report_store2(i64) + +declare void @__asan_store2(i64) + +declare void @__asan_report_store4(i64) + +declare void @__asan_store4(i64) + +declare void @__asan_report_store8(i64) + +declare void @__asan_store8(i64) + +declare void @__asan_report_store16(i64) + +declare void @__asan_store16(i64) + +declare void @__asan_report_exp_load_n(i64, i64, i32) + +declare void @__asan_exp_loadN(i64, i64, i32) + +declare void @__asan_report_exp_load1(i64, i32) + +declare void @__asan_exp_load1(i64, i32) + +declare void @__asan_report_exp_load2(i64, i32) + +declare void @__asan_exp_load2(i64, i32) + +declare void @__asan_report_exp_load4(i64, i32) + +declare void @__asan_exp_load4(i64, i32) + +declare void @__asan_report_exp_load8(i64, i32) + +declare void @__asan_exp_load8(i64, i32) + +declare void @__asan_report_exp_load16(i64, i32) + +declare void @__asan_exp_load16(i64, i32) + +declare void @__asan_report_exp_store_n(i64, i64, i32) + +declare void @__asan_exp_storeN(i64, i64, i32) + +declare void @__asan_report_exp_store1(i64, i32) + +declare void @__asan_exp_store1(i64, i32) + +declare void @__asan_report_exp_store2(i64, i32) + +declare void @__asan_exp_store2(i64, i32) + +declare void @__asan_report_exp_store4(i64, i32) + +declare void @__asan_exp_store4(i64, i32) + +declare void @__asan_report_exp_store8(i64, i32) + +declare void @__asan_exp_store8(i64, i32) + +declare void @__asan_report_exp_store16(i64, i32) + +declare void @__asan_exp_store16(i64, i32) + +declare ptr @__asan_memmove(ptr, ptr, i64) + +declare ptr @__asan_memcpy(ptr, ptr, i64) + +declare ptr @__asan_memset(ptr, i32, i64) + +declare void @__asan_handle_no_return() + +declare void @__sanitizer_ptr_cmp(i64, i64) + +declare void @__sanitizer_ptr_sub(i64, i64) + +; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) +declare i1 @llvm.amdgcn.is.shared(ptr) #2 + +; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) +declare i1 @llvm.amdgcn.is.private(ptr) #2 + +declare void @__asan_before_dynamic_init(i64) + +declare void @__asan_after_dynamic_init() + +declare void @__asan_register_globals(i64, i64) + +declare void @__asan_unregister_globals(i64, i64) + +declare void @__asan_register_image_globals(i64) + +declare void @__asan_unregister_image_globals(i64) + +declare void @__asan_register_elf_globals(i64, i64, i64) + +declare void @__asan_unregister_elf_globals(i64, i64, i64) + +declare void @__asan_init() + +; Function Attrs: nounwind uwtable +define internal void @asan.module_ctor() #3 { + call void @__asan_init() + call void @__asan_version_mismatch_check_v8() + ret void +} + +declare void @__asan_version_mismatch_check_v8() + +attributes #0 = { mustprogress noinline norecurse nounwind optnone sanitize_address uwtable } +attributes #1 = { nobuiltin nocallback nofree nosync nounwind willreturn } +attributes #2 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) } +attributes #3 = { nounwind uwtable "frame-pointer"="all" } +attributes #4 = { nomerge } + +!llvm.module.flags = !{!0, !1, !2, !3, !4} +!llvm.ident = !{!5} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{i32 4, !"nosanitize_address", i32 1} +!5 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!6 = !{!"branch_weights", i32 1, i32 1048575} diff --git a/test/test-files/irgenerator/instrumentation/success-tbaa-metadata/ir-code-macos-amd64.ll b/test/test-files/irgenerator/instrumentation/success-tbaa-metadata/ir-code-macos-amd64.ll new file mode 100644 index 000000000..8fb30d419 --- /dev/null +++ b/test/test-files/irgenerator/instrumentation/success-tbaa-metadata/ir-code-macos-amd64.ll @@ -0,0 +1,47 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [13 x i8] c"i, j: %d, %d\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4, !type !5 + %i = alloca i32, align 4, !type !5 + %j = alloca i64, align 8, !type !6 + store i32 0, ptr %result, align 4, !tbaa !7 + store i32 123, ptr %i, align 4, !tbaa !7 + %1 = load i32, ptr %i, align 4, !tbaa !7 + %2 = zext i32 %1 to i64 + store i64 %2, ptr %j, align 8, !tbaa !11 + %3 = load i64, ptr %j, align 8, !tbaa !11 + %4 = add i64 %3, 1 + store i64 %4, ptr %j, align 8 + %5 = load i32, ptr %i, align 4, !tbaa !7 + %6 = load i64, ptr %j, align 8, !tbaa !11 + %7 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %5, i64 noundef %6) + %8 = load i32, ptr %result, align 4 + ret i32 %8 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{i64 5535379567501308475, !"int"} +!6 = !{i64 4012008395254530479, !"unsigned long"} +!7 = !{!8, !8, i64 0} +!8 = !{!"int", !9, i64 0} +!9 = !{!"omnipotent byte", !10, i64 0} +!10 = !{!"Simple Spice TBAA"} +!11 = !{!12, !12, i64 0} +!12 = !{!"unsigned long", !9, i64 0} diff --git a/test/test-files/irgenerator/instrumentation/success-tysan-and-dbg-info/ir-code-macos-amd64.ll b/test/test-files/irgenerator/instrumentation/success-tysan-and-dbg-info/ir-code-macos-amd64.ll new file mode 100644 index 000000000..2e34865f7 --- /dev/null +++ b/test/test-files/irgenerator/instrumentation/success-tysan-and-dbg-info/ir-code-macos-amd64.ll @@ -0,0 +1,119 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }] +@__tysan_v1_Simple_20Spice_20TBAA = linkonce_odr constant { i64, i64, [18 x i8] } { i64 2, i64 0, [18 x i8] c"Simple Spice TBAA\00" } +@__tysan_v1_omnipotent_20byte = linkonce_odr constant { i64, i64, ptr, i64, [16 x i8] } { i64 2, i64 1, ptr @__tysan_v1_Simple_20Spice_20TBAA, i64 0, [16 x i8] c"omnipotent byte\00" } +@__tysan_v1_int = linkonce_odr constant { i64, i64, ptr, i64, [4 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [4 x i8] c"int\00" } +@__tysan_v1_int_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_int, ptr @__tysan_v1_int, i64 0 } +@__tysan_v1_long = linkonce_odr constant { i64, i64, ptr, i64, [5 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [5 x i8] c"long\00" } +@__tysan_v1_long_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_long, ptr @__tysan_v1_long, i64 0 } +@__tysan_v1_double_2a = linkonce_odr constant { i64, i64, ptr, i64, [8 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [8 x i8] c"double*\00" } +@__tysan_v1_double_2a_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_double_2a, ptr @__tysan_v1_double_2a, i64 0 } +@__tysan_v1_double = linkonce_odr constant { i64, i64, ptr, i64, [7 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [7 x i8] c"double\00" } +@__tysan_v1_double_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_double, ptr @__tysan_v1_double, i64 0 } +@llvm.used = appending global [11 x ptr] [ptr @tysan.module_ctor, ptr @__tysan_v1_Simple_20Spice_20TBAA, ptr @__tysan_v1_omnipotent_20byte, ptr @__tysan_v1_int, ptr @__tysan_v1_int_o_0, ptr @__tysan_v1_long, ptr @__tysan_v1_long_o_0, ptr @__tysan_v1_double_2a, ptr @__tysan_v1_double_2a_o_0, ptr @__tysan_v1_double, ptr @__tysan_v1_double_o_0], section "llvm.metadata" +@__tysan_shadow_memory_address = external global i64 +@__tysan_app_memory_mask = external global i64 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone sanitize_type uwtable +define dso_local noundef i32 @main() #0 !dbg !9 { + %app.mem.mask = load i64, ptr @__tysan_app_memory_mask, align 8 + %shadow.base = load i64, ptr @__tysan_shadow_memory_address, align 8 + %result = alloca i32, align 4, !type !15 + call void @__tysan_instrument_mem_inst(ptr %result, ptr null, i64 4, i1 false) + %l = alloca i64, align 8, !type !16 + call void @__tysan_instrument_mem_inst(ptr %l, ptr null, i64 8, i1 false) + %ptr = alloca ptr, align 8, !dbg !17, !type !18 + #dbg_declare(ptr %result, !19, !DIExpression(), !17) + call void @__tysan_instrument_mem_inst(ptr %ptr, ptr null, i64 8, i1 false), !dbg !17 + call void @__tysan_instrument_with_shadow_update(ptr %result, ptr @__tysan_v1_int_o_0, i1 true, i64 4, i32 2), !dbg !17 + store i32 0, ptr %result, align 4, !dbg !17, !tbaa !20 + call void @__tysan_instrument_with_shadow_update(ptr %l, ptr @__tysan_v1_long_o_0, i1 true, i64 8, i32 2), !dbg !24 + store i64 100, ptr %l, align 8, !dbg !24, !tbaa !25 + #dbg_declare(ptr %l, !27, !DIExpression(), !29) + call void @__tysan_instrument_with_shadow_update(ptr %ptr, ptr @__tysan_v1_double_2a_o_0, i1 true, i64 8, i32 2), !dbg !30 + store ptr %l, ptr %ptr, align 8, !dbg !30, !tbaa !32 + #dbg_declare(ptr %ptr, !34, !DIExpression(), !37) + call void @__tysan_instrument_with_shadow_update(ptr %ptr, ptr null, i1 true, i64 8, i32 1), !dbg !38 + %1 = load ptr, ptr %ptr, align 8, !dbg !38 + call void @__tysan_instrument_with_shadow_update(ptr %1, ptr @__tysan_v1_double_o_0, i1 true, i64 8, i32 1), !dbg !38 + %2 = load double, ptr %1, align 8, !dbg !38, !tbaa !39 + %3 = fadd double %2, 2.000000e+00, !dbg !38 + call void @__tysan_instrument_with_shadow_update(ptr %1, ptr null, i1 true, i64 8, i32 2), !dbg !38 + store double %3, ptr %1, align 8, !dbg !38 + call void @__tysan_instrument_with_shadow_update(ptr %result, ptr null, i1 true, i64 4, i32 1), !dbg !41 + %4 = load i32, ptr %result, align 4, !dbg !41 + ret i32 %4, !dbg !41 +} + +declare void @__tysan_init() + +; Function Attrs: nounwind uwtable +define internal void @tysan.module_ctor() #1 { + call void @__tysan_init() + ret void +} + +; Function Attrs: nounwind +declare void @__tysan_check(ptr, i32, ptr, i32) #2 + +; Function Attrs: nounwind +declare void @__tysan_instrument_mem_inst(ptr, ptr, i64, i1) #2 + +; Function Attrs: nounwind +declare void @__tysan_instrument_with_shadow_update(ptr, ptr, i1, i64, i32) #2 + +; Function Attrs: nounwind +declare void @__tysan_set_shadow_type(ptr, ptr, i64) #2 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone sanitize_type uwtable } +attributes #1 = { nounwind uwtable "frame-pointer"="all" } +attributes #2 = { nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5} +!llvm.ident = !{!6} +!llvm.dbg.cu = !{!7} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{i32 7, !"Dwarf Version", i32 5} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!7 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !8, producer: "spice version dev (https://github.com/spicelang/spice)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!8 = !DIFile(filename: "/home/marc/Documents/Dev/spice/cmake-build-debug/test/./test-files/irgenerator/instrumentation/success-tysan-and-dbg-info/source.spice", directory: "./test-files/irgenerator/instrumentation/success-tysan-and-dbg-info") +!9 = distinct !DISubprogram(name: "main", linkageName: "_Z4mainv", scope: !10, file: !10, line: 3, type: !11, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !14) +!10 = !DIFile(filename: "source.spice", directory: "./test-files/irgenerator/instrumentation/success-tysan-and-dbg-info") +!11 = !DISubroutineType(types: !12) +!12 = !{!13} +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !{} +!15 = !{i64 5535379567501308475, !"int"} +!16 = !{i64 4012008395254530479, !"long"} +!17 = !DILocation(line: 3, column: 1, scope: !9) +!18 = !{i64 -8911943234966098186, !"double*"} +!19 = !DILocalVariable(name: "result", scope: !9, file: !10, line: 3, type: !13) +!20 = !{!21, !21, i64 0} +!21 = !{!"int", !22, i64 0} +!22 = !{!"omnipotent byte", !23, i64 0} +!23 = !{!"Simple Spice TBAA"} +!24 = !DILocation(line: 4, column: 14, scope: !9) +!25 = !{!26, !26, i64 0} +!26 = !{!"long", !22, i64 0} +!27 = !DILocalVariable(name: "l", scope: !9, file: !10, line: 4, type: !28) +!28 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed) +!29 = !DILocation(line: 4, column: 5, scope: !9) +!30 = !DILocation(line: 6, column: 37, scope: !31) +!31 = distinct !DILexicalBlock(scope: !9, file: !10, line: 5, column: 5) +!32 = !{!33, !33, i64 0} +!33 = !{!"double*", !22, i64 0} +!34 = !DILocalVariable(name: "ptr", scope: !31, file: !10, line: 6, type: !35) +!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64) +!36 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float) +!37 = !DILocation(line: 6, column: 8, scope: !31) +!38 = !DILocation(line: 7, column: 9, scope: !31) +!39 = !{!40, !40, i64 0} +!40 = !{!"double", !22, i64 0} +!41 = !DILocation(line: 9, column: 1, scope: !9) diff --git a/test/test-files/irgenerator/instrumentation/success-tysan/ir-code-macos-amd64.ll b/test/test-files/irgenerator/instrumentation/success-tysan/ir-code-macos-amd64.ll new file mode 100644 index 000000000..b0e549334 --- /dev/null +++ b/test/test-files/irgenerator/instrumentation/success-tysan/ir-code-macos-amd64.ll @@ -0,0 +1,91 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }] +@__tysan_v1_Simple_20Spice_20TBAA = linkonce_odr constant { i64, i64, [18 x i8] } { i64 2, i64 0, [18 x i8] c"Simple Spice TBAA\00" } +@__tysan_v1_omnipotent_20byte = linkonce_odr constant { i64, i64, ptr, i64, [16 x i8] } { i64 2, i64 1, ptr @__tysan_v1_Simple_20Spice_20TBAA, i64 0, [16 x i8] c"omnipotent byte\00" } +@__tysan_v1_int = linkonce_odr constant { i64, i64, ptr, i64, [4 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [4 x i8] c"int\00" } +@__tysan_v1_int_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_int, ptr @__tysan_v1_int, i64 0 } +@__tysan_v1_long = linkonce_odr constant { i64, i64, ptr, i64, [5 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [5 x i8] c"long\00" } +@__tysan_v1_long_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_long, ptr @__tysan_v1_long, i64 0 } +@__tysan_v1_double_2a = linkonce_odr constant { i64, i64, ptr, i64, [8 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [8 x i8] c"double*\00" } +@__tysan_v1_double_2a_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_double_2a, ptr @__tysan_v1_double_2a, i64 0 } +@__tysan_v1_double = linkonce_odr constant { i64, i64, ptr, i64, [7 x i8] } { i64 2, i64 1, ptr @__tysan_v1_omnipotent_20byte, i64 0, [7 x i8] c"double\00" } +@__tysan_v1_double_o_0 = linkonce_odr constant { i64, ptr, ptr, i64 } { i64 1, ptr @__tysan_v1_double, ptr @__tysan_v1_double, i64 0 } +@llvm.used = appending global [11 x ptr] [ptr @tysan.module_ctor, ptr @__tysan_v1_Simple_20Spice_20TBAA, ptr @__tysan_v1_omnipotent_20byte, ptr @__tysan_v1_int, ptr @__tysan_v1_int_o_0, ptr @__tysan_v1_long, ptr @__tysan_v1_long_o_0, ptr @__tysan_v1_double_2a, ptr @__tysan_v1_double_2a_o_0, ptr @__tysan_v1_double, ptr @__tysan_v1_double_o_0], section "llvm.metadata" +@__tysan_shadow_memory_address = external global i64 +@__tysan_app_memory_mask = external global i64 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone sanitize_type uwtable +define dso_local noundef i32 @main() #0 { + %app.mem.mask = load i64, ptr @__tysan_app_memory_mask, align 8 + %shadow.base = load i64, ptr @__tysan_shadow_memory_address, align 8 + %result = alloca i32, align 4, !type !5 + call void @__tysan_instrument_mem_inst(ptr %result, ptr null, i64 4, i1 false) + %l = alloca i64, align 8, !type !6 + call void @__tysan_instrument_mem_inst(ptr %l, ptr null, i64 8, i1 false) + %ptr = alloca ptr, align 8, !type !7 + call void @__tysan_instrument_mem_inst(ptr %ptr, ptr null, i64 8, i1 false) + call void @__tysan_instrument_with_shadow_update(ptr %result, ptr @__tysan_v1_int_o_0, i1 true, i64 4, i32 2) + store i32 0, ptr %result, align 4, !tbaa !8 + call void @__tysan_instrument_with_shadow_update(ptr %l, ptr @__tysan_v1_long_o_0, i1 true, i64 8, i32 2) + store i64 100, ptr %l, align 8, !tbaa !12 + call void @__tysan_instrument_with_shadow_update(ptr %ptr, ptr @__tysan_v1_double_2a_o_0, i1 true, i64 8, i32 2) + store ptr %l, ptr %ptr, align 8, !tbaa !14 + call void @__tysan_instrument_with_shadow_update(ptr %ptr, ptr null, i1 true, i64 8, i32 1) + %1 = load ptr, ptr %ptr, align 8 + call void @__tysan_instrument_with_shadow_update(ptr %1, ptr @__tysan_v1_double_o_0, i1 true, i64 8, i32 1) + %2 = load double, ptr %1, align 8, !tbaa !16 + %3 = fadd double %2, 2.000000e+00 + call void @__tysan_instrument_with_shadow_update(ptr %1, ptr null, i1 true, i64 8, i32 2) + store double %3, ptr %1, align 8 + call void @__tysan_instrument_with_shadow_update(ptr %result, ptr null, i1 true, i64 4, i32 1) + %4 = load i32, ptr %result, align 4 + ret i32 %4 +} + +declare void @__tysan_init() + +; Function Attrs: nounwind uwtable +define internal void @tysan.module_ctor() #1 { + call void @__tysan_init() + ret void +} + +; Function Attrs: nounwind +declare void @__tysan_check(ptr, i32, ptr, i32) #2 + +; Function Attrs: nounwind +declare void @__tysan_instrument_mem_inst(ptr, ptr, i64, i1) #2 + +; Function Attrs: nounwind +declare void @__tysan_instrument_with_shadow_update(ptr, ptr, i1, i64, i32) #2 + +; Function Attrs: nounwind +declare void @__tysan_set_shadow_type(ptr, ptr, i64) #2 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone sanitize_type uwtable } +attributes #1 = { nounwind uwtable "frame-pointer"="all" } +attributes #2 = { nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{i64 5535379567501308475, !"int"} +!6 = !{i64 4012008395254530479, !"long"} +!7 = !{i64 -8911943234966098186, !"double*"} +!8 = !{!9, !9, i64 0} +!9 = !{!"int", !10, i64 0} +!10 = !{!"omnipotent byte", !11, i64 0} +!11 = !{!"Simple Spice TBAA"} +!12 = !{!13, !13, i64 0} +!13 = !{!"long", !10, i64 0} +!14 = !{!15, !15, i64 0} +!15 = !{!"double*", !10, i64 0} +!16 = !{!17, !17, i64 0} +!17 = !{!"double", !10, i64 0} diff --git a/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-O2-macos-amd64.ll b/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-O2-macos-amd64.ll new file mode 100644 index 000000000..8182ac8ad --- /dev/null +++ b/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-O2-macos-amd64.ll @@ -0,0 +1,68 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +%struct.Car = type { %interface.Driveable, i1 } +%interface.Driveable = type { ptr } + +@_ZTS3Car = weak_odr dso_local constant [5 x i8] c"3Car\00", align 4 +@_ZTV8TypeInfo = external global ptr +@_ZTI9Driveable = external global ptr +@_ZTI3Car = weak_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS3Car, ptr @_ZTI9Driveable }, align 8 +@_ZTV3Car = weak_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTI3Car, ptr @_ZN3Car5driveEi, ptr @_ZN3Car9isDrivingEv] }, align 8 +@printf.str.0 = private unnamed_addr constant [15 x i8] c"Is driving: %d\00", align 4 + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) +define private fastcc void @_ZN3Car4ctorEv(ptr noundef nonnull writeonly align 8 captures(none) dereferenceable(16) initializes((0, 9)) %0) unnamed_addr #0 { + store ptr getelementptr inbounds nuw (i8, ptr @_ZTV3Car, i64 16), ptr %0, align 8 + %2 = getelementptr inbounds nuw i8, ptr %0, i64 8 + store i1 false, ptr %2, align 8 + ret void +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) +define private void @_ZN3Car5driveEi(ptr noundef nonnull writeonly align 8 captures(none) dereferenceable(16) initializes((8, 9)) %0, i32 %1) #0 { + %driving.addr = getelementptr inbounds nuw i8, ptr %0, i64 8 + store i1 true, ptr %driving.addr, align 8 + ret void +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) +define private noundef zeroext i1 @_ZN3Car9isDrivingEv(ptr noundef nonnull readonly align 8 captures(none) dereferenceable(16) %0) #1 { + %driving.addr = getelementptr inbounds nuw i8, ptr %0, i64 8 + %2 = load i1, ptr %driving.addr, align 8 + ret i1 %2 +} + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() local_unnamed_addr #2 { + %car = alloca %struct.Car, align 8 + call fastcc void @_ZN3Car4ctorEv(ptr noundef nonnull align 8 dereferenceable(16) %car) #4 + %vtable.addr = load ptr, ptr %car, align 8 + %fct = load ptr, ptr %vtable.addr, align 8 + call void %fct(ptr noundef nonnull align 8 dereferenceable(8) %car, i32 noundef 12) #4 + %vtable.addr1 = load ptr, ptr %car, align 8 + %vfct.addr2 = getelementptr inbounds nuw i8, ptr %vtable.addr1, i64 8 + %fct3 = load ptr, ptr %vfct.addr2, align 8 + %1 = call noundef zeroext i1 %fct3(ptr noundef nonnull align 8 dereferenceable(8) %car) #4 + %2 = zext i1 %1 to i32 + %3 = call noundef i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @printf.str.0, i32 noundef %2) + ret i32 0 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #3 + +attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) } +attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) } +attributes #2 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #3 = { nofree nounwind } +attributes #4 = { nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-macos-amd64.ll b/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-macos-amd64.ll new file mode 100644 index 000000000..088e86a21 --- /dev/null +++ b/test/test-files/irgenerator/interfaces/success-cross-sourcefile-interfaces/ir-code-macos-amd64.ll @@ -0,0 +1,85 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +%struct.Car = type { %interface.Driveable, i1 } +%interface.Driveable = type { ptr } + +@_ZTS3Car = weak_odr dso_local constant [5 x i8] c"3Car\00", align 4 +@_ZTV8TypeInfo = external global ptr +@_ZTI9Driveable = external global ptr +@_ZTI3Car = weak_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS3Car, ptr @_ZTI9Driveable }, align 8 +@_ZTV3Car = weak_odr dso_local unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTI3Car, ptr @_ZN3Car5driveEi, ptr @_ZN3Car9isDrivingEv] }, align 8 +@printf.str.0 = private unnamed_addr constant [15 x i8] c"Is driving: %d\00", align 4 + +define private void @_ZN3Car4ctorEv(ptr noundef nonnull align 8 dereferenceable(16) %0) { + %this = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV3Car, i64 0, i32 0, i32 2), ptr %2, align 8 + %3 = getelementptr inbounds nuw %struct.Car, ptr %2, i32 0, i32 1 + store i1 false, ptr %3, align 1 + %4 = load ptr, ptr %this, align 8 + %driving.addr = getelementptr inbounds %struct.Car, ptr %4, i64 0, i32 1 + store i1 false, ptr %driving.addr, align 1 + ret void +} + +define private void @_ZN3Car5driveEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) { + %this = alloca ptr, align 8 + %_param = alloca i32, align 4 + store ptr %0, ptr %this, align 8 + store i32 %1, ptr %_param, align 4 + %3 = load ptr, ptr %this, align 8 + %driving.addr = getelementptr inbounds %struct.Car, ptr %3, i64 0, i32 1 + store i1 true, ptr %driving.addr, align 1 + ret void +} + +define private noundef zeroext i1 @_ZN3Car9isDrivingEv(ptr noundef nonnull align 8 dereferenceable(16) %0) { + %result = alloca i1, align 1 + %this = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + %driving.addr = getelementptr inbounds %struct.Car, ptr %2, i64 0, i32 1 + %3 = load i1, ptr %driving.addr, align 1 + ret i1 %3 +} + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %car = alloca %struct.Car, align 8 + %driveable = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + call void @_ZN3Car4ctorEv(ptr noundef nonnull align 8 dereferenceable(16) %car) + store ptr %car, ptr %driveable, align 8 + %1 = load ptr, ptr %driveable, align 8 + %vtable.addr = load ptr, ptr %1, align 8 + %vfct.addr = getelementptr inbounds ptr, ptr %vtable.addr, i64 0 + %fct = load ptr, ptr %vfct.addr, align 8 + call void %fct(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 12) + %2 = load ptr, ptr %driveable, align 8 + %vtable.addr1 = load ptr, ptr %2, align 8 + %vfct.addr2 = getelementptr inbounds ptr, ptr %vtable.addr1, i64 1 + %fct3 = load ptr, ptr %vfct.addr2, align 8 + %3 = call noundef zeroext i1 %fct3(ptr noundef nonnull align 8 dereferenceable(8) %2) + %4 = zext i1 %3 to i32 + %5 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %4) + %6 = load i32, ptr %result, align 4 + ret i32 %6 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/interfaces/success-generic-interfaces/ir-code-macos-amd64.ll b/test/test-files/irgenerator/interfaces/success-generic-interfaces/ir-code-macos-amd64.ll new file mode 100644 index 000000000..12772223a --- /dev/null +++ b/test/test-files/irgenerator/interfaces/success-generic-interfaces/ir-code-macos-amd64.ll @@ -0,0 +1,119 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +%struct.Person = type { %interface.Compareable, ptr, ptr, i32 } +%interface.Compareable = type { ptr } + +@_ZTS11CompareableIlE = private constant [14 x i8] c"11Compareable\00", align 4 +@_ZTV8TypeInfo = external global ptr +@_ZTI11CompareableIlE = private constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS11CompareableIlE }, align 8 +@_ZTV11CompareableIlE = private unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI11CompareableIlE, ptr null] }, align 8 +@_ZTS6Person = private constant [8 x i8] c"6Person\00", align 4 +@_ZTI6Person = private constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS6Person, ptr @_ZTI11CompareableIlE }, align 8 +@_ZTV6Person = private unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI6Person, ptr @_ZN6Person7compareERKlRKl] }, align 8 +@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 4 +@1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 4 +@anon.string.0 = private unnamed_addr constant [5 x i8] c"Mike\00", align 4 +@anon.string.1 = private unnamed_addr constant [7 x i8] c"Miller\00", align 4 +@printf.str.0 = private unnamed_addr constant [3 x i8] c"%d\00", align 4 + +define private void @_ZN6Person4ctorEPKcPKcj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) { + %this = alloca ptr, align 8 + %firstName = alloca ptr, align 8 + %lastName = alloca ptr, align 8 + %age = alloca i32, align 4 + store ptr %0, ptr %this, align 8 + store ptr %1, ptr %firstName, align 8 + store ptr %2, ptr %lastName, align 8 + store i32 %3, ptr %age, align 4 + %5 = load ptr, ptr %this, align 8 + store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV6Person, i64 0, i32 0, i32 2), ptr %5, align 8 + %6 = getelementptr inbounds nuw %struct.Person, ptr %5, i32 0, i32 1 + store ptr @0, ptr %6, align 8 + %7 = getelementptr inbounds nuw %struct.Person, ptr %5, i32 0, i32 2 + store ptr @1, ptr %7, align 8 + %8 = getelementptr inbounds nuw %struct.Person, ptr %5, i32 0, i32 3 + store i32 0, ptr %8, align 4 + %9 = load ptr, ptr %this, align 8 + %firstName.addr = getelementptr inbounds %struct.Person, ptr %9, i64 0, i32 1 + %10 = load ptr, ptr %firstName, align 8 + store ptr %10, ptr %firstName.addr, align 8 + %11 = load ptr, ptr %this, align 8 + %lastName.addr = getelementptr inbounds %struct.Person, ptr %11, i64 0, i32 2 + %12 = load ptr, ptr %lastName, align 8 + store ptr %12, ptr %lastName.addr, align 8 + %13 = load ptr, ptr %this, align 8 + %age.addr = getelementptr inbounds %struct.Person, ptr %13, i64 0, i32 3 + %14 = load i32, ptr %age, align 4 + store i32 %14, ptr %age.addr, align 4 + ret void +} + +define private noundef i32 @_ZN6Person7compareERKlRKl(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, ptr noundef %2) { + %result = alloca i32, align 4 + %this = alloca ptr, align 8 + %a = alloca ptr, align 8 + %b = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + store ptr %1, ptr %a, align 8 + store ptr %2, ptr %b, align 8 + %4 = load ptr, ptr %a, align 8 + %5 = load i64, ptr %4, align 8 + %6 = load ptr, ptr %b, align 8 + %7 = load i64, ptr %6, align 8 + %8 = icmp sgt i64 %5, %7 + br i1 %8, label %if.then.L26, label %if.exit.L26 + +if.then.L26: ; preds = %3 + ret i32 2 + +if.exit.L26: ; preds = %3 + %9 = load ptr, ptr %a, align 8 + %10 = load i64, ptr %9, align 8 + %11 = load ptr, ptr %b, align 8 + %12 = load i64, ptr %11, align 8 + %13 = icmp slt i64 %10, %12 + br i1 %13, label %if.then.L27, label %if.exit.L27 + +if.then.L27: ; preds = %if.exit.L26 + ret i32 0 + +if.exit.L27: ; preds = %if.exit.L26 + ret i32 1 +} + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %mike = alloca %struct.Person, align 8 + %1 = alloca i64, align 8 + %2 = alloca i64, align 8 + %isEqual = alloca i1, align 1 + store i32 0, ptr %result, align 4 + call void @_ZN6Person4ctorEPKcPKcj(ptr noundef nonnull align 8 dereferenceable(32) %mike, ptr noundef @anon.string.0, ptr noundef @anon.string.1, i32 noundef 43) + store i64 22, ptr %1, align 8 + store i64 22, ptr %2, align 8 + %3 = call noundef i32 @_ZN6Person7compareERKlRKl(ptr noundef nonnull align 8 dereferenceable(32) %mike, ptr noundef %1, ptr noundef %2) + %4 = icmp eq i32 %3, 1 + store i1 %4, ptr %isEqual, align 1 + %5 = load i1, ptr %isEqual, align 1 + %6 = zext i1 %5 to i32 + %7 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %6) + %8 = load i32, ptr %result, align 4 + ret i32 %8 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/lambdas/success-captures/ir-code-macos-amd64.ll b/test/test-files/irgenerator/lambdas/success-captures/ir-code-macos-amd64.ll new file mode 100644 index 000000000..8b1d9972e --- /dev/null +++ b/test/test-files/irgenerator/lambdas/success-captures/ir-code-macos-amd64.ll @@ -0,0 +1,143 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.string.0 = private unnamed_addr constant [58 x i8] c"Assertion failed: Condition 'x == 6' evaluated to false.\0A\00", align 4 +@anon.string.1 = private unnamed_addr constant [59 x i8] c"Assertion failed: Condition 'foo2(x)' evaluated to false.\0A\00", align 4 +@anon.string.2 = private unnamed_addr constant [59 x i8] c"Assertion failed: Condition 'x == 11' evaluated to false.\0A\00", align 4 +@printf.str.0 = private unnamed_addr constant [19 x i8] c"All tests passed!\0A\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %z = alloca i32, align 4 + %w = alloca i32, align 4 + %captures = alloca { i32, i32 }, align 8 + %fat.ptr = alloca { ptr, ptr, i64 }, align 8 + %foo1 = alloca { ptr, ptr, i64 }, align 8 + %captures1 = alloca { i32, i32 }, align 8 + %fat.ptr2 = alloca { ptr, ptr, i64 }, align 8 + %foo2 = alloca { ptr, ptr, i64 }, align 8 + %x = alloca i32, align 4 + store i32 0, ptr %result, align 4 + store i32 2, ptr %z, align 4 + store i32 3, ptr %w, align 4 + %1 = load i32, ptr %w, align 4 + store i32 %1, ptr %captures, align 4 + %2 = load i32, ptr %z, align 4 + %3 = getelementptr inbounds nuw { i32, i32 }, ptr %captures, i32 0, i32 1 + store i32 %2, ptr %3, align 4 + store ptr @_Z14lambda.L4C20.0Ri, ptr %fat.ptr, align 8 + %4 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 1 + store ptr %captures, ptr %4, align 8 + %5 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 2 + store i64 8, ptr %5, align 8 + %6 = load { ptr, ptr, i64 }, ptr %fat.ptr, align 8 + store { ptr, ptr, i64 } %6, ptr %foo1, align 8 + %7 = load i32, ptr %w, align 4 + store i32 %7, ptr %captures1, align 4 + %8 = load i32, ptr %z, align 4 + %9 = getelementptr inbounds nuw { i32, i32 }, ptr %captures1, i32 0, i32 1 + store i32 %8, ptr %9, align 4 + store ptr @_Z14lambda.L7C26.0Ri, ptr %fat.ptr2, align 8 + %10 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr2, i32 0, i32 1 + store ptr %captures1, ptr %10, align 8 + %11 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr2, i32 0, i32 2 + store i64 8, ptr %11, align 8 + %12 = load { ptr, ptr, i64 }, ptr %fat.ptr2, align 8 + store { ptr, ptr, i64 } %12, ptr %foo2, align 8 + store i32 1, ptr %x, align 4 + %13 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %foo1, i32 0, i32 1 + %captures3 = load ptr, ptr %13, align 8 + %fct = load ptr, ptr %foo1, align 8 + call void %fct(ptr %captures3, ptr %x) + %14 = load i32, ptr %x, align 4 + %15 = icmp eq i32 %14, 6 + br i1 %15, label %assert.exit.L13, label %assert.then.L13, !prof !5 + +assert.then.L13: ; preds = %0 + %16 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L13: ; preds = %0 + %17 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %foo2, i32 0, i32 1 + %captures4 = load ptr, ptr %17, align 8 + %fct5 = load ptr, ptr %foo2, align 8 + %18 = call i1 %fct5(ptr %captures4, ptr %x) + br i1 %18, label %assert.exit.L14, label %assert.then.L14, !prof !5 + +assert.then.L14: ; preds = %assert.exit.L13 + %19 = call i32 (ptr, ...) @printf(ptr @anon.string.1) + call void @exit(i32 1) + unreachable + +assert.exit.L14: ; preds = %assert.exit.L13 + %20 = load i32, ptr %x, align 4 + %21 = icmp eq i32 %20, 11 + br i1 %21, label %assert.exit.L15, label %assert.then.L15, !prof !5 + +assert.then.L15: ; preds = %assert.exit.L14 + %22 = call i32 (ptr, ...) @printf(ptr @anon.string.2) + call void @exit(i32 1) + unreachable + +assert.exit.L15: ; preds = %assert.exit.L14 + %23 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0) + %24 = load i32, ptr %result, align 4 + ret i32 %24 +} + +define private void @_Z14lambda.L4C20.0Ri(ptr noundef nonnull dereferenceable(8) %0, ptr %1) { + %captures = alloca ptr, align 8 + %x = alloca ptr, align 8 + store ptr %0, ptr %captures, align 8 + store ptr %1, ptr %x, align 8 + %3 = load ptr, ptr %captures, align 8 + %z = getelementptr inbounds nuw { i32, i32 }, ptr %3, i32 0, i32 1 + %4 = load i32, ptr %z, align 4 + %5 = load i32, ptr %3, align 4 + %6 = add nsw i32 %4, %5 + %7 = load ptr, ptr %x, align 8 + %8 = load i32, ptr %7, align 4 + %9 = add nsw i32 %8, %6 + store i32 %9, ptr %7, align 4 + ret void +} + +define private i1 @_Z14lambda.L7C26.0Ri(ptr noundef nonnull dereferenceable(8) %0, ptr %1) { + %result = alloca i1, align 1 + %captures = alloca ptr, align 8 + %x = alloca ptr, align 8 + store ptr %0, ptr %captures, align 8 + store ptr %1, ptr %x, align 8 + %3 = load ptr, ptr %captures, align 8 + %z = getelementptr inbounds nuw { i32, i32 }, ptr %3, i32 0, i32 1 + %4 = load i32, ptr %z, align 4 + %5 = load i32, ptr %3, align 4 + %6 = add nsw i32 %4, %5 + %7 = load ptr, ptr %x, align 8 + %8 = load i32, ptr %7, align 4 + %9 = add nsw i32 %8, %6 + store i32 %9, ptr %7, align 4 + ret i1 true +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #2 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } +attributes #2 = { cold noreturn nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/irgenerator/lambdas/success-different-capture-modes/ir-code-macos-amd64.ll b/test/test-files/irgenerator/lambdas/success-different-capture-modes/ir-code-macos-amd64.ll new file mode 100644 index 000000000..14c7955a4 --- /dev/null +++ b/test/test-files/irgenerator/lambdas/success-different-capture-modes/ir-code-macos-amd64.ll @@ -0,0 +1,76 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@printf.str.0 = private unnamed_addr constant [23 x i8] c"Hello from inside: %d\0A\00", align 4 +@printf.str.1 = private unnamed_addr constant [23 x i8] c"Hello from inside: %d\0A\00", align 4 +@printf.str.2 = private unnamed_addr constant [24 x i8] c"Hello from outside: %d\0A\00", align 4 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %i = alloca i32, align 4 + %j = alloca i32, align 4 + %captures = alloca { ptr, i32 }, align 8 + %fat.ptr = alloca { ptr, ptr, i64 }, align 8 + %lambda = alloca { ptr, ptr, i64 }, align 8 + store i32 0, ptr %result, align 4 + store i32 123, ptr %i, align 4 + store i32 321, ptr %j, align 4 + store ptr %i, ptr %captures, align 8 + %1 = load i32, ptr %j, align 4 + %2 = getelementptr inbounds nuw { ptr, i32 }, ptr %captures, i32 0, i32 1 + store i32 %1, ptr %2, align 4 + store ptr @_Z14lambda.L4C18.0v, ptr %fat.ptr, align 8 + %3 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 1 + store ptr %captures, ptr %3, align 8 + %4 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 2 + store i64 16, ptr %4, align 8 + %5 = load { ptr, ptr, i64 }, ptr %fat.ptr, align 8 + store { ptr, ptr, i64 } %5, ptr %lambda, align 8 + %6 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %lambda, i32 0, i32 1 + %captures1 = load ptr, ptr %6, align 8 + %fct = load ptr, ptr %lambda, align 8 + call void %fct(ptr %captures1) + %7 = load i32, ptr %i, align 4 + %8 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.2, i32 noundef %7) + %9 = load i32, ptr %result, align 4 + ret i32 %9 +} + +define private void @_Z14lambda.L4C18.0v(ptr noundef nonnull dereferenceable(8) %0) { + %captures = alloca ptr, align 8 + store ptr %0, ptr %captures, align 8 + %2 = load ptr, ptr %captures, align 8 + %j = getelementptr inbounds nuw { ptr, i32 }, ptr %2, i32 0, i32 1 + %3 = load ptr, ptr %2, align 8 + %4 = load i32, ptr %3, align 4 + %5 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %4) + %6 = load ptr, ptr %2, align 8 + %7 = load i32, ptr %6, align 4 + %8 = add nsw i32 %7, 1 + store i32 %8, ptr %6, align 4 + %9 = load ptr, ptr %2, align 8 + %10 = load i32, ptr %9, align 4 + %11 = load i32, ptr %j, align 4 + %12 = add nsw i32 %10, %11 + store i32 %12, ptr %9, align 4 + %13 = load ptr, ptr %2, align 8 + %14 = load i32, ptr %13, align 4 + %15 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1, i32 noundef %14) + ret void +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/lambdas/success-expression-lambda/ir-code-macos-amd64.ll b/test/test-files/irgenerator/lambdas/success-expression-lambda/ir-code-macos-amd64.ll new file mode 100644 index 000000000..83badc26b --- /dev/null +++ b/test/test-files/irgenerator/lambdas/success-expression-lambda/ir-code-macos-amd64.ll @@ -0,0 +1,183 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.array.0 = private unnamed_addr constant [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1] +@printf.str.0 = private unnamed_addr constant [4 x i8] c"%d \00", align 4 +@printf.str.1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 4 + +define private void @_Z4swapRiRi(ptr noundef %0, ptr noundef %1) { + %a = alloca ptr, align 8 + %b = alloca ptr, align 8 + %temp = alloca i32, align 4 + store ptr %0, ptr %a, align 8 + store ptr %1, ptr %b, align 8 + %3 = load ptr, ptr %a, align 8 + %4 = load i32, ptr %3, align 4 + store i32 %4, ptr %temp, align 4 + %5 = load ptr, ptr %a, align 8 + %6 = load ptr, ptr %b, align 8 + %7 = load i32, ptr %6, align 4 + store i32 %7, ptr %5, align 4 + %8 = load ptr, ptr %b, align 8 + %9 = load i32, ptr %temp, align 4 + store i32 %9, ptr %8, align 4 + ret void +} + +define private void @_Z4sortRA10_iPFbiiE(ptr noundef %0, { ptr, ptr, i64 } noundef %1) { + %array = alloca ptr, align 8 + %sortFct = alloca { ptr, ptr, i64 }, align 8 + %i = alloca i32, align 4 + %j = alloca i32, align 4 + store ptr %0, ptr %array, align 8 + store { ptr, ptr, i64 } %1, ptr %sortFct, align 8 + store i32 0, ptr %i, align 4 + br label %for.head.L8 + +for.head.L8: ; preds = %for.tail.L8, %2 + %3 = load i32, ptr %i, align 4 + %4 = sext i32 %3 to i64 + %5 = icmp slt i64 %4, 9 + br i1 %5, label %for.body.L8, label %for.exit.L8 + +for.body.L8: ; preds = %for.head.L8 + store i32 0, ptr %j, align 4 + br label %for.head.L9 + +for.head.L9: ; preds = %for.tail.L9, %for.body.L8 + %6 = load i32, ptr %i, align 4 + %7 = sext i32 %6 to i64 + %8 = sub nsw i64 10, %7 + %9 = sub nsw i64 %8, 1 + %10 = load i32, ptr %j, align 4 + %11 = sext i32 %10 to i64 + %12 = icmp slt i64 %11, %9 + br i1 %12, label %for.body.L9, label %for.exit.L9 + +for.body.L9: ; preds = %for.head.L9 + %13 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %sortFct, i32 0, i32 1 + %captures = load ptr, ptr %13, align 8 + %14 = load i32, ptr %j, align 4 + %15 = load ptr, ptr %array, align 8 + %16 = getelementptr inbounds [10 x i32], ptr %15, i64 0, i32 %14 + %17 = load i32, ptr %16, align 4 + %18 = load i32, ptr %j, align 4 + %19 = add nsw i32 %18, 1 + %20 = load ptr, ptr %array, align 8 + %21 = getelementptr inbounds [10 x i32], ptr %20, i64 0, i32 %19 + %22 = load i32, ptr %21, align 4 + %fct = load ptr, ptr %sortFct, align 8 + %23 = call i1 %fct(ptr %captures, i32 %17, i32 %22) + br i1 %23, label %if.then.L10, label %if.exit.L10 + +if.then.L10: ; preds = %for.body.L9 + %24 = load i32, ptr %j, align 4 + %25 = load ptr, ptr %array, align 8 + %26 = getelementptr inbounds [10 x i32], ptr %25, i64 0, i32 %24 + %27 = load i32, ptr %j, align 4 + %28 = add nsw i32 %27, 1 + %29 = load ptr, ptr %array, align 8 + %30 = getelementptr inbounds [10 x i32], ptr %29, i64 0, i32 %28 + call void @_Z4swapRiRi(ptr noundef %26, ptr noundef %30) + br label %if.exit.L10 + +if.exit.L10: ; preds = %if.then.L10, %for.body.L9 + br label %for.tail.L9 + +for.tail.L9: ; preds = %if.exit.L10 + %31 = load i32, ptr %j, align 4 + %32 = add nsw i32 %31, 1 + store i32 %32, ptr %j, align 4 + br label %for.head.L9 + +for.exit.L9: ; preds = %for.head.L9 + br label %for.tail.L8 + +for.tail.L8: ; preds = %for.exit.L9 + %33 = load i32, ptr %i, align 4 + %34 = add nsw i32 %33, 1 + store i32 %34, ptr %i, align 4 + br label %for.head.L8 + +for.exit.L8: ; preds = %for.head.L8 + ret void +} + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %array = alloca [10 x i32], align 4 + %fat.ptr = alloca { ptr, ptr, i64 }, align 8 + store i32 0, ptr %result, align 4 + store [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1], ptr %array, align 4 + store ptr @_Z15lambda.L19C17.0ii, ptr %fat.ptr, align 8 + %1 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 1 + store ptr null, ptr %1, align 8 + %2 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 2 + store i64 0, ptr %2, align 8 + %3 = load { ptr, ptr, i64 }, ptr %fat.ptr, align 8 + call void @_Z4sortRA10_iPFbiiE(ptr noundef %array, { ptr, ptr, i64 } noundef %3) + call void @_Z10printArrayRA10_i(ptr noundef %array) + %4 = load i32, ptr %result, align 4 + ret i32 %4 +} + +define private i1 @_Z15lambda.L19C17.0ii(ptr %0, i32 %1, i32 %2) { + %captures = alloca ptr, align 8 + %a = alloca i32, align 4 + %b = alloca i32, align 4 + store ptr %0, ptr %captures, align 8 + store i32 %1, ptr %a, align 4 + store i32 %2, ptr %b, align 4 + %4 = load i32, ptr %a, align 4 + %5 = load i32, ptr %b, align 4 + %6 = icmp sgt i32 %4, %5 + ret i1 %6 +} + +define private void @_Z10printArrayRA10_i(ptr noundef %0) { + %array = alloca ptr, align 8 + %i = alloca i32, align 4 + store ptr %0, ptr %array, align 8 + store i32 0, ptr %i, align 4 + br label %for.head.L24 + +for.head.L24: ; preds = %for.tail.L24, %1 + %2 = load i32, ptr %i, align 4 + %3 = sext i32 %2 to i64 + %4 = icmp slt i64 %3, 10 + br i1 %4, label %for.body.L24, label %for.exit.L24 + +for.body.L24: ; preds = %for.head.L24 + %5 = load i32, ptr %i, align 4 + %6 = load ptr, ptr %array, align 8 + %7 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i32 %5 + %8 = load i32, ptr %7, align 4 + %9 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %8) + br label %for.tail.L24 + +for.tail.L24: ; preds = %for.body.L24 + %10 = load i32, ptr %i, align 4 + %11 = add nsw i32 %10, 1 + store i32 %11, ptr %i, align 4 + br label %for.head.L24 + +for.exit.L24: ; preds = %for.head.L24 + %12 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1) + ret void +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} diff --git a/test/test-files/irgenerator/lambdas/success-foreign-captures/ir-code-macos-amd64.ll b/test/test-files/irgenerator/lambdas/success-foreign-captures/ir-code-macos-amd64.ll new file mode 100644 index 000000000..7c0a7cf34 --- /dev/null +++ b/test/test-files/irgenerator/lambdas/success-foreign-captures/ir-code-macos-amd64.ll @@ -0,0 +1,154 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.string.0 = private unnamed_addr constant [58 x i8] c"Assertion failed: Condition 'x == 6' evaluated to false.\0A\00", align 4 +@anon.string.1 = private unnamed_addr constant [57 x i8] c"Assertion failed: Condition 'l2(x)' evaluated to false.\0A\00", align 4 +@anon.string.2 = private unnamed_addr constant [59 x i8] c"Assertion failed: Condition 'x == 11' evaluated to false.\0A\00", align 4 +@printf.str.0 = private unnamed_addr constant [19 x i8] c"All tests passed!\0A\00", align 4 + +define private void @_Z4testPFCvRiEPFCbRiE({ ptr, ptr, i64 } noundef %0, { ptr, ptr, i64 } noundef %1) { + %l1 = alloca { ptr, ptr, i64 }, align 8 + %l2 = alloca { ptr, ptr, i64 }, align 8 + %x = alloca i32, align 4 + store { ptr, ptr, i64 } %0, ptr %l1, align 8 + store { ptr, ptr, i64 } %1, ptr %l2, align 8 + store i32 1, ptr %x, align 4 + %3 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %l1, i32 0, i32 1 + %captures = load ptr, ptr %3, align 8 + %fct = load ptr, ptr %l1, align 8 + call void %fct(ptr %captures, ptr %x) + %4 = load i32, ptr %x, align 4 + %5 = icmp eq i32 %4, 6 + br i1 %5, label %assert.exit.L4, label %assert.then.L4, !prof !5 + +assert.then.L4: ; preds = %2 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L4: ; preds = %2 + %7 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %l2, i32 0, i32 1 + %captures1 = load ptr, ptr %7, align 8 + %fct2 = load ptr, ptr %l2, align 8 + %8 = call i1 %fct2(ptr %captures1, ptr %x) + br i1 %8, label %assert.exit.L5, label %assert.then.L5, !prof !5 + +assert.then.L5: ; preds = %assert.exit.L4 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.1) + call void @exit(i32 1) + unreachable + +assert.exit.L5: ; preds = %assert.exit.L4 + %10 = load i32, ptr %x, align 4 + %11 = icmp eq i32 %10, 11 + br i1 %11, label %assert.exit.L6, label %assert.then.L6, !prof !5 + +assert.then.L6: ; preds = %assert.exit.L5 + %12 = call i32 (ptr, ...) @printf(ptr @anon.string.2) + call void @exit(i32 1) + unreachable + +assert.exit.L6: ; preds = %assert.exit.L5 + ret void +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #0 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #1 + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #2 { + %result = alloca i32, align 4 + %z = alloca i32, align 4 + %w = alloca i32, align 4 + %captures = alloca { i32, i32 }, align 8 + %fat.ptr = alloca { ptr, ptr, i64 }, align 8 + %foo1 = alloca { ptr, ptr, i64 }, align 8 + %captures1 = alloca { i32, i32 }, align 8 + %fat.ptr2 = alloca { ptr, ptr, i64 }, align 8 + %foo2 = alloca { ptr, ptr, i64 }, align 8 + store i32 0, ptr %result, align 4 + store i32 2, ptr %z, align 4 + store i32 3, ptr %w, align 4 + %1 = load i32, ptr %w, align 4 + store i32 %1, ptr %captures, align 4 + %2 = load i32, ptr %z, align 4 + %3 = getelementptr inbounds nuw { i32, i32 }, ptr %captures, i32 0, i32 1 + store i32 %2, ptr %3, align 4 + store ptr @_Z15lambda.L12C20.0Ri, ptr %fat.ptr, align 8 + %4 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 1 + store ptr %captures, ptr %4, align 8 + %5 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr, i32 0, i32 2 + store i64 8, ptr %5, align 8 + %6 = load { ptr, ptr, i64 }, ptr %fat.ptr, align 8 + store { ptr, ptr, i64 } %6, ptr %foo1, align 8 + %7 = load i32, ptr %w, align 4 + store i32 %7, ptr %captures1, align 4 + %8 = load i32, ptr %z, align 4 + %9 = getelementptr inbounds nuw { i32, i32 }, ptr %captures1, i32 0, i32 1 + store i32 %8, ptr %9, align 4 + store ptr @_Z15lambda.L15C26.0Ri, ptr %fat.ptr2, align 8 + %10 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr2, i32 0, i32 1 + store ptr %captures1, ptr %10, align 8 + %11 = getelementptr inbounds nuw { ptr, ptr, i64 }, ptr %fat.ptr2, i32 0, i32 2 + store i64 8, ptr %11, align 8 + %12 = load { ptr, ptr, i64 }, ptr %fat.ptr2, align 8 + store { ptr, ptr, i64 } %12, ptr %foo2, align 8 + %13 = load { ptr, ptr, i64 }, ptr %foo1, align 8 + %14 = load { ptr, ptr, i64 }, ptr %foo2, align 8 + call void @_Z4testPFCvRiEPFCbRiE({ ptr, ptr, i64 } noundef %13, { ptr, ptr, i64 } noundef %14) + %15 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0) + %16 = load i32, ptr %result, align 4 + ret i32 %16 +} + +define private void @_Z15lambda.L12C20.0Ri(ptr noundef nonnull dereferenceable(8) %0, ptr %1) { + %captures = alloca ptr, align 8 + %x = alloca ptr, align 8 + store ptr %0, ptr %captures, align 8 + store ptr %1, ptr %x, align 8 + %3 = load ptr, ptr %captures, align 8 + %z = getelementptr inbounds nuw { i32, i32 }, ptr %3, i32 0, i32 1 + %4 = load i32, ptr %z, align 4 + %5 = load i32, ptr %3, align 4 + %6 = add nsw i32 %4, %5 + %7 = load ptr, ptr %x, align 8 + %8 = load i32, ptr %7, align 4 + %9 = add nsw i32 %8, %6 + store i32 %9, ptr %7, align 4 + ret void +} + +define private i1 @_Z15lambda.L15C26.0Ri(ptr noundef nonnull dereferenceable(8) %0, ptr %1) { + %result = alloca i1, align 1 + %captures = alloca ptr, align 8 + %x = alloca ptr, align 8 + store ptr %0, ptr %captures, align 8 + store ptr %1, ptr %x, align 8 + %3 = load ptr, ptr %captures, align 8 + %z = getelementptr inbounds nuw { i32, i32 }, ptr %3, i32 0, i32 1 + %4 = load i32, ptr %z, align 4 + %5 = load i32, ptr %3, align 4 + %6 = add nsw i32 %4, %5 + %7 = load ptr, ptr %x, align 8 + %8 = load i32, ptr %7, align 4 + %9 = add nsw i32 %8, %6 + store i32 %9, ptr %7, align 4 + ret i1 true +} + +attributes #0 = { nofree nounwind } +attributes #1 = { cold noreturn nounwind } +attributes #2 = { mustprogress noinline norecurse nounwind optnone uwtable } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/irgenerator/operators/success-operator-overloading-binary/ir-code-macos-amd64.ll b/test/test-files/irgenerator/operators/success-operator-overloading-binary/ir-code-macos-amd64.ll new file mode 100644 index 000000000..047ca7ca0 --- /dev/null +++ b/test/test-files/irgenerator/operators/success-operator-overloading-binary/ir-code-macos-amd64.ll @@ -0,0 +1,333 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +%struct.Counter = type { i64 } + +@printf.str.0 = private unnamed_addr constant [20 x i8] c"Counter1 value: %d\0A\00", align 4 +@printf.str.1 = private unnamed_addr constant [20 x i8] c"Counter2 value: %d\0A\00", align 4 +@printf.str.2 = private unnamed_addr constant [20 x i8] c"Counter3 value: %d\0A\00", align 4 +@printf.str.3 = private unnamed_addr constant [20 x i8] c"Counter4 value: %d\0A\00", align 4 +@printf.str.4 = private unnamed_addr constant [20 x i8] c"Counter5 value: %d\0A\00", align 4 +@printf.str.5 = private unnamed_addr constant [20 x i8] c"Counter6 value: %d\0A\00", align 4 +@printf.str.6 = private unnamed_addr constant [20 x i8] c"Counter7 value: %d\0A\00", align 4 +@printf.str.7 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 +@printf.str.8 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 +@printf.str.9 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 +@printf.str.10 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 +@printf.str.11 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 +@anon.string.0 = private unnamed_addr constant [61 x i8] c"Assertion failed: Condition 'res == 14' evaluated to false.\0A\00", align 4 +@printf.str.12 = private unnamed_addr constant [20 x i8] c"Counter8 value: %d\0A\00", align 4 + +define private void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %1) { + %this = alloca ptr, align 8 + %initialValue = alloca i64, align 8 + store ptr %0, ptr %this, align 8 + store i64 %1, ptr %initialValue, align 8 + %3 = load ptr, ptr %this, align 8 + store i64 0, ptr %3, align 8 + %4 = load ptr, ptr %this, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %4, i64 0, i32 0 + %5 = load i64, ptr %initialValue, align 8 + store i64 %5, ptr %value.addr, align 8 + ret void +} + +define private noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %0) { + %result = alloca i64, align 8 + %this = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %2, i64 0, i32 0 + %3 = load i64, ptr %value.addr, align 8 + ret i64 %3 +} + +define private noundef %struct.Counter @_Z7op.plus7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = add nsw i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private noundef %struct.Counter @_Z8op.minus7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = sub nsw i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private noundef %struct.Counter @_Z6op.mul7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = mul nsw i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private noundef %struct.Counter @_Z6op.div7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = sdiv i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private noundef %struct.Counter @_Z6op.shl7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = shl i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private noundef %struct.Counter @_Z6op.shr7Counter7Counter(%struct.Counter noundef %0, %struct.Counter noundef %1) { + %result = alloca %struct.Counter, align 8 + %c1 = alloca %struct.Counter, align 8 + %c2 = alloca %struct.Counter, align 8 + %3 = alloca %struct.Counter, align 8 + store %struct.Counter %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c1, i64 0, i32 0 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %4 = load i64, ptr %value.addr, align 8 + %5 = load i64, ptr %value.addr1, align 8 + %6 = ashr i64 %4, %5 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %6) + %7 = load %struct.Counter, ptr %3, align 8 + ret %struct.Counter %7 +} + +define private void @_Z12op.plusequalR7Counter7Counter(ptr noundef %0, %struct.Counter noundef %1) { + %c1 = alloca ptr, align 8 + %c2 = alloca %struct.Counter, align 8 + store ptr %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %3 = load ptr, ptr %c1, align 8 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %3, i64 0, i32 0 + %4 = load i64, ptr %value.addr1, align 8 + %5 = load i64, ptr %value.addr, align 8 + %6 = add nsw i64 %4, %5 + store i64 %6, ptr %value.addr1, align 8 + ret void +} + +define private void @_Z13op.minusequalR7Counter7Counter(ptr noundef %0, %struct.Counter noundef %1) { + %c1 = alloca ptr, align 8 + %c2 = alloca %struct.Counter, align 8 + store ptr %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %3 = load ptr, ptr %c1, align 8 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %3, i64 0, i32 0 + %4 = load i64, ptr %value.addr1, align 8 + %5 = load i64, ptr %value.addr, align 8 + %6 = sub nsw i64 %4, %5 + store i64 %6, ptr %value.addr1, align 8 + ret void +} + +define private void @_Z11op.mulequalR7Counter7Counter(ptr noundef %0, %struct.Counter noundef %1) { + %c1 = alloca ptr, align 8 + %c2 = alloca %struct.Counter, align 8 + store ptr %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %3 = load ptr, ptr %c1, align 8 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %3, i64 0, i32 0 + %4 = load i64, ptr %value.addr1, align 8 + %5 = load i64, ptr %value.addr, align 8 + %6 = mul nsw i64 %4, %5 + store i64 %6, ptr %value.addr1, align 8 + ret void +} + +define private void @_Z11op.divequalR7Counter7Counter(ptr noundef %0, %struct.Counter noundef %1) { + %c1 = alloca ptr, align 8 + %c2 = alloca %struct.Counter, align 8 + store ptr %0, ptr %c1, align 8 + store %struct.Counter %1, ptr %c2, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %c2, i64 0, i32 0 + %3 = load ptr, ptr %c1, align 8 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %3, i64 0, i32 0 + %4 = load i64, ptr %value.addr1, align 8 + %5 = load i64, ptr %value.addr, align 8 + %6 = sdiv i64 %4, %5 + store i64 %6, ptr %value.addr1, align 8 + ret void +} + +define private noundef ptr @_Z12op.subscriptR7Counterj(ptr noundef %0, i32 noundef %1) { + %result = alloca ptr, align 8 + %c = alloca ptr, align 8 + %summand = alloca i32, align 4 + store ptr %0, ptr %c, align 8 + store i32 %1, ptr %summand, align 4 + %3 = load ptr, ptr %c, align 8 + %value.addr = getelementptr inbounds %struct.Counter, ptr %3, i64 0, i32 0 + %4 = load i32, ptr %summand, align 4 + %5 = sext i32 %4 to i64 + %6 = load i64, ptr %value.addr, align 8 + %7 = add i64 %6, %5 + store i64 %7, ptr %value.addr, align 8 + %8 = load ptr, ptr %c, align 8 + %value.addr1 = getelementptr inbounds %struct.Counter, ptr %8, i64 0, i32 0 + ret ptr %value.addr1 +} + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 { + %result = alloca i32, align 4 + %counter1 = alloca %struct.Counter, align 8 + %counter2 = alloca %struct.Counter, align 8 + %counter3 = alloca %struct.Counter, align 8 + %counter4 = alloca %struct.Counter, align 8 + %counter5 = alloca %struct.Counter, align 8 + %counter6 = alloca %struct.Counter, align 8 + %counter7 = alloca %struct.Counter, align 8 + %counter8 = alloca %struct.Counter, align 8 + %res = alloca i64, align 8 + store i32 0, ptr %result, align 4 + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %counter1, i64 noundef 2) + call void @_ZN7Counter4ctorEl(ptr noundef nonnull align 8 dereferenceable(8) %counter2, i64 noundef 3) + %1 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter1) + %2 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i64 noundef %1) + %3 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter2) + %4 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1, i64 noundef %3) + %5 = load %struct.Counter, ptr %counter1, align 8 + %6 = load %struct.Counter, ptr %counter2, align 8 + %7 = call %struct.Counter @_Z7op.plus7Counter7Counter(%struct.Counter %5, %struct.Counter %6) + store %struct.Counter %7, ptr %counter3, align 8 + %8 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter3) + %9 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.2, i64 noundef %8) + %10 = load %struct.Counter, ptr %counter3, align 8 + %11 = load %struct.Counter, ptr %counter2, align 8 + %12 = call %struct.Counter @_Z8op.minus7Counter7Counter(%struct.Counter %10, %struct.Counter %11) + store %struct.Counter %12, ptr %counter4, align 8 + %13 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter4) + %14 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.3, i64 noundef %13) + %15 = load %struct.Counter, ptr %counter4, align 8 + %16 = load %struct.Counter, ptr %counter2, align 8 + %17 = call %struct.Counter @_Z6op.mul7Counter7Counter(%struct.Counter %15, %struct.Counter %16) + store %struct.Counter %17, ptr %counter5, align 8 + %18 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter5) + %19 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.4, i64 noundef %18) + %20 = load %struct.Counter, ptr %counter5, align 8 + %21 = load %struct.Counter, ptr %counter2, align 8 + %22 = call %struct.Counter @_Z6op.div7Counter7Counter(%struct.Counter %20, %struct.Counter %21) + store %struct.Counter %22, ptr %counter6, align 8 + %23 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter6) + %24 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.5, i64 noundef %23) + %25 = load %struct.Counter, ptr %counter6, align 8 + %26 = load %struct.Counter, ptr %counter2, align 8 + %27 = call %struct.Counter @_Z6op.shl7Counter7Counter(%struct.Counter %25, %struct.Counter %26) + store %struct.Counter %27, ptr %counter7, align 8 + %28 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter7) + %29 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.6, i64 noundef %28) + %30 = load %struct.Counter, ptr %counter7, align 8 + %31 = load %struct.Counter, ptr %counter2, align 8 + %32 = call %struct.Counter @_Z6op.shr7Counter7Counter(%struct.Counter %30, %struct.Counter %31) + store %struct.Counter %32, ptr %counter8, align 8 + %33 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %34 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.7, i64 noundef %33) + %35 = load %struct.Counter, ptr %counter2, align 8 + call void @_Z12op.plusequalR7Counter7Counter(ptr %counter8, %struct.Counter %35) + %36 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %37 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.8, i64 noundef %36) + %38 = load %struct.Counter, ptr %counter2, align 8 + call void @_Z13op.minusequalR7Counter7Counter(ptr %counter8, %struct.Counter %38) + %39 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %40 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.9, i64 noundef %39) + %41 = load %struct.Counter, ptr %counter2, align 8 + call void @_Z11op.mulequalR7Counter7Counter(ptr %counter8, %struct.Counter %41) + %42 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %43 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.10, i64 noundef %42) + %44 = load %struct.Counter, ptr %counter2, align 8 + call void @_Z11op.divequalR7Counter7Counter(ptr %counter8, %struct.Counter %44) + %45 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %46 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.11, i64 noundef %45) + %47 = call ptr @_Z12op.subscriptR7Counterj(ptr %counter8, i32 12) + %48 = load i64, ptr %47, align 8 + store i64 %48, ptr %res, align 8 + %49 = load i64, ptr %res, align 8 + %50 = icmp eq i64 %49, 14 + br i1 %50, label %assert.exit.L86, label %assert.then.L86, !prof !5 + +assert.then.L86: ; preds = %0 + %51 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L86: ; preds = %0 + %52 = call noundef i64 @_ZN7Counter8getValueEv(ptr noundef nonnull align 8 dereferenceable(8) %counter8) + %53 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.12, i64 noundef %52) + %54 = load i32, ptr %result, align 4 + ret i32 %54 +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #2 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable } +attributes #1 = { nofree nounwind } +attributes #2 = { cold noreturn nounwind } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/irgenerator/testing/error-testing-failing-test2/ir-code-macos-amd64.ll b/test/test-files/irgenerator/testing/error-testing-failing-test2/ir-code-macos-amd64.ll new file mode 100644 index 000000000..5b0892a06 --- /dev/null +++ b/test/test-files/irgenerator/testing/error-testing-failing-test2/ir-code-macos-amd64.ll @@ -0,0 +1,77 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.string.0 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(1, 2) == 4' evaluated to false.\0A\00", align 4 +@allStartMsg0 = private unnamed_addr constant [56 x i8] c"[==========] Running %d test(s) from %d source file(s)\0A\00", align 4 +@allEndMsg0 = private unnamed_addr constant [52 x i8] c"[==========] Ran %d test(s) from %d source file(s)\0A\00", align 4 +@fileStartMsg0 = private unnamed_addr constant [41 x i8] c"[----------] Running %d test(s) from %s\0A\00", align 4 +@fileEndMsg0 = private unnamed_addr constant [38 x i8] c"[----------] Ran %d test(s) from %s\0A\0A\00", align 4 +@runMsg0 = private unnamed_addr constant [17 x i8] c"[ RUN ] %s\0A\00", align 4 +@successMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[32m[ PASSED ]\1B[0m\1B[22m %s\0A\00", align 4 +@errorMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[31m[ FAILED ]\1B[0m\1B[22m %s\0A\00", align 4 +@skippedMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[33m[ SKIPPED ]\1B[0m\1B[22m %s\0A\00", align 4 +@fileName0 = private unnamed_addr constant [13 x i8] c"source.spice\00", align 4 +@testName0 = private unnamed_addr constant [8 x i8] c"testAdd\00", align 4 + +define private noundef i32 @_Z3addii(i32 noundef %0, i32 noundef %1) { + %result = alloca i32, align 4 + %a = alloca i32, align 4 + %b = alloca i32, align 4 + store i32 %0, ptr %a, align 4 + store i32 %1, ptr %b, align 4 + %3 = load i32, ptr %a, align 4 + %4 = load i32, ptr %b, align 4 + %5 = add nsw i32 %3, %4 + ret i32 %5 +} + +define dso_local noundef zeroext i1 @_Z7testAddv() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3addii(i32 noundef 1, i32 noundef 2) + %2 = icmp eq i32 %1, 4 + br i1 %2, label %assert.exit.L7, label %assert.then.L7, !prof !5 + +assert.then.L7: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L7: ; preds = %0 + ret i1 true +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #0 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #1 + +; Function Attrs: mustprogress noinline nounwind optnone uwtable +define i32 @main() #2 { + %1 = call i32 (ptr, ...) @printf(ptr @allStartMsg0, i32 1, i32 1) + %2 = call i32 (ptr, ...) @printf(ptr @fileStartMsg0, i32 1, ptr @fileName0) + %3 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName0) + %4 = call i1 @_Z7testAddv() + %5 = select i1 %4, ptr @successMsg0, ptr @errorMsg0 + %6 = call i32 (ptr, ...) @printf(ptr %5, ptr @testName0) + %7 = call i32 (ptr, ...) @printf(ptr @fileEndMsg0, i32 1, ptr @fileName0) + %8 = call i32 (ptr, ...) @printf(ptr @allEndMsg0, i32 1, i32 1) + %9 = and i1 true, %4 + %10 = xor i1 %9, true + %11 = zext i1 %10 to i32 + ret i32 %11 +} + +attributes #0 = { nofree nounwind } +attributes #1 = { cold noreturn nounwind } +attributes #2 = { mustprogress noinline nounwind optnone uwtable } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/irgenerator/testing/success-testing-multi-file/ir-code-macos-amd64.ll b/test/test-files/irgenerator/testing/success-testing-multi-file/ir-code-macos-amd64.ll new file mode 100644 index 000000000..440123571 --- /dev/null +++ b/test/test-files/irgenerator/testing/success-testing-multi-file/ir-code-macos-amd64.ll @@ -0,0 +1,162 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.string.0 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(1, 2) == 3' evaluated to false.\0A\00", align 4 +@anon.string.1 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(2, 2) == 4' evaluated to false.\0A\00", align 4 +@anon.string.2 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(3, 2) == 5' evaluated to false.\0A\00", align 4 +@anon.string.3 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(5, -4) == 1' evaluated to false.\0A\00", align 4 +@anon.string.4 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(2, 8) == 10' evaluated to false.\0A\00", align 4 +@anon.string.5 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(-3, 5) == 2' evaluated to false.\0A\00", align 4 +@allStartMsg0 = private unnamed_addr constant [56 x i8] c"[==========] Running %d test(s) from %d source file(s)\0A\00", align 4 +@allEndMsg0 = private unnamed_addr constant [52 x i8] c"[==========] Ran %d test(s) from %d source file(s)\0A\00", align 4 +@fileStartMsg0 = private unnamed_addr constant [41 x i8] c"[----------] Running %d test(s) from %s\0A\00", align 4 +@fileEndMsg0 = private unnamed_addr constant [38 x i8] c"[----------] Ran %d test(s) from %s\0A\0A\00", align 4 +@runMsg0 = private unnamed_addr constant [17 x i8] c"[ RUN ] %s\0A\00", align 4 +@successMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[32m[ PASSED ]\1B[0m\1B[22m %s\0A\00", align 4 +@errorMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[31m[ FAILED ]\1B[0m\1B[22m %s\0A\00", align 4 +@skippedMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[33m[ SKIPPED ]\1B[0m\1B[22m %s\0A\00", align 4 +@fileName0 = private unnamed_addr constant [14 x i8] c"source2.spice\00", align 4 +@testName0 = private unnamed_addr constant [9 x i8] c"testSub1\00", align 4 +@testName1 = private unnamed_addr constant [9 x i8] c"testSub2\00", align 4 +@fileName1 = private unnamed_addr constant [13 x i8] c"source.spice\00", align 4 +@testName2 = private unnamed_addr constant [9 x i8] c"testAdd1\00", align 4 +@testName3 = private unnamed_addr constant [9 x i8] c"testAdd2\00", align 4 + +define private noundef i32 @_Z3addii(i32 noundef %0, i32 noundef %1) { + %result = alloca i32, align 4 + %a = alloca i32, align 4 + %b = alloca i32, align 4 + store i32 %0, ptr %a, align 4 + store i32 %1, ptr %b, align 4 + %3 = load i32, ptr %a, align 4 + %4 = load i32, ptr %b, align 4 + %5 = add nsw i32 %3, %4 + ret i32 %5 +} + +define dso_local noundef zeroext i1 @_Z8testAdd1v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3addii(i32 noundef 1, i32 noundef 2) + %2 = icmp eq i32 %1, 3 + br i1 %2, label %assert.exit.L9, label %assert.then.L9, !prof !5 + +assert.then.L9: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L9: ; preds = %0 + %4 = call noundef i32 @_Z3addii(i32 noundef 2, i32 noundef 2) + %5 = icmp eq i32 %4, 4 + br i1 %5, label %assert.exit.L10, label %assert.then.L10, !prof !5 + +assert.then.L10: ; preds = %assert.exit.L9 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.1) + call void @exit(i32 1) + unreachable + +assert.exit.L10: ; preds = %assert.exit.L9 + %7 = call noundef i32 @_Z3addii(i32 noundef 3, i32 noundef 2) + %8 = icmp eq i32 %7, 5 + br i1 %8, label %assert.exit.L11, label %assert.then.L11, !prof !5 + +assert.then.L11: ; preds = %assert.exit.L10 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.2) + call void @exit(i32 1) + unreachable + +assert.exit.L11: ; preds = %assert.exit.L10 + ret i1 true +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #0 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #1 + +define dso_local noundef zeroext i1 @_Z8testAdd2v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3addii(i32 noundef 5, i32 noundef -4) + %2 = icmp eq i32 %1, 1 + br i1 %2, label %assert.exit.L17, label %assert.then.L17, !prof !5 + +assert.then.L17: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.3) + call void @exit(i32 1) + unreachable + +assert.exit.L17: ; preds = %0 + %4 = call noundef i32 @_Z3addii(i32 noundef 2, i32 noundef 8) + %5 = icmp eq i32 %4, 10 + br i1 %5, label %assert.exit.L18, label %assert.then.L18, !prof !5 + +assert.then.L18: ; preds = %assert.exit.L17 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.4) + call void @exit(i32 1) + unreachable + +assert.exit.L18: ; preds = %assert.exit.L17 + %7 = call noundef i32 @_Z3addii(i32 noundef -3, i32 noundef 5) + %8 = icmp eq i32 %7, 2 + br i1 %8, label %assert.exit.L19, label %assert.then.L19, !prof !5 + +assert.then.L19: ; preds = %assert.exit.L18 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.5) + call void @exit(i32 1) + unreachable + +assert.exit.L19: ; preds = %assert.exit.L18 + ret i1 true +} + +; Function Attrs: mustprogress noinline nounwind optnone uwtable +define i32 @main() #2 { + %1 = call i32 (ptr, ...) @printf(ptr @allStartMsg0, i32 4, i32 2) + %2 = call i32 (ptr, ...) @printf(ptr @fileStartMsg0, i32 2, ptr @fileName0) + %3 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName0) + %4 = call i1 @_Z8testSub1v() + %5 = select i1 %4, ptr @successMsg0, ptr @errorMsg0 + %6 = call i32 (ptr, ...) @printf(ptr %5, ptr @testName0) + %7 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName1) + %8 = call i1 @_Z8testSub2v() + %9 = select i1 %8, ptr @successMsg0, ptr @errorMsg0 + %10 = call i32 (ptr, ...) @printf(ptr %9, ptr @testName1) + %11 = call i32 (ptr, ...) @printf(ptr @fileEndMsg0, i32 2, ptr @fileName0) + %12 = call i32 (ptr, ...) @printf(ptr @fileStartMsg0, i32 2, ptr @fileName1) + %13 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName2) + %14 = call i1 @_Z8testAdd1v() + %15 = select i1 %14, ptr @successMsg0, ptr @errorMsg0 + %16 = call i32 (ptr, ...) @printf(ptr %15, ptr @testName2) + %17 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName3) + %18 = call i1 @_Z8testAdd2v() + %19 = select i1 %18, ptr @successMsg0, ptr @errorMsg0 + %20 = call i32 (ptr, ...) @printf(ptr %19, ptr @testName3) + %21 = call i32 (ptr, ...) @printf(ptr @fileEndMsg0, i32 2, ptr @fileName1) + %22 = call i32 (ptr, ...) @printf(ptr @allEndMsg0, i32 4, i32 2) + %23 = and i1 true, %4 + %24 = and i1 %23, %8 + %25 = and i1 %24, %14 + %26 = and i1 %25, %18 + %27 = xor i1 %26, true + %28 = zext i1 %27 to i32 + ret i32 %28 +} + +declare i1 @_Z8testSub1v() + +declare i1 @_Z8testSub2v() + +attributes #0 = { nofree nounwind } +attributes #1 = { cold noreturn nounwind } +attributes #2 = { mustprogress noinline nounwind optnone uwtable } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/irgenerator/testing/success-testing/ir-code-macos-amd64.ll b/test/test-files/irgenerator/testing/success-testing/ir-code-macos-amd64.ll new file mode 100644 index 000000000..ca5e9e04d --- /dev/null +++ b/test/test-files/irgenerator/testing/success-testing/ir-code-macos-amd64.ll @@ -0,0 +1,240 @@ +; ModuleID = 'source.spice' +source_filename = "source.spice" + +@anon.string.0 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(1, 2) == 3' evaluated to false.\0A\00", align 4 +@anon.string.1 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(2, 2) == 4' evaluated to false.\0A\00", align 4 +@anon.string.2 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'add(3, 2) == 5' evaluated to false.\0A\00", align 4 +@anon.string.3 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(5, -4) == 1' evaluated to false.\0A\00", align 4 +@anon.string.4 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(2, 8) == 10' evaluated to false.\0A\00", align 4 +@anon.string.5 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'add(-3, 5) == 2' evaluated to false.\0A\00", align 4 +@anon.string.6 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'sub(1, 2) == -1' evaluated to false.\0A\00", align 4 +@anon.string.7 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'sub(2, 2) == 0' evaluated to false.\0A\00", align 4 +@anon.string.8 = private unnamed_addr constant [66 x i8] c"Assertion failed: Condition 'sub(3, 2) == 1' evaluated to false.\0A\00", align 4 +@anon.string.9 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'sub(5, -4) == 9' evaluated to false.\0A\00", align 4 +@anon.string.10 = private unnamed_addr constant [67 x i8] c"Assertion failed: Condition 'sub(2, 8) == -6' evaluated to false.\0A\00", align 4 +@anon.string.11 = private unnamed_addr constant [68 x i8] c"Assertion failed: Condition 'sub(-3, 5) == -8' evaluated to false.\0A\00", align 4 +@allStartMsg0 = private unnamed_addr constant [56 x i8] c"[==========] Running %d test(s) from %d source file(s)\0A\00", align 4 +@allEndMsg0 = private unnamed_addr constant [52 x i8] c"[==========] Ran %d test(s) from %d source file(s)\0A\00", align 4 +@fileStartMsg0 = private unnamed_addr constant [41 x i8] c"[----------] Running %d test(s) from %s\0A\00", align 4 +@fileEndMsg0 = private unnamed_addr constant [38 x i8] c"[----------] Ran %d test(s) from %s\0A\0A\00", align 4 +@runMsg0 = private unnamed_addr constant [17 x i8] c"[ RUN ] %s\0A\00", align 4 +@successMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[32m[ PASSED ]\1B[0m\1B[22m %s\0A\00", align 4 +@errorMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[31m[ FAILED ]\1B[0m\1B[22m %s\0A\00", align 4 +@skippedMsg0 = private unnamed_addr constant [35 x i8] c"\1B[1m\1B[33m[ SKIPPED ]\1B[0m\1B[22m %s\0A\00", align 4 +@fileName0 = private unnamed_addr constant [13 x i8] c"source.spice\00", align 4 +@testName0 = private unnamed_addr constant [53 x i8] c"testAdd1 (Simple 'happy-path' test for add function)\00", align 4 +@testName1 = private unnamed_addr constant [9 x i8] c"testAdd2\00", align 4 +@testName2 = private unnamed_addr constant [9 x i8] c"testSub1\00", align 4 +@testName3 = private unnamed_addr constant [9 x i8] c"testSub2\00", align 4 + +define private noundef i32 @_Z3addii(i32 noundef %0, i32 noundef %1) { + %result = alloca i32, align 4 + %a = alloca i32, align 4 + %b = alloca i32, align 4 + store i32 %0, ptr %a, align 4 + store i32 %1, ptr %b, align 4 + %3 = load i32, ptr %a, align 4 + %4 = load i32, ptr %b, align 4 + %5 = add nsw i32 %3, %4 + ret i32 %5 +} + +define private noundef i32 @_Z3subii(i32 noundef %0, i32 noundef %1) { + %result = alloca i32, align 4 + %a = alloca i32, align 4 + %b = alloca i32, align 4 + store i32 %0, ptr %a, align 4 + store i32 %1, ptr %b, align 4 + %3 = load i32, ptr %a, align 4 + %4 = load i32, ptr %b, align 4 + %5 = sub nsw i32 %3, %4 + ret i32 %5 +} + +define dso_local noundef zeroext i1 @_Z8testAdd1v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3addii(i32 noundef 1, i32 noundef 2) + %2 = icmp eq i32 %1, 3 + br i1 %2, label %assert.exit.L12, label %assert.then.L12, !prof !5 + +assert.then.L12: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.0) + call void @exit(i32 1) + unreachable + +assert.exit.L12: ; preds = %0 + %4 = call noundef i32 @_Z3addii(i32 noundef 2, i32 noundef 2) + %5 = icmp eq i32 %4, 4 + br i1 %5, label %assert.exit.L13, label %assert.then.L13, !prof !5 + +assert.then.L13: ; preds = %assert.exit.L12 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.1) + call void @exit(i32 1) + unreachable + +assert.exit.L13: ; preds = %assert.exit.L12 + %7 = call noundef i32 @_Z3addii(i32 noundef 3, i32 noundef 2) + %8 = icmp eq i32 %7, 5 + br i1 %8, label %assert.exit.L14, label %assert.then.L14, !prof !5 + +assert.then.L14: ; preds = %assert.exit.L13 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.2) + call void @exit(i32 1) + unreachable + +assert.exit.L14: ; preds = %assert.exit.L13 + ret i1 true +} + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #0 + +; Function Attrs: cold noreturn nounwind +declare void @exit(i32) #1 + +define dso_local noundef zeroext i1 @_Z8testAdd2v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3addii(i32 noundef 5, i32 noundef -4) + %2 = icmp eq i32 %1, 1 + br i1 %2, label %assert.exit.L20, label %assert.then.L20, !prof !5 + +assert.then.L20: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.3) + call void @exit(i32 1) + unreachable + +assert.exit.L20: ; preds = %0 + %4 = call noundef i32 @_Z3addii(i32 noundef 2, i32 noundef 8) + %5 = icmp eq i32 %4, 10 + br i1 %5, label %assert.exit.L21, label %assert.then.L21, !prof !5 + +assert.then.L21: ; preds = %assert.exit.L20 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.4) + call void @exit(i32 1) + unreachable + +assert.exit.L21: ; preds = %assert.exit.L20 + %7 = call noundef i32 @_Z3addii(i32 noundef -3, i32 noundef 5) + %8 = icmp eq i32 %7, 2 + br i1 %8, label %assert.exit.L22, label %assert.then.L22, !prof !5 + +assert.then.L22: ; preds = %assert.exit.L21 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.5) + call void @exit(i32 1) + unreachable + +assert.exit.L22: ; preds = %assert.exit.L21 + ret i1 false +} + +define dso_local noundef zeroext i1 @_Z8testSub1v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3subii(i32 noundef 1, i32 noundef 2) + %2 = icmp eq i32 %1, -1 + br i1 %2, label %assert.exit.L28, label %assert.then.L28, !prof !5 + +assert.then.L28: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.6) + call void @exit(i32 1) + unreachable + +assert.exit.L28: ; preds = %0 + %4 = call noundef i32 @_Z3subii(i32 noundef 2, i32 noundef 2) + %5 = icmp eq i32 %4, 0 + br i1 %5, label %assert.exit.L29, label %assert.then.L29, !prof !5 + +assert.then.L29: ; preds = %assert.exit.L28 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.7) + call void @exit(i32 1) + unreachable + +assert.exit.L29: ; preds = %assert.exit.L28 + %7 = call noundef i32 @_Z3subii(i32 noundef 3, i32 noundef 2) + %8 = icmp eq i32 %7, 1 + br i1 %8, label %assert.exit.L30, label %assert.then.L30, !prof !5 + +assert.then.L30: ; preds = %assert.exit.L29 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.8) + call void @exit(i32 1) + unreachable + +assert.exit.L30: ; preds = %assert.exit.L29 + ret i1 true +} + +define dso_local noundef zeroext i1 @_Z8testSub2v() { + %result = alloca i1, align 1 + %1 = call noundef i32 @_Z3subii(i32 noundef 5, i32 noundef -4) + %2 = icmp eq i32 %1, 9 + br i1 %2, label %assert.exit.L36, label %assert.then.L36, !prof !5 + +assert.then.L36: ; preds = %0 + %3 = call i32 (ptr, ...) @printf(ptr @anon.string.9) + call void @exit(i32 1) + unreachable + +assert.exit.L36: ; preds = %0 + %4 = call noundef i32 @_Z3subii(i32 noundef 2, i32 noundef 8) + %5 = icmp eq i32 %4, -6 + br i1 %5, label %assert.exit.L37, label %assert.then.L37, !prof !5 + +assert.then.L37: ; preds = %assert.exit.L36 + %6 = call i32 (ptr, ...) @printf(ptr @anon.string.10) + call void @exit(i32 1) + unreachable + +assert.exit.L37: ; preds = %assert.exit.L36 + %7 = call noundef i32 @_Z3subii(i32 noundef -3, i32 noundef 5) + %8 = icmp eq i32 %7, -8 + br i1 %8, label %assert.exit.L38, label %assert.then.L38, !prof !5 + +assert.then.L38: ; preds = %assert.exit.L37 + %9 = call i32 (ptr, ...) @printf(ptr @anon.string.11) + call void @exit(i32 1) + unreachable + +assert.exit.L38: ; preds = %assert.exit.L37 + ret i1 true +} + +; Function Attrs: mustprogress noinline nounwind optnone uwtable +define i32 @main() #2 { + %1 = call i32 (ptr, ...) @printf(ptr @allStartMsg0, i32 4, i32 1) + %2 = call i32 (ptr, ...) @printf(ptr @fileStartMsg0, i32 4, ptr @fileName0) + %3 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName0) + %4 = call i1 @_Z8testAdd1v() + %5 = select i1 %4, ptr @successMsg0, ptr @errorMsg0 + %6 = call i32 (ptr, ...) @printf(ptr %5, ptr @testName0) + %7 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName1) + %8 = call i32 (ptr, ...) @printf(ptr @skippedMsg0, ptr @testName1) + %9 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName2) + %10 = call i1 @_Z8testSub1v() + %11 = select i1 %10, ptr @successMsg0, ptr @errorMsg0 + %12 = call i32 (ptr, ...) @printf(ptr %11, ptr @testName2) + %13 = call i32 (ptr, ...) @printf(ptr @runMsg0, ptr @testName3) + %14 = call i1 @_Z8testSub2v() + %15 = select i1 %14, ptr @successMsg0, ptr @errorMsg0 + %16 = call i32 (ptr, ...) @printf(ptr %15, ptr @testName3) + %17 = call i32 (ptr, ...) @printf(ptr @fileEndMsg0, i32 4, ptr @fileName0) + %18 = call i32 (ptr, ...) @printf(ptr @allEndMsg0, i32 4, i32 1) + %19 = and i1 true, %4 + %20 = and i1 %19, %10 + %21 = and i1 %20, %14 + %22 = xor i1 %21, true + %23 = zext i1 %22 to i32 + ret i32 %23 +} + +attributes #0 = { nofree nounwind } +attributes #1 = { cold noreturn nounwind } +attributes #2 = { mustprogress noinline nounwind optnone uwtable } + +!llvm.module.flags = !{!0, !1, !2, !3} +!llvm.ident = !{!4} + +!0 = !{i32 8, !"PIC Level", i32 2} +!1 = !{i32 7, !"PIE Level", i32 2} +!2 = !{i32 7, !"uwtable", i32 2} +!3 = !{i32 7, !"frame-pointer", i32 2} +!4 = !{!"spice version dev (https://github.com/spicelang/spice)"} +!5 = !{!"branch_weights", i32 1048575, i32 1} diff --git a/test/test-files/typechecker/imports/error-imported-file-not-existing/exception-macos-amd64.out b/test/test-files/typechecker/imports/error-imported-file-not-existing/exception-macos-amd64.out new file mode 100644 index 000000000..72a12707e --- /dev/null +++ b/test/test-files/typechecker/imports/error-imported-file-not-existing/exception-macos-amd64.out @@ -0,0 +1,10 @@ +[Error|Semantic] ./source.spice:1:1: +Imported source file not existing: The source file 'source2.spice' was not found + +The following paths were checked with descending priority: +- source2_darwin_x86_64.spice +- source2_darwin.spice +- source2.spice + +1 import "source2" as s2; + ^^^^^^^^^^^^^^^^^^^^^^^ \ No newline at end of file diff --git a/test/test-files/typechecker/imports/error-imported-std-not-existing/exception-macos-amd64.out b/test/test-files/typechecker/imports/error-imported-std-not-existing/exception-macos-amd64.out new file mode 100644 index 000000000..bb6edbfa2 --- /dev/null +++ b/test/test-files/typechecker/imports/error-imported-std-not-existing/exception-macos-amd64.out @@ -0,0 +1,10 @@ +[Error|Semantic] ./source.spice:1:1: +Imported source file not existing: The source file 'foo.spice' was not found + +The following paths were checked with descending priority: +- foo_darwin_x86_64.spice +- foo_darwin.spice +- foo.spice + +1 import "std/non-existing/foo" as foo; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \ No newline at end of file