We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export fn entry() void { var z = []u32{1234}; var y: []const u32 = z[0..]; var x = @sliceToBytes(y); }
define void @entry() #2 !dbg !41 { Entry: %0 = alloca %"[]u32", align 8 %1 = alloca %"[]u8", align 8 %z = alloca [1 x i32], align 4 %y = alloca %"[]u32", align 8 %x = alloca %"[]u8", align 8 %2 = bitcast [1 x i32]* %z to i8*, !dbg !60 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %2, i8* align 4 bitcast ([1 x i32]* @0 to i8*), i64 4, i1 false), !dbg !60 call void @llvm.dbg.declare(metadata [1 x i32]* %z, metadata !45, metadata !DIExpression()), !dbg !60 br i1 true, label %BoundsCheckOk, label %BoundsCheckFail, !dbg !61 BoundsCheckFail: ; preds = %Entry tail call fastcc void @panic(%"[]u8"* @3, %StackTrace* null), !dbg !61 unreachable, !dbg !61 BoundsCheckOk: ; preds = %Entry %3 = getelementptr inbounds %"[]u32", %"[]u32"* %0, i32 0, i32 0, !dbg !61 %4 = getelementptr inbounds [1 x i32], [1 x i32]* %z, i64 0, i64 0, !dbg !61 ...
The bounds check can always be elided, even in debug mode, when slicing from 0 with inferred len.
The text was updated successfully, but these errors were encountered:
copy elision: @sliceToBytes
2b39363
```zig export fn entry() void { var z = []u32{1234}; var y: []const u32 = z[0..]; var x = @sliceToBytes(y); } ``` don't worry about the bounds check, that's #1839 ```llvm define void @entry() #2 !dbg !41 { Entry: %z = alloca [1 x i32], align 4 %y = alloca %"[]u32", align 8 %x = alloca %"[]u8", align 8 %0 = bitcast [1 x i32]* %z to i8*, !dbg !60 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 4 bitcast ([1 x i32]* @0 to i8*), i64 4, i1 false), !dbg !60 call void @llvm.dbg.declare(metadata [1 x i32]* %z, metadata !45, metadata !DIExpression()), !dbg !60 br i1 true, label %BoundsCheckOk, label %BoundsCheckFail, !dbg !61 BoundsCheckFail: ; preds = %Entry tail call fastcc void @Panic(%"[]u8"* @3, %StackTrace* null), !dbg !61 unreachable, !dbg !61 BoundsCheckOk: ; preds = %Entry %1 = getelementptr inbounds %"[]u32", %"[]u32"* %y, i32 0, i32 0, !dbg !61 %2 = getelementptr inbounds [1 x i32], [1 x i32]* %z, i64 0, i64 0, !dbg !61 store i32* %2, i32** %1, align 8, !dbg !61 %3 = getelementptr inbounds %"[]u32", %"[]u32"* %y, i32 0, i32 1, !dbg !61 store i64 1, i64* %3, align 8, !dbg !61 call void @llvm.dbg.declare(metadata %"[]u32"* %y, metadata !51, metadata !DIExpression()), !dbg !62 %4 = bitcast %"[]u8"* %x to %"[]u32"*, !dbg !63 %5 = bitcast %"[]u32"* %y to i8*, !dbg !64 %6 = bitcast %"[]u32"* %4 to i8*, !dbg !64 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %6, i8* align 8 %5, i64 16, i1 false), !dbg !64 call void @llvm.dbg.declare(metadata %"[]u8"* %x, metadata !58, metadata !DIExpression()), !dbg !65 ret void, !dbg !66 } ```
In the following use case (all factors must apply) no bounds checking is performed:
export fn entry() void { var a = [_]u32{ 1,2,3,4 }; const slice = a[99..]; }
Sorry, something went wrong.
No branches or pull requests
The bounds check can always be elided, even in debug mode, when slicing from 0 with inferred len.
The text was updated successfully, but these errors were encountered: