aboutsummaryrefslogtreecommitdiff
path: root/test/stage2
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2021-01-10 17:36:01 +0100
committerAndrew Kelley <andrew@ziglang.org>2021-01-10 17:47:34 -0800
commite1d8073d2fc0df6fbc5ce983312e3da374a9889b (patch)
tree11d8c5aa24c3c09dfec529c2d9f150511623c7b9 /test/stage2
parent2117489e05ddf7cc4653feecbf47b3637276d6b6 (diff)
downloadzig-e1d8073d2fc0df6fbc5ce983312e3da374a9889b.tar.gz
zig-e1d8073d2fc0df6fbc5ce983312e3da374a9889b.zip
stage2: add support for loops in LLVM backend
A simple `while(true) {}` loop generates the following LLVMIR: ``` define i32 @main() { Entry: br label %Loop Loop: ; preds = %Loop, %Entry br label %Loop } ``` Also implement TZIR printing for loops and add a corresponding test.
Diffstat (limited to 'test/stage2')
-rw-r--r--test/stage2/llvm.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig
index eecea3d1f0..69622714a7 100644
--- a/test/stage2/llvm.zig
+++ b/test/stage2/llvm.zig
@@ -111,4 +111,25 @@ pub fn addCases(ctx: *TestContext) !void {
\\}
, "");
}
+
+ {
+ var case = ctx.exeUsingLlvmBackend("while loops", linux_x64);
+
+ case.addCompareOutput(
+ \\fn assert(ok: bool) void {
+ \\ if (!ok) unreachable;
+ \\}
+ \\
+ \\export fn main() c_int {
+ \\ var sum: u32 = 0;
+ \\ var i: u32 = 0;
+ \\ while (i < 5) : (i += 1) {
+ \\ sum += i;
+ \\ }
+ \\ assert(sum == 10);
+ \\ assert(i == 5);
+ \\ return 0;
+ \\}
+ , "");
+ }
}