Skip to content
New issue

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

wrong line number in stack trace #12818

Closed
andrewrk opened this issue Sep 11, 2022 · 2 comments
Closed

wrong line number in stack trace #12818

andrewrk opened this issue Sep 11, 2022 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

Zig Version: 0.10.0-dev.3981+60678f5ba

Steps to reproduce:

const std = @import("std");

test {
    var a: []const u8 = "My funny string";
    var b: [128]u8 = undefined;
    const key = [32]u8{ 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB, 0x13, 0x37, 0x99, 0x99, 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB, 0x13, 0x37, 0x99, 0x99 };
    const nonce = [12]u8{ 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB };
    std.crypto.stream.chacha.ChaCha8IETF.xor(b[0..], a[0..], 0, key, nonce);
}
[nix-shell:~/Downloads/zig/build]$ stage3/bin/zig test test.zig
Test [1/1] test_0... thread 469589 panic: reached unreachable code
/home/andy/Downloads/zig/lib/std/debug.zig:281:14: 0x20ffa6 in assert (test)
    if (!ok) unreachable; // assertion failure
             ^
/home/andy/Downloads/zig/lib/std/crypto/chacha20.zig:394:19: 0x20f52a in xor (test)
        pub fn xor(out: []u8, in: []const u8, counter: u32, key: [key_length]u8, nonce: [nonce_length]u8) void {
                  ^
./test.zig:8:45: 0x20f4a4 in test_0 (test)
    std.crypto.stream.chacha.ChaCha8IETF.xor(b[0..], a[0..], 0, key, nonce);
                                            ^
/home/andy/Downloads/zig/lib/test_runner.zig:79:28: 0x213165 in main (test)
        } else test_fn.func();
                           ^
/home/andy/Downloads/zig/lib/std/start.zig:568:22: 0x20ff4d in posixCallMainAndExit (test)
            root.main();
                     ^
/home/andy/Downloads/zig/lib/std/start.zig:340:5: 0x20f952 in _start (test)
    @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
    ^
error: the following test command crashed:
zig-cache/o/4dc2fc2140133627808e3b17a79d727f/test /home/andy/Downloads/zig/build/stage3/bin/zig

The second frame points at xor but it should point at the next line, at

            assert(in.len == out.len);
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Sep 11, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Sep 11, 2022
@Vexu
Copy link
Member

Vexu commented Sep 12, 2022

Duplicate/related #12725, stack trace points to correct line with this patch:

diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig
index 2a43f4b94..2d9c67502 100644
--- a/lib/std/crypto/chacha20.zig
+++ b/lib/std/crypto/chacha20.zig
@@ -381,8 +381,7 @@ fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [
     };
 }
 
-fn ChaChaIETF(comptime rounds_nb: usize) type {
-    return struct {
+fn ChaChaIETF(comptime rounds_nb: usize) type { return struct {
         /// Nonce length in bytes.
         pub const nonce_length = 12;
         /// Key length in bytes.
                                 

@andrewrk
Copy link
Member Author

Thank you - I see that you have already a reduction and have narrowed down the problem to AstGen 👍

Vexu added a commit to Vexu/zig that referenced this issue Sep 29, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
Vexu added a commit to Vexu/zig that referenced this issue Sep 29, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
Vexu added a commit to Vexu/zig that referenced this issue Sep 29, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
Vexu added a commit to Vexu/zig that referenced this issue Sep 29, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
wooster0 pushed a commit to wooster0/zig that referenced this issue Oct 4, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
Vexu added a commit to Vexu/zig that referenced this issue Oct 10, 2022
Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes ziglang#12725
Closes ziglang#12818
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants