mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
73 lines
2.1 KiB
C
73 lines
2.1 KiB
C
// #target: x64-darwin
|
|
module test;
|
|
|
|
fn void test()
|
|
{
|
|
int[3] x;
|
|
int g = 0;
|
|
foreach (z : x)
|
|
{
|
|
if (z > 0) break;
|
|
if (z == 1) continue;
|
|
g += z;
|
|
}
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
define void @test.test() #0 {
|
|
entry:
|
|
%x = alloca [3 x i32], align 4
|
|
%g = alloca i32, align 4
|
|
%idx = alloca i64, align 8
|
|
%z = alloca i32, align 4
|
|
%0 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 0
|
|
store i32 0, i32* %0, align 4
|
|
%1 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 1
|
|
store i32 0, i32* %1, align 4
|
|
%2 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 2
|
|
store i32 0, i32* %2, align 4
|
|
store i32 0, i32* %g, align 4
|
|
store i64 0, i64* %idx, align 8
|
|
br label %foreach.cond
|
|
|
|
foreach.cond: ; preds = %foreach.inc, %entry
|
|
%3 = load i64, i64* %idx, align 8
|
|
%lt = icmp ult i64 %3, 3
|
|
br i1 %lt, label %foreach.body, label %foreach.exit
|
|
|
|
foreach.body: ; preds = %foreach.cond
|
|
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 %3
|
|
%5 = load i32, i32* %4, align 4
|
|
store i32 %5, i32* %z, align 4
|
|
%6 = load i32, i32* %z, align 4
|
|
%gt = icmp sgt i32 %6, 0
|
|
br i1 %gt, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %foreach.body
|
|
br label %foreach.exit
|
|
|
|
if.exit: ; preds = %foreach.body
|
|
%7 = load i32, i32* %z, align 4
|
|
%eq = icmp eq i32 %7, 1
|
|
br i1 %eq, label %if.then1, label %if.exit2
|
|
|
|
if.then1: ; preds = %if.exit
|
|
br label %foreach.inc
|
|
|
|
if.exit2: ; preds = %if.exit
|
|
%8 = load i32, i32* %g, align 4
|
|
%9 = load i32, i32* %z, align 4
|
|
%add = add i32 %8, %9
|
|
store i32 %add, i32* %g, align 4
|
|
br label %foreach.inc
|
|
|
|
foreach.inc: ; preds = %if.exit2, %if.then1
|
|
%10 = load i64, i64* %idx, align 8
|
|
%11 = add i64 %10, 1
|
|
store i64 %11, i64* %idx, align 8
|
|
br label %foreach.cond
|
|
|
|
foreach.exit: ; preds = %if.then, %foreach.cond
|
|
ret void
|
|
}
|