ssa: index/indexAddr check max
This commit is contained in:
@@ -1215,73 +1215,75 @@ _llgo_24: ; preds = %_llgo_22
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_25: ; preds = %_llgo_27
|
||||
%52 = fptosi double %69 to i64
|
||||
%53 = add i64 %70, 2
|
||||
%52 = fptosi double %71 to i64
|
||||
%53 = add i64 %72, 2
|
||||
%54 = add i64 %52, 48
|
||||
%55 = trunc i64 %54 to i8
|
||||
%56 = icmp slt i64 %53, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %56)
|
||||
%57 = getelementptr inbounds i8, ptr %20, i64 %53
|
||||
store i8 %55, ptr %57, align 1
|
||||
%58 = sitofp i64 %52 to double
|
||||
%59 = fsub double %69, %58
|
||||
%60 = fmul double %59, 1.000000e+01
|
||||
%61 = add i64 %70, 1
|
||||
%57 = icmp sge i64 %53, 14
|
||||
%58 = or i1 %57, %56
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %58)
|
||||
%59 = getelementptr inbounds i8, ptr %20, i64 %53
|
||||
store i8 %55, ptr %59, align 1
|
||||
%60 = sitofp i64 %52 to double
|
||||
%61 = fsub double %71, %60
|
||||
%62 = fmul double %61, 1.000000e+01
|
||||
%63 = add i64 %72, 1
|
||||
br label %_llgo_27
|
||||
|
||||
_llgo_26: ; preds = %_llgo_27
|
||||
%62 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
%63 = load i8, ptr %62, align 1
|
||||
%64 = getelementptr inbounds i8, ptr %20, i64 1
|
||||
store i8 %63, ptr %64, align 1
|
||||
%65 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
store i8 46, ptr %65, align 1
|
||||
%66 = getelementptr inbounds i8, ptr %20, i64 9
|
||||
store i8 101, ptr %66, align 1
|
||||
%67 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 43, ptr %67, align 1
|
||||
%68 = icmp slt i64 %28, 0
|
||||
br i1 %68, label %_llgo_28, label %_llgo_29
|
||||
%64 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
%65 = load i8, ptr %64, align 1
|
||||
%66 = getelementptr inbounds i8, ptr %20, i64 1
|
||||
store i8 %65, ptr %66, align 1
|
||||
%67 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
store i8 46, ptr %67, align 1
|
||||
%68 = getelementptr inbounds i8, ptr %20, i64 9
|
||||
store i8 101, ptr %68, align 1
|
||||
%69 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 43, ptr %69, align 1
|
||||
%70 = icmp slt i64 %28, 0
|
||||
br i1 %70, label %_llgo_28, label %_llgo_29
|
||||
|
||||
_llgo_27: ; preds = %_llgo_25, %_llgo_12
|
||||
%69 = phi double [ %27, %_llgo_12 ], [ %60, %_llgo_25 ]
|
||||
%70 = phi i64 [ 0, %_llgo_12 ], [ %61, %_llgo_25 ]
|
||||
%71 = icmp slt i64 %70, 7
|
||||
br i1 %71, label %_llgo_25, label %_llgo_26
|
||||
%71 = phi double [ %27, %_llgo_12 ], [ %62, %_llgo_25 ]
|
||||
%72 = phi i64 [ 0, %_llgo_12 ], [ %63, %_llgo_25 ]
|
||||
%73 = icmp slt i64 %72, 7
|
||||
br i1 %73, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_28: ; preds = %_llgo_26
|
||||
%72 = sub i64 0, %28
|
||||
%73 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 45, ptr %73, align 1
|
||||
%74 = sub i64 0, %28
|
||||
%75 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 45, ptr %75, align 1
|
||||
br label %_llgo_29
|
||||
|
||||
_llgo_29: ; preds = %_llgo_28, %_llgo_26
|
||||
%74 = phi i64 [ %28, %_llgo_26 ], [ %72, %_llgo_28 ]
|
||||
%75 = sdiv i64 %74, 100
|
||||
%76 = trunc i64 %75 to i8
|
||||
%77 = add i8 %76, 48
|
||||
%78 = getelementptr inbounds i8, ptr %20, i64 11
|
||||
store i8 %77, ptr %78, align 1
|
||||
%79 = sdiv i64 %74, 10
|
||||
%80 = trunc i64 %79 to i8
|
||||
%81 = urem i8 %80, 10
|
||||
%82 = add i8 %81, 48
|
||||
%83 = getelementptr inbounds i8, ptr %20, i64 12
|
||||
store i8 %82, ptr %83, align 1
|
||||
%84 = srem i64 %74, 10
|
||||
%85 = trunc i64 %84 to i8
|
||||
%86 = add i8 %85, 48
|
||||
%87 = getelementptr inbounds i8, ptr %20, i64 13
|
||||
store i8 %86, ptr %87, align 1
|
||||
%88 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%89 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 0
|
||||
store ptr %20, ptr %89, align 8
|
||||
%90 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 1
|
||||
store i64 14, ptr %90, align 4
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 2
|
||||
store i64 14, ptr %91, align 4
|
||||
%92 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, align 8
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %92)
|
||||
%76 = phi i64 [ %28, %_llgo_26 ], [ %74, %_llgo_28 ]
|
||||
%77 = sdiv i64 %76, 100
|
||||
%78 = trunc i64 %77 to i8
|
||||
%79 = add i8 %78, 48
|
||||
%80 = getelementptr inbounds i8, ptr %20, i64 11
|
||||
store i8 %79, ptr %80, align 1
|
||||
%81 = sdiv i64 %76, 10
|
||||
%82 = trunc i64 %81 to i8
|
||||
%83 = urem i8 %82, 10
|
||||
%84 = add i8 %83, 48
|
||||
%85 = getelementptr inbounds i8, ptr %20, i64 12
|
||||
store i8 %84, ptr %85, align 1
|
||||
%86 = srem i64 %76, 10
|
||||
%87 = trunc i64 %86 to i8
|
||||
%88 = add i8 %87, 48
|
||||
%89 = getelementptr inbounds i8, ptr %20, i64 13
|
||||
store i8 %88, ptr %89, align 1
|
||||
%90 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 0
|
||||
store ptr %20, ptr %91, align 8
|
||||
%92 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 1
|
||||
store i64 14, ptr %92, align 4
|
||||
%93 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 2
|
||||
store i64 14, ptr %93, align 4
|
||||
%94 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, align 8
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %94)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -1291,7 +1293,7 @@ _llgo_0:
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = urem i64 %20, 16
|
||||
%2 = urem i64 %28, 16
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
|
||||
store ptr @9, ptr %4, align 8
|
||||
@@ -1299,46 +1301,55 @@ _llgo_1: ; preds = %_llgo_3
|
||||
store i64 16, ptr %5, align 4
|
||||
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %6, 0
|
||||
%8 = getelementptr inbounds i8, ptr %7, i64 %2
|
||||
%9 = load i8, ptr %8, align 1
|
||||
%10 = icmp slt i64 %21, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = getelementptr inbounds i8, ptr %1, i64 %21
|
||||
store i8 %9, ptr %11, align 1
|
||||
%12 = icmp ult i64 %20, 16
|
||||
br i1 %12, label %_llgo_5, label %_llgo_4
|
||||
%8 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %6, 1
|
||||
%9 = icmp sge i64 %2, %8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds i8, ptr %7, i64 %2
|
||||
%11 = load i8, ptr %10, align 1
|
||||
%12 = icmp slt i64 %29, 0
|
||||
%13 = icmp sge i64 %29, 100
|
||||
%14 = or i1 %13, %12
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds i8, ptr %1, i64 %29
|
||||
store i8 %11, ptr %15, align 1
|
||||
%16 = icmp ult i64 %28, 16
|
||||
br i1 %16, label %_llgo_5, label %_llgo_4
|
||||
|
||||
_llgo_2: ; preds = %_llgo_5, %_llgo_3
|
||||
%13 = sub i64 %21, 1
|
||||
%14 = icmp slt i64 %13, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds i8, ptr %1, i64 %13
|
||||
store i8 120, ptr %15, align 1
|
||||
%16 = sub i64 %13, 1
|
||||
%17 = icmp slt i64 %16, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17)
|
||||
%18 = getelementptr inbounds i8, ptr %1, i64 %16
|
||||
store i8 48, ptr %18, align 1
|
||||
%19 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %16, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %19)
|
||||
%17 = sub i64 %29, 1
|
||||
%18 = icmp slt i64 %17, 0
|
||||
%19 = icmp sge i64 %17, 100
|
||||
%20 = or i1 %19, %18
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %20)
|
||||
%21 = getelementptr inbounds i8, ptr %1, i64 %17
|
||||
store i8 120, ptr %21, align 1
|
||||
%22 = sub i64 %17, 1
|
||||
%23 = icmp slt i64 %22, 0
|
||||
%24 = icmp sge i64 %22, 100
|
||||
%25 = or i1 %24, %23
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %25)
|
||||
%26 = getelementptr inbounds i8, ptr %1, i64 %22
|
||||
store i8 48, ptr %26, align 1
|
||||
%27 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %22, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %27)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_4, %_llgo_0
|
||||
%20 = phi i64 [ %0, %_llgo_0 ], [ %23, %_llgo_4 ]
|
||||
%21 = phi i64 [ 99, %_llgo_0 ], [ %24, %_llgo_4 ]
|
||||
%22 = icmp sgt i64 %21, 0
|
||||
br i1 %22, label %_llgo_1, label %_llgo_2
|
||||
%28 = phi i64 [ %0, %_llgo_0 ], [ %31, %_llgo_4 ]
|
||||
%29 = phi i64 [ 99, %_llgo_0 ], [ %32, %_llgo_4 ]
|
||||
%30 = icmp sgt i64 %29, 0
|
||||
br i1 %30, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_1
|
||||
%23 = udiv i64 %20, 16
|
||||
%24 = sub i64 %21, 1
|
||||
%31 = udiv i64 %28, 16
|
||||
%32 = sub i64 %29, 1
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_5: ; preds = %_llgo_1
|
||||
%25 = sub i64 100, %21
|
||||
%26 = load i64, ptr @main.minhexdigits, align 4
|
||||
%27 = icmp sge i64 %25, %26
|
||||
br i1 %27, label %_llgo_2, label %_llgo_4
|
||||
%33 = sub i64 100, %29
|
||||
%34 = load i64, ptr @main.minhexdigits, align 4
|
||||
%35 = icmp sge i64 %33, %34
|
||||
br i1 %35, label %_llgo_2, label %_llgo_4
|
||||
}
|
||||
|
||||
define void @main.printint(i64 %0) {
|
||||
@@ -1375,30 +1386,33 @@ _llgo_1: ; preds = %_llgo_5, %_llgo_0
|
||||
br i1 %4, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%5 = icmp slt i64 %3, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %6, i64 %3
|
||||
%8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8
|
||||
%9 = icmp ne i64 %3, 0
|
||||
br i1 %9, label %_llgo_4, label %_llgo_5
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%7 = icmp slt i64 %3, 0
|
||||
%8 = icmp sge i64 %3, %6
|
||||
%9 = or i1 %8, %7
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i64 %3
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
|
||||
%12 = icmp ne i64 %3, 0
|
||||
br i1 %12, label %_llgo_4, label %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
call void @main.printnl()
|
||||
ret void
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
|
||||
store ptr @11, ptr %11, align 8
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
|
||||
store i64 1, ptr %12, align 4
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||
%13 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 0
|
||||
store ptr @11, ptr %14, align 8
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 1
|
||||
store i64 1, ptr %15, align 4
|
||||
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %13, align 8
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %16)
|
||||
br label %_llgo_5
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4, %_llgo_2
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %8)
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %11)
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
@@ -1439,30 +1453,32 @@ _llgo_0:
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = urem i64 %9, 10
|
||||
%2 = urem i64 %11, 10
|
||||
%3 = add i64 %2, 48
|
||||
%4 = trunc i64 %3 to i8
|
||||
%5 = icmp slt i64 %10, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = getelementptr inbounds i8, ptr %1, i64 %10
|
||||
store i8 %4, ptr %6, align 1
|
||||
%7 = icmp ult i64 %9, 10
|
||||
br i1 %7, label %_llgo_2, label %_llgo_4
|
||||
%5 = icmp slt i64 %12, 0
|
||||
%6 = icmp sge i64 %12, 100
|
||||
%7 = or i1 %6, %5
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %7)
|
||||
%8 = getelementptr inbounds i8, ptr %1, i64 %12
|
||||
store i8 %4, ptr %8, align 1
|
||||
%9 = icmp ult i64 %11, 10
|
||||
br i1 %9, label %_llgo_2, label %_llgo_4
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_3
|
||||
%8 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %10, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %8)
|
||||
%10 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %12, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %10)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_4, %_llgo_0
|
||||
%9 = phi i64 [ %0, %_llgo_0 ], [ %12, %_llgo_4 ]
|
||||
%10 = phi i64 [ 99, %_llgo_0 ], [ %13, %_llgo_4 ]
|
||||
%11 = icmp sgt i64 %10, 0
|
||||
br i1 %11, label %_llgo_1, label %_llgo_2
|
||||
%11 = phi i64 [ %0, %_llgo_0 ], [ %14, %_llgo_4 ]
|
||||
%12 = phi i64 [ 99, %_llgo_0 ], [ %15, %_llgo_4 ]
|
||||
%13 = icmp sgt i64 %12, 0
|
||||
br i1 %13, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_1
|
||||
%12 = udiv i64 %9, 10
|
||||
%13 = sub i64 %10, 1
|
||||
%14 = udiv i64 %11, 10
|
||||
%15 = sub i64 %12, 1
|
||||
br label %_llgo_3
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@ source_filename = "main"
|
||||
|
||||
define i8 @main.index(i8 %0) {
|
||||
_llgo_0:
|
||||
%1 = icmp slt i8 %0, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %1)
|
||||
%2 = zext i8 %0 to i64
|
||||
%3 = getelementptr inbounds i8, ptr @main.array, i64 %2
|
||||
%4 = load i8, ptr %3, align 1
|
||||
ret i8 %4
|
||||
%1 = sext i8 %0 to i64
|
||||
%2 = icmp slt i64 %1, 0
|
||||
%3 = icmp sge i64 %1, 8
|
||||
%4 = or i1 %3, %2
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %4)
|
||||
%5 = getelementptr inbounds i8, ptr @main.array, i64 %1
|
||||
%6 = load i8, ptr %5, align 1
|
||||
ret i8 %6
|
||||
}
|
||||
|
||||
define void @main.init() {
|
||||
|
||||
@@ -98,42 +98,45 @@ _llgo_1: ; preds = %_llgo_4, %_llgo_0
|
||||
br i1 %4, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%5 = icmp slt i64 %3, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %6, i64 %3
|
||||
%8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8
|
||||
%9 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 0
|
||||
%10 = load ptr, ptr @_llgo_int, align 8
|
||||
%11 = icmp eq ptr %9, %10
|
||||
br i1 %11, label %_llgo_4, label %_llgo_5
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%7 = icmp slt i64 %3, 0
|
||||
%8 = icmp sge i64 %3, %6
|
||||
%9 = or i1 %8, %7
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i64 %3
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %11, 0
|
||||
%13 = load ptr, ptr @_llgo_int, align 8
|
||||
%14 = icmp eq ptr %12, %13
|
||||
br i1 %14, label %_llgo_4, label %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret void
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 1
|
||||
%13 = ptrtoint ptr %12 to i64
|
||||
%14 = call i32 (ptr, ...) @printf(ptr @0, i64 %13)
|
||||
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %11, 1
|
||||
%16 = ptrtoint ptr %15 to i64
|
||||
%17 = call i32 (ptr, ...) @printf(ptr @0, i64 %16)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_5: ; preds = %_llgo_2
|
||||
%15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0
|
||||
store ptr @1, ptr %16, align 8
|
||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1
|
||||
store i64 21, ptr %17, align 4
|
||||
%18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
|
||||
%19 = load ptr, ptr @_llgo_string, align 8
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %18, ptr %20, align 8
|
||||
%21 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 0
|
||||
store ptr %19, ptr %22, align 8
|
||||
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 1
|
||||
store ptr %20, ptr %23, align 8
|
||||
%24 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %24)
|
||||
%18 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 0
|
||||
store ptr @1, ptr %19, align 8
|
||||
%20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 1
|
||||
store i64 21, ptr %20, align 4
|
||||
%21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %18, align 8
|
||||
%22 = load ptr, ptr @_llgo_string, align 8
|
||||
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %21, ptr %23, align 8
|
||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 0
|
||||
store ptr %22, ptr %25, align 8
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 1
|
||||
store ptr %23, ptr %26, align 8
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %27)
|
||||
unreachable
|
||||
}
|
||||
|
||||
|
||||
140
cl/_testgo/indexerr/in.go
Normal file
140
cl/_testgo/indexerr/in.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array -1 must error")
|
||||
}
|
||||
}()
|
||||
array(-1)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array 2 must error")
|
||||
}
|
||||
}()
|
||||
array(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array2 must error")
|
||||
}
|
||||
}()
|
||||
array2(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice -1 must error")
|
||||
}
|
||||
}()
|
||||
slice(-1)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice 2 must error")
|
||||
}
|
||||
}()
|
||||
slice(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice2 2 must error")
|
||||
}
|
||||
}()
|
||||
slice2(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n = -1
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("-1 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n uint = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n = -1
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("-1 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n uint = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func array(n int) {
|
||||
println([...]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func array2(n uint) {
|
||||
println([...]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func slice(n int) {
|
||||
println([]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func slice2(n int) {
|
||||
println([]int{1, 2}[n])
|
||||
}
|
||||
1
cl/_testgo/indexerr/out.ll
Normal file
1
cl/_testgo/indexerr/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
@@ -788,16 +788,19 @@ _llgo_2: ; preds = %_llgo_0
|
||||
%11 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 0
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %11, align 8
|
||||
%13 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %12, 0
|
||||
%14 = icmp slt i64 %10, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds i8, ptr %13, i64 %10
|
||||
%16 = load i8, ptr %15, align 1
|
||||
%17 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
%18 = load i64, ptr %17, align 4
|
||||
%19 = add i64 %18, 1
|
||||
%14 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %12, 1
|
||||
%15 = icmp slt i64 %10, 0
|
||||
%16 = icmp sge i64 %10, %14
|
||||
%17 = or i1 %16, %15
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17)
|
||||
%18 = getelementptr inbounds i8, ptr %13, i64 %10
|
||||
%19 = load i8, ptr %18, align 1
|
||||
%20 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %19, ptr %20, align 4
|
||||
%mrv1 = insertvalue { i8, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i8 %16, 0
|
||||
%21 = load i64, ptr %20, align 4
|
||||
%22 = add i64 %21, 1
|
||||
%23 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %22, ptr %23, align 4
|
||||
%mrv1 = insertvalue { i8, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i8 %19, 0
|
||||
%mrv2 = insertvalue { i8, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv1, %"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer, 1
|
||||
ret { i8, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv2
|
||||
}
|
||||
@@ -829,42 +832,45 @@ _llgo_2: ; preds = %_llgo_0
|
||||
%14 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 0
|
||||
%15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8
|
||||
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %15, 0
|
||||
%17 = icmp slt i64 %13, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17)
|
||||
%18 = getelementptr inbounds i8, ptr %16, i64 %13
|
||||
%19 = load i8, ptr %18, align 1
|
||||
%20 = icmp ult i8 %19, -128
|
||||
br i1 %20, label %_llgo_3, label %_llgo_4
|
||||
%17 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %15, 1
|
||||
%18 = icmp slt i64 %13, 0
|
||||
%19 = icmp sge i64 %13, %17
|
||||
%20 = or i1 %19, %18
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %20)
|
||||
%21 = getelementptr inbounds i8, ptr %16, i64 %13
|
||||
%22 = load i8, ptr %21, align 1
|
||||
%23 = icmp ult i8 %22, -128
|
||||
br i1 %23, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%21 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
%22 = load i64, ptr %21, align 4
|
||||
%23 = add i64 %22, 1
|
||||
%24 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %23, ptr %24, align 4
|
||||
%25 = sext i8 %19 to i32
|
||||
%mrv1 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i32 %25, 0
|
||||
%25 = load i64, ptr %24, align 4
|
||||
%26 = add i64 %25, 1
|
||||
%27 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %26, ptr %27, align 4
|
||||
%28 = sext i8 %22 to i32
|
||||
%mrv1 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i32 %28, 0
|
||||
%mrv2 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv1, i64 1, 1
|
||||
%mrv3 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv2, %"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer, 2
|
||||
ret { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv3
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%26 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 0
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %26, align 8
|
||||
%28 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
%29 = load i64, ptr %28, align 4
|
||||
%30 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %27, 1
|
||||
%31 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %27, i64 %29, i64 %30)
|
||||
%32 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String" %31)
|
||||
%33 = extractvalue { i32, i64 } %32, 0
|
||||
%34 = extractvalue { i32, i64 } %32, 1
|
||||
%35 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
%36 = load i64, ptr %35, align 4
|
||||
%37 = add i64 %36, %34
|
||||
%29 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 0
|
||||
%30 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8
|
||||
%31 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
%32 = load i64, ptr %31, align 4
|
||||
%33 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %30, 1
|
||||
%34 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %30, i64 %32, i64 %33)
|
||||
%35 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String" %34)
|
||||
%36 = extractvalue { i32, i64 } %35, 0
|
||||
%37 = extractvalue { i32, i64 } %35, 1
|
||||
%38 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %37, ptr %38, align 4
|
||||
%mrv4 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i32 %33, 0
|
||||
%mrv5 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv4, i64 %34, 1
|
||||
%39 = load i64, ptr %38, align 4
|
||||
%40 = add i64 %39, %37
|
||||
%41 = getelementptr inbounds %main.stringReader, ptr %0, i32 0, i32 1
|
||||
store i64 %40, ptr %41, align 4
|
||||
%mrv4 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } poison, i32 %36, 0
|
||||
%mrv5 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv4, i64 %37, 1
|
||||
%mrv6 = insertvalue { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv5, %"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer, 2
|
||||
ret { i32, i64, %"github.com/goplus/llgo/internal/runtime.iface" } %mrv6
|
||||
}
|
||||
|
||||
@@ -486,129 +486,135 @@ _llgo_3: ; preds = %_llgo_1
|
||||
%205 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromBytes"(%"github.com/goplus/llgo/internal/runtime.Slice" %199)
|
||||
%206 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRunes"(%"github.com/goplus/llgo/internal/runtime.Slice" %204)
|
||||
%207 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %199, 0
|
||||
%208 = getelementptr inbounds i8, ptr %207, i64 3
|
||||
%209 = load i8, ptr %208, align 1
|
||||
%210 = sext i8 %209 to i32
|
||||
%211 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %210)
|
||||
%212 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 0
|
||||
%213 = getelementptr inbounds i32, ptr %212, i64 0
|
||||
%214 = load i32, ptr %213, align 4
|
||||
%215 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %214)
|
||||
%208 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %199, 1
|
||||
%209 = icmp sge i64 3, %208
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %209)
|
||||
%210 = getelementptr inbounds i8, ptr %207, i64 3
|
||||
%211 = load i8, ptr %210, align 1
|
||||
%212 = sext i8 %211 to i32
|
||||
%213 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %212)
|
||||
%214 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 0
|
||||
%215 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 1
|
||||
%216 = icmp sge i64 0, %215
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %216)
|
||||
%217 = getelementptr inbounds i32, ptr %214, i64 0
|
||||
%218 = load i32, ptr %217, align 4
|
||||
%219 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %218)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %205)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %206)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %211)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %213)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %215)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %219)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%216 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%217 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %216, i32 0, i32 0
|
||||
store ptr @4, ptr %217, align 8
|
||||
%218 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %216, i32 0, i32 1
|
||||
store i64 3, ptr %218, align 4
|
||||
%219 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %216, align 8
|
||||
%220 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%221 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %220, i32 0, i32 0
|
||||
store ptr @4, ptr %221, align 8
|
||||
%222 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %220, i32 0, i32 1
|
||||
store i64 3, ptr %222, align 4
|
||||
%223 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %220, align 8
|
||||
%224 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %219, %"github.com/goplus/llgo/internal/runtime.String" %223)
|
||||
%225 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%226 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %225, i32 0, i32 0
|
||||
store ptr @4, ptr %226, align 8
|
||||
%227 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %225, i32 0, i32 1
|
||||
store i64 3, ptr %227, align 4
|
||||
%228 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %225, align 8
|
||||
%224 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%225 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %224, i32 0, i32 0
|
||||
store ptr @4, ptr %225, align 8
|
||||
%226 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %224, i32 0, i32 1
|
||||
store i64 3, ptr %226, align 4
|
||||
%227 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %224, align 8
|
||||
%228 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %223, %"github.com/goplus/llgo/internal/runtime.String" %227)
|
||||
%229 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%230 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %229, i32 0, i32 0
|
||||
store ptr @5, ptr %230, align 8
|
||||
store ptr @4, ptr %230, align 8
|
||||
%231 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %229, i32 0, i32 1
|
||||
store i64 3, ptr %231, align 4
|
||||
%232 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %229, align 8
|
||||
%233 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %228, %"github.com/goplus/llgo/internal/runtime.String" %232)
|
||||
%234 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%235 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %234, i32 0, i32 0
|
||||
store ptr @4, ptr %235, align 8
|
||||
%236 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %234, i32 0, i32 1
|
||||
store i64 3, ptr %236, align 4
|
||||
%237 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %234, align 8
|
||||
%233 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%234 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %233, i32 0, i32 0
|
||||
store ptr @5, ptr %234, align 8
|
||||
%235 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %233, i32 0, i32 1
|
||||
store i64 3, ptr %235, align 4
|
||||
%236 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %233, align 8
|
||||
%237 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %232, %"github.com/goplus/llgo/internal/runtime.String" %236)
|
||||
%238 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%239 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %238, i32 0, i32 0
|
||||
store ptr @5, ptr %239, align 8
|
||||
store ptr @4, ptr %239, align 8
|
||||
%240 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %238, i32 0, i32 1
|
||||
store i64 3, ptr %240, align 4
|
||||
%241 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %238, align 8
|
||||
%242 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %237, %"github.com/goplus/llgo/internal/runtime.String" %241)
|
||||
%243 = xor i1 %242, true
|
||||
%244 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%245 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %244, i32 0, i32 0
|
||||
store ptr @4, ptr %245, align 8
|
||||
%246 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %244, i32 0, i32 1
|
||||
store i64 3, ptr %246, align 4
|
||||
%247 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %244, align 8
|
||||
%242 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%243 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %242, i32 0, i32 0
|
||||
store ptr @5, ptr %243, align 8
|
||||
%244 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %242, i32 0, i32 1
|
||||
store i64 3, ptr %244, align 4
|
||||
%245 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %242, align 8
|
||||
%246 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %241, %"github.com/goplus/llgo/internal/runtime.String" %245)
|
||||
%247 = xor i1 %246, true
|
||||
%248 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%249 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %248, i32 0, i32 0
|
||||
store ptr @5, ptr %249, align 8
|
||||
store ptr @4, ptr %249, align 8
|
||||
%250 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %248, i32 0, i32 1
|
||||
store i64 3, ptr %250, align 4
|
||||
%251 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %248, align 8
|
||||
%252 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %247, %"github.com/goplus/llgo/internal/runtime.String" %251)
|
||||
%253 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%254 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %253, i32 0, i32 0
|
||||
store ptr @4, ptr %254, align 8
|
||||
%255 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %253, i32 0, i32 1
|
||||
store i64 3, ptr %255, align 4
|
||||
%256 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %253, align 8
|
||||
%252 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%253 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %252, i32 0, i32 0
|
||||
store ptr @5, ptr %253, align 8
|
||||
%254 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %252, i32 0, i32 1
|
||||
store i64 3, ptr %254, align 4
|
||||
%255 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %252, align 8
|
||||
%256 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %251, %"github.com/goplus/llgo/internal/runtime.String" %255)
|
||||
%257 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%258 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %257, i32 0, i32 0
|
||||
store ptr @5, ptr %258, align 8
|
||||
store ptr @4, ptr %258, align 8
|
||||
%259 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %257, i32 0, i32 1
|
||||
store i64 3, ptr %259, align 4
|
||||
%260 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %257, align 8
|
||||
%261 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %260, %"github.com/goplus/llgo/internal/runtime.String" %256)
|
||||
%262 = xor i1 %261, true
|
||||
%263 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%264 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %263, i32 0, i32 0
|
||||
store ptr @4, ptr %264, align 8
|
||||
%265 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %263, i32 0, i32 1
|
||||
store i64 3, ptr %265, align 4
|
||||
%266 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %263, align 8
|
||||
%261 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%262 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %261, i32 0, i32 0
|
||||
store ptr @5, ptr %262, align 8
|
||||
%263 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %261, i32 0, i32 1
|
||||
store i64 3, ptr %263, align 4
|
||||
%264 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %261, align 8
|
||||
%265 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %264, %"github.com/goplus/llgo/internal/runtime.String" %260)
|
||||
%266 = xor i1 %265, true
|
||||
%267 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%268 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %267, i32 0, i32 0
|
||||
store ptr @5, ptr %268, align 8
|
||||
store ptr @4, ptr %268, align 8
|
||||
%269 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %267, i32 0, i32 1
|
||||
store i64 3, ptr %269, align 4
|
||||
%270 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %267, align 8
|
||||
%271 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %270, %"github.com/goplus/llgo/internal/runtime.String" %266)
|
||||
%272 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%273 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %272, i32 0, i32 0
|
||||
store ptr @4, ptr %273, align 8
|
||||
%274 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %272, i32 0, i32 1
|
||||
store i64 3, ptr %274, align 4
|
||||
%275 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %272, align 8
|
||||
%271 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%272 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %271, i32 0, i32 0
|
||||
store ptr @5, ptr %272, align 8
|
||||
%273 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %271, i32 0, i32 1
|
||||
store i64 3, ptr %273, align 4
|
||||
%274 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %271, align 8
|
||||
%275 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %274, %"github.com/goplus/llgo/internal/runtime.String" %270)
|
||||
%276 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%277 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %276, i32 0, i32 0
|
||||
store ptr @5, ptr %277, align 8
|
||||
store ptr @4, ptr %277, align 8
|
||||
%278 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %276, i32 0, i32 1
|
||||
store i64 3, ptr %278, align 4
|
||||
%279 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %276, align 8
|
||||
%280 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %275, %"github.com/goplus/llgo/internal/runtime.String" %279)
|
||||
%281 = xor i1 %280, true
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %224)
|
||||
%280 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%281 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %280, i32 0, i32 0
|
||||
store ptr @5, ptr %281, align 8
|
||||
%282 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %280, i32 0, i32 1
|
||||
store i64 3, ptr %282, align 4
|
||||
%283 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %280, align 8
|
||||
%284 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %279, %"github.com/goplus/llgo/internal/runtime.String" %283)
|
||||
%285 = xor i1 %284, true
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %228)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %233)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %237)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %243)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %247)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %252)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %256)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %262)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %266)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %271)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %275)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %281)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %285)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
@@ -701,6 +707,8 @@ declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/ll
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRunes"(%"github.com/goplus/llgo/internal/runtime.Slice")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32)
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
@@ -24,19 +24,22 @@ _llgo_0:
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%6 = phi %"github.com/goplus/llgo/internal/runtime.String" [ %5, %_llgo_0 ], [ %14, %_llgo_2 ]
|
||||
%6 = phi %"github.com/goplus/llgo/internal/runtime.String" [ %5, %_llgo_0 ], [ %17, %_llgo_2 ]
|
||||
%7 = phi i64 [ -1, %_llgo_0 ], [ %8, %_llgo_2 ]
|
||||
%8 = add i64 %7, 1
|
||||
%9 = icmp slt i64 %8, %1
|
||||
br i1 %9, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%10 = icmp slt i64 %8, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i64 %8
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8
|
||||
%14 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %6, %"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||
%10 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%12 = icmp slt i64 %8, 0
|
||||
%13 = icmp sge i64 %8, %11
|
||||
%14 = or i1 %13, %12
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i64 %8
|
||||
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
|
||||
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %6, %"github.com/goplus/llgo/internal/runtime.String" %16)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
|
||||
@@ -13,24 +13,28 @@ source_filename = "main"
|
||||
|
||||
define ptr @main.Basic(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = getelementptr inbounds ptr, ptr @main.basicTypes, i64 %0
|
||||
%2 = load ptr, ptr %1, align 8
|
||||
ret ptr %2
|
||||
%1 = icmp sge i64 %0, 25
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %1)
|
||||
%2 = getelementptr inbounds ptr, ptr @main.basicTypes, i64 %0
|
||||
%3 = load ptr, ptr %2, align 8
|
||||
ret ptr %3
|
||||
}
|
||||
|
||||
define ptr @main.basicType(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 72)
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0
|
||||
%3 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
|
||||
%4 = load i64, ptr %3, align 4
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 2
|
||||
%6 = trunc i64 %0 to i32
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 6
|
||||
%8 = trunc i64 %0 to i8
|
||||
store i64 %4, ptr %2, align 4
|
||||
store i32 %6, ptr %5, align 4
|
||||
store i8 %8, ptr %7, align 1
|
||||
%3 = icmp sge i64 %0, 25
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %3)
|
||||
%4 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
|
||||
%5 = load i64, ptr %4, align 4
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 2
|
||||
%7 = trunc i64 %0 to i32
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 6
|
||||
%9 = trunc i64 %0 to i8
|
||||
store i64 %5, ptr %2, align 4
|
||||
store i32 %7, ptr %6, align 4
|
||||
store i8 %9, ptr %8, align 1
|
||||
ret ptr %1
|
||||
}
|
||||
|
||||
@@ -67,6 +71,8 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
||||
|
||||
@@ -110,55 +110,64 @@ _llgo_0:
|
||||
store i64 6, ptr %51, align 4
|
||||
%52 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %49, align 8
|
||||
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %52, 0
|
||||
%54 = getelementptr inbounds i8, ptr %53, i64 2
|
||||
%55 = load i8, ptr %54, align 1
|
||||
%56 = sext i8 %55 to i32
|
||||
%57 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %56)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %57)
|
||||
%54 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %52, 1
|
||||
%55 = icmp sge i64 2, %54
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %55)
|
||||
%56 = getelementptr inbounds i8, ptr %53, i64 2
|
||||
%57 = load i8, ptr %56, align 1
|
||||
%58 = sext i8 %57 to i32
|
||||
%59 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %58)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %59)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%58 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%59 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %58, i32 0, i32 0
|
||||
store ptr @0, ptr %59, align 8
|
||||
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %58, i32 0, i32 1
|
||||
store i64 6, ptr %60, align 4
|
||||
%61 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %58, align 8
|
||||
%62 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %61, 0
|
||||
%63 = getelementptr inbounds i8, ptr %62, i64 1
|
||||
%64 = load i8, ptr %63, align 1
|
||||
%65 = sext i8 %64 to i32
|
||||
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %65)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %66)
|
||||
%60 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 0
|
||||
store ptr @0, ptr %61, align 8
|
||||
%62 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 1
|
||||
store i64 6, ptr %62, align 4
|
||||
%63 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %60, align 8
|
||||
%64 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 0
|
||||
%65 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 1
|
||||
%66 = icmp sge i64 1, %65
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %66)
|
||||
%67 = getelementptr inbounds i8, ptr %64, i64 1
|
||||
%68 = load i8, ptr %67, align 1
|
||||
%69 = sext i8 %68 to i32
|
||||
%70 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %69)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %70)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%67 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
%68 = getelementptr inbounds i64, ptr %67, i64 0
|
||||
%69 = getelementptr inbounds i64, ptr %67, i64 1
|
||||
store i64 1, ptr %68, align 4
|
||||
store i64 2, ptr %69, align 4
|
||||
%70 = getelementptr inbounds i64, ptr %67, i64 1
|
||||
%71 = load i64, ptr %70, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %71)
|
||||
%71 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
%72 = getelementptr inbounds i64, ptr %71, i64 0
|
||||
%73 = getelementptr inbounds i64, ptr %71, i64 1
|
||||
store i64 1, ptr %72, align 4
|
||||
store i64 2, ptr %73, align 4
|
||||
%74 = getelementptr inbounds i64, ptr %71, i64 1
|
||||
%75 = load i64, ptr %74, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %75)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%72 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%73 = getelementptr inbounds i64, ptr %72, i64 0
|
||||
store i64 1, ptr %73, align 4
|
||||
%74 = getelementptr inbounds i64, ptr %72, i64 1
|
||||
store i64 2, ptr %74, align 4
|
||||
%75 = getelementptr inbounds i64, ptr %72, i64 2
|
||||
store i64 3, ptr %75, align 4
|
||||
%76 = getelementptr inbounds i64, ptr %72, i64 3
|
||||
store i64 4, ptr %76, align 4
|
||||
%77 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%78 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %77, i32 0, i32 0
|
||||
store ptr %72, ptr %78, align 8
|
||||
%79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %77, i32 0, i32 1
|
||||
store i64 4, ptr %79, align 4
|
||||
%80 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %77, i32 0, i32 2
|
||||
%76 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%77 = getelementptr inbounds i64, ptr %76, i64 0
|
||||
store i64 1, ptr %77, align 4
|
||||
%78 = getelementptr inbounds i64, ptr %76, i64 1
|
||||
store i64 2, ptr %78, align 4
|
||||
%79 = getelementptr inbounds i64, ptr %76, i64 2
|
||||
store i64 3, ptr %79, align 4
|
||||
%80 = getelementptr inbounds i64, ptr %76, i64 3
|
||||
store i64 4, ptr %80, align 4
|
||||
%81 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %77, align 8
|
||||
%82 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %81, 0
|
||||
%83 = getelementptr inbounds i64, ptr %82, i64 1
|
||||
%84 = load i64, ptr %83, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %84)
|
||||
%81 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 0
|
||||
store ptr %76, ptr %82, align 8
|
||||
%83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 1
|
||||
store i64 4, ptr %83, align 4
|
||||
%84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 2
|
||||
store i64 4, ptr %84, align 4
|
||||
%85 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, align 8
|
||||
%86 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %85, 0
|
||||
%87 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %85, 1
|
||||
%88 = icmp sge i64 1, %87
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %88)
|
||||
%89 = getelementptr inbounds i64, ptr %86, i64 1
|
||||
%90 = load i64, ptr %89, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %90)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 0)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
@@ -173,6 +182,8 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
@@ -36,11 +36,14 @@ _llgo_2: ; preds = %_llgo_1
|
||||
%13 = extractvalue { ptr, ptr } %1, 1
|
||||
%14 = extractvalue { ptr, ptr } %1, 0
|
||||
%15 = call i32 %14(ptr %13)
|
||||
%16 = icmp slt i64 %11, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %16)
|
||||
%17 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 0
|
||||
%18 = getelementptr inbounds i32, ptr %17, i64 %11
|
||||
store i32 %15, ptr %18, align 4
|
||||
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 0
|
||||
%17 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 1
|
||||
%18 = icmp slt i64 %11, 0
|
||||
%19 = icmp sge i64 %11, %17
|
||||
%20 = or i1 %19, %18
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %20)
|
||||
%21 = getelementptr inbounds i32, ptr %16, i64 %11
|
||||
store i32 %15, ptr %21, align 4
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
@@ -95,75 +98,84 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
br i1 %10, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%11 = icmp slt i64 %9, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
|
||||
%13 = getelementptr inbounds i32, ptr %12, i64 %9
|
||||
%14 = load i32, ptr %13, align 4
|
||||
%15 = call i32 (ptr, ...) @printf(ptr @0, i32 %14)
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 1
|
||||
%13 = icmp slt i64 %9, 0
|
||||
%14 = icmp sge i64 %9, %12
|
||||
%15 = or i1 %14, %13
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %15)
|
||||
%16 = getelementptr inbounds i32, ptr %11, i64 %9
|
||||
%17 = load i32, ptr %16, align 4
|
||||
%18 = call i32 (ptr, ...) @printf(ptr @0, i32 %17)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
store i32 1, ptr %16, align 4
|
||||
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%18 = getelementptr inbounds { ptr }, ptr %17, i32 0, i32 0
|
||||
store ptr %16, ptr %18, align 8
|
||||
%19 = alloca { ptr, ptr }, align 8
|
||||
%20 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 0
|
||||
store ptr @"main.main$1", ptr %20, align 8
|
||||
%21 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 1
|
||||
store ptr %17, ptr %21, align 8
|
||||
%22 = load { ptr, ptr }, ptr %19, align 8
|
||||
%23 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %22)
|
||||
%24 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 1
|
||||
%19 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
store i32 1, ptr %19, align 4
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%21 = getelementptr inbounds { ptr }, ptr %20, i32 0, i32 0
|
||||
store ptr %19, ptr %21, align 8
|
||||
%22 = alloca { ptr, ptr }, align 8
|
||||
%23 = getelementptr inbounds { ptr, ptr }, ptr %22, i32 0, i32 0
|
||||
store ptr @"main.main$1", ptr %23, align 8
|
||||
%24 = getelementptr inbounds { ptr, ptr }, ptr %22, i32 0, i32 1
|
||||
store ptr %20, ptr %24, align 8
|
||||
%25 = load { ptr, ptr }, ptr %22, align 8
|
||||
%26 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %25)
|
||||
%27 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 1
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_3
|
||||
%25 = phi i64 [ -1, %_llgo_3 ], [ %26, %_llgo_5 ]
|
||||
%26 = add i64 %25, 1
|
||||
%27 = icmp slt i64 %26, %24
|
||||
br i1 %27, label %_llgo_5, label %_llgo_6
|
||||
%28 = phi i64 [ -1, %_llgo_3 ], [ %29, %_llgo_5 ]
|
||||
%29 = add i64 %28, 1
|
||||
%30 = icmp slt i64 %29, %27
|
||||
br i1 %30, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%28 = icmp slt i64 %26, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %28)
|
||||
%29 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 0
|
||||
%30 = getelementptr inbounds i32, ptr %29, i64 %26
|
||||
%31 = load i32, ptr %30, align 4
|
||||
%32 = call i32 (ptr, ...) @printf(ptr @1, i32 %31)
|
||||
%31 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 0
|
||||
%32 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 1
|
||||
%33 = icmp slt i64 %29, 0
|
||||
%34 = icmp sge i64 %29, %32
|
||||
%35 = or i1 %34, %33
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %35)
|
||||
%36 = getelementptr inbounds i32, ptr %31, i64 %29
|
||||
%37 = load i32, ptr %36, align 4
|
||||
%38 = call i32 (ptr, ...) @printf(ptr @1, i32 %37)
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_6: ; preds = %_llgo_4
|
||||
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
%34 = getelementptr inbounds %main.generator, ptr %33, i32 0, i32 0
|
||||
store i32 1, ptr %34, align 4
|
||||
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%36 = getelementptr inbounds { ptr }, ptr %35, i32 0, i32 0
|
||||
store ptr %33, ptr %36, align 8
|
||||
%37 = alloca { ptr, ptr }, align 8
|
||||
%38 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 0
|
||||
store ptr @"main.next$bound", ptr %38, align 8
|
||||
%39 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 1
|
||||
store ptr %35, ptr %39, align 8
|
||||
%40 = load { ptr, ptr }, ptr %37, align 8
|
||||
%41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %40)
|
||||
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
|
||||
%39 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
%40 = getelementptr inbounds %main.generator, ptr %39, i32 0, i32 0
|
||||
store i32 1, ptr %40, align 4
|
||||
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%42 = getelementptr inbounds { ptr }, ptr %41, i32 0, i32 0
|
||||
store ptr %39, ptr %42, align 8
|
||||
%43 = alloca { ptr, ptr }, align 8
|
||||
%44 = getelementptr inbounds { ptr, ptr }, ptr %43, i32 0, i32 0
|
||||
store ptr @"main.next$bound", ptr %44, align 8
|
||||
%45 = getelementptr inbounds { ptr, ptr }, ptr %43, i32 0, i32 1
|
||||
store ptr %41, ptr %45, align 8
|
||||
%46 = load { ptr, ptr }, ptr %43, align 8
|
||||
%47 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %46)
|
||||
%48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 1
|
||||
br label %_llgo_7
|
||||
|
||||
_llgo_7: ; preds = %_llgo_8, %_llgo_6
|
||||
%43 = phi i64 [ -1, %_llgo_6 ], [ %44, %_llgo_8 ]
|
||||
%44 = add i64 %43, 1
|
||||
%45 = icmp slt i64 %44, %42
|
||||
br i1 %45, label %_llgo_8, label %_llgo_9
|
||||
%49 = phi i64 [ -1, %_llgo_6 ], [ %50, %_llgo_8 ]
|
||||
%50 = add i64 %49, 1
|
||||
%51 = icmp slt i64 %50, %48
|
||||
br i1 %51, label %_llgo_8, label %_llgo_9
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7
|
||||
%46 = icmp slt i64 %44, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %46)
|
||||
%47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 0
|
||||
%48 = getelementptr inbounds i32, ptr %47, i64 %44
|
||||
%49 = load i32, ptr %48, align 4
|
||||
%50 = call i32 (ptr, ...) @printf(ptr @2, i32 %49)
|
||||
%52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 0
|
||||
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 1
|
||||
%54 = icmp slt i64 %50, 0
|
||||
%55 = icmp sge i64 %50, %53
|
||||
%56 = or i1 %55, %54
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %56)
|
||||
%57 = getelementptr inbounds i32, ptr %52, i64 %50
|
||||
%58 = load i32, ptr %57, align 4
|
||||
%59 = call i32 (ptr, ...) @printf(ptr @2, i32 %58)
|
||||
br label %_llgo_7
|
||||
|
||||
_llgo_9: ; preds = %_llgo_7
|
||||
|
||||
@@ -49,10 +49,12 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%13 = icmp slt i64 %11, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %13)
|
||||
%14 = getelementptr inbounds i64, ptr %2, i64 %11
|
||||
%15 = load i64, ptr %14, align 4
|
||||
%16 = call i32 (ptr, ...) @printf(ptr @0, i64 %15)
|
||||
%14 = icmp sge i64 %11, 5
|
||||
%15 = or i1 %14, %13
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %15)
|
||||
%16 = getelementptr inbounds i64, ptr %2, i64 %11
|
||||
%17 = load i64, ptr %16, align 4
|
||||
%18 = call i32 (ptr, ...) @printf(ptr @0, i64 %17)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
|
||||
@@ -55,19 +55,22 @@ _llgo_0:
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%2 = phi i64 [ 0, %_llgo_0 ], [ %10, %_llgo_2 ]
|
||||
%2 = phi i64 [ 0, %_llgo_0 ], [ %13, %_llgo_2 ]
|
||||
%3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ]
|
||||
%4 = add i64 %3, 1
|
||||
%5 = icmp slt i64 %4, %1
|
||||
br i1 %5, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%6 = icmp slt i64 %4, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %6)
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 %4
|
||||
%9 = load i64, ptr %8, align 4
|
||||
%10 = add i64 %2, %9
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%8 = icmp slt i64 %4, 0
|
||||
%9 = icmp sge i64 %4, %7
|
||||
%10 = or i1 %9, %8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = getelementptr inbounds i64, ptr %6, i64 %4
|
||||
%12 = load i64, ptr %11, align 4
|
||||
%13 = add i64 %2, %12
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
|
||||
@@ -125,34 +125,107 @@ func (b Builder) IndexAddr(x, idx Expr) Expr {
|
||||
if debugInstr {
|
||||
log.Printf("IndexAddr %v, %v\n", x.impl, idx.impl)
|
||||
}
|
||||
idx = b.checkIndex(idx)
|
||||
prog := b.Prog
|
||||
telem := prog.Index(x.Type)
|
||||
pt := prog.Pointer(telem)
|
||||
switch x.raw.Type.Underlying().(type) {
|
||||
switch t := x.raw.Type.Underlying().(type) {
|
||||
case *types.Slice:
|
||||
ptr := b.SliceData(x)
|
||||
max := b.SliceLen(x)
|
||||
idx = b.checkIndex(idx, max)
|
||||
indices := []llvm.Value{idx.impl}
|
||||
return Expr{llvm.CreateInBoundsGEP(b.impl, telem.ll, ptr.impl, indices), pt}
|
||||
case *types.Pointer:
|
||||
ar := t.Elem().Underlying().(*types.Array)
|
||||
max := prog.IntVal(uint64(ar.Len()), prog.Int())
|
||||
idx = b.checkIndex(idx, max)
|
||||
}
|
||||
// case *types.Pointer:
|
||||
indices := []llvm.Value{idx.impl}
|
||||
return Expr{llvm.CreateInBoundsGEP(b.impl, telem.ll, x.impl, indices), pt}
|
||||
}
|
||||
|
||||
// check index >= 0 and size to uint
|
||||
func (b Builder) checkIndex(idx Expr) Expr {
|
||||
prog := b.Prog
|
||||
if needsNegativeCheck(idx) {
|
||||
zero := llvm.ConstInt(idx.ll, 0, false)
|
||||
check := Expr{llvm.CreateICmp(b.impl, llvm.IntSLT, idx.impl, zero), prog.Bool()}
|
||||
b.InlineCall(b.Pkg.rtFunc("AssertIndexRange"), check)
|
||||
func isConstantInt(x Expr) (v int64, ok bool) {
|
||||
if rv := x.impl.IsAConstantInt(); !rv.IsNil() {
|
||||
v = rv.SExtValue()
|
||||
ok = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func isConstantUint(x Expr) (v uint64, ok bool) {
|
||||
if rv := x.impl.IsAConstantInt(); !rv.IsNil() {
|
||||
v = rv.ZExtValue()
|
||||
ok = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func checkRange(idx Expr, max Expr) (checkMin, checkMax bool) {
|
||||
if idx.kind == vkSigned {
|
||||
if v, ok := isConstantInt(idx); ok {
|
||||
if v < 0 {
|
||||
checkMin = true
|
||||
}
|
||||
if m, ok := isConstantInt(max); ok {
|
||||
if v >= m {
|
||||
checkMax = true
|
||||
}
|
||||
} else {
|
||||
checkMax = true
|
||||
}
|
||||
} else {
|
||||
checkMin = true
|
||||
checkMax = true
|
||||
}
|
||||
} else {
|
||||
if v, ok := isConstantUint(idx); ok {
|
||||
if m, ok := isConstantUint(max); ok {
|
||||
if v >= m {
|
||||
checkMax = true
|
||||
}
|
||||
} else {
|
||||
checkMax = true
|
||||
}
|
||||
} else {
|
||||
checkMax = true
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// check index >= 0 && index < max and size to uint
|
||||
func (b Builder) checkIndex(idx Expr, max Expr) Expr {
|
||||
prog := b.Prog
|
||||
// check range
|
||||
checkMin, checkMax := checkRange(idx, max)
|
||||
// fit size
|
||||
var typ Type
|
||||
if idx.kind == vkSigned {
|
||||
typ = prog.Int()
|
||||
} else {
|
||||
typ = prog.Uint()
|
||||
}
|
||||
typ := prog.Uint()
|
||||
if prog.SizeOf(idx.Type) < prog.SizeOf(typ) {
|
||||
idx.Type = typ
|
||||
idx.impl = castUintptr(b, idx.impl, typ)
|
||||
}
|
||||
// check range expr
|
||||
var check Expr
|
||||
if checkMin {
|
||||
zero := llvm.ConstInt(idx.ll, 0, false)
|
||||
check = Expr{llvm.CreateICmp(b.impl, llvm.IntSLT, idx.impl, zero), prog.Bool()}
|
||||
}
|
||||
if checkMax {
|
||||
r := Expr{llvm.CreateICmp(b.impl, llvm.IntSGE, idx.impl, max.impl), prog.Bool()}
|
||||
if check.IsNil() {
|
||||
check = r
|
||||
} else {
|
||||
check = Expr{b.impl.CreateOr(r.impl, check.impl, ""), prog.Bool()}
|
||||
}
|
||||
}
|
||||
if !check.IsNil() {
|
||||
b.InlineCall(b.Pkg.rtFunc("AssertIndexRange"), check)
|
||||
}
|
||||
return idx
|
||||
}
|
||||
|
||||
@@ -170,6 +243,7 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) (Expr, bool)) Expr {
|
||||
prog := b.Prog
|
||||
var telem Type
|
||||
var ptr Expr
|
||||
var max Expr
|
||||
var zero bool
|
||||
switch t := x.raw.Type.Underlying().(type) {
|
||||
case *types.Basic:
|
||||
@@ -178,6 +252,7 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) (Expr, bool)) Expr {
|
||||
}
|
||||
telem = prog.rawType(types.Typ[types.Byte])
|
||||
ptr = b.StringData(x)
|
||||
max = b.StringLen(x)
|
||||
case *types.Array:
|
||||
telem = prog.Index(x.Type)
|
||||
if addr != nil {
|
||||
@@ -190,9 +265,9 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) (Expr, bool)) Expr {
|
||||
*/
|
||||
panic("unreachable")
|
||||
}
|
||||
max = prog.IntVal(uint64(t.Len()), prog.Int())
|
||||
}
|
||||
// TODO check range
|
||||
idx = b.checkIndex(idx)
|
||||
idx = b.checkIndex(idx, max)
|
||||
if zero {
|
||||
return Expr{llvm.ConstNull(telem.ll), telem}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user