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

incorrect generation of error defers for fn inside fn #878

andrewrk opened this Issue Mar 31, 2018 · 0 comments


None yet
1 participant

andrewrk commented Mar 31, 2018

Thanks to @tgschultz for the report and test case.

const mem = @import("std").mem;
const ArrayList = @import("std").ArrayList;

fn bail() void

pub fn read(alloc: &mem.Allocator) !ArrayList(u32)
    var sections = ArrayList(u32).init(alloc);
    //compiler only segfaults when the errdefer is present
    errdefer bail();
    //compiler only segaults if this struct is defined inside
    //this fn
    const Chk = struct
        fn fail(list: &ArrayList(u32)) !void
            //compiler only fails if the array list is referenced.
            //doesn't seem to be triggered by primitive types
            var s = list;
            //also only fails if this fn can return an error
            return error.Fail;
    return sections;


test "empty data"
    const DirectAllocator = @import("std").heap.DirectAllocator;
    var alloc = DirectAllocator.init().allocator;
    var list = try read(&alloc);
!dbg attachment points at wrong subprogram for function
!1378 = distinct !DISubprogram(name: "Chk_fail", scope: !1379, file: !766, line: 20, type: !1380, isLocal: true, isDefinition: true, scopeLine: 20, isOptimized: false, unit: !1, variables: !1382)
i16 (%StackTrace*, %"AlignedArrayList(u32,4)"*)* @Chk_fail
  call fastcc void @bail(), !dbg !900
!900 = !DILocation(line: 14, column: 18, scope: !898)
!898 = distinct !DILexicalBlock(scope: !889, file: !766, line: 11, column: 5)
!878 = distinct !DISubprogram(name: "read", scope: !766, file: !766, line: 9, type: !879, isLocal: true, isDefinition: true, scopeLine: 9, isOptimized: false, unit: !1, variables: !886)
LLVM ERROR: Broken module found, compilation aborted!

@andrewrk andrewrk added the bug label Mar 31, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Mar 31, 2018

@andrewrk andrewrk closed this in 0a880d5 Jul 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment