From aa60d2a688c965dcccf8e2c42afe5c180daba8fc Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Sun, 16 Jun 2019 02:10:06 +0200 Subject: fixes resolving aligment of child type in slice --- src/ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 6c1c84da3b..0936f78df3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16794,7 +16794,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdPromise: case ZigTypeIdVector: { - if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) + if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) return ira->codegen->invalid_instruction; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); -- cgit v1.2.3 From f4b8850002d5f617450a9d08b05519f390bd3f21 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 16 Jun 2019 14:14:57 -0400 Subject: fix type info crash on extern lib name --- src/ir.cpp | 5 +++-- test/stage1/behavior/type_info.zig | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 0936f78df3..5c09e48b2d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -18613,10 +18613,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr true, false, PtrLenUnknown, 0, 0, 0, false); fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); - if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { + if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) { fn_decl_fields[6].data.x_optional = create_const_vals(1); ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name); - init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true); + init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, + buf_len(fn_node->lib_name), true); } else { fn_decl_fields[6].data.x_optional = nullptr; } diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index f05b02e7ab..4ae81aff20 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -1,7 +1,9 @@ -const expect = @import("std").testing.expect; -const mem = @import("std").mem; -const TypeInfo = @import("builtin").TypeInfo; -const TypeId = @import("builtin").TypeId; +const std = @import("std"); +const expect = std.testing.expect; +const mem = std.mem; +const builtin = @import("builtin"); +const TypeInfo = builtin.TypeInfo; +const TypeId = builtin.TypeId; test "type info: tag type, void info" { testBasic(); @@ -317,3 +319,20 @@ test "type info: TypeId -> TypeInfo impl cast" { _ = passTypeInfo(TypeId.Void); _ = comptime passTypeInfo(TypeId.Void); } + +test "type info: extern fns with and without lib names" { + const S = struct { + extern fn bar1() void; + extern "cool" fn bar2() void; + }; + const info = @typeInfo(S); + comptime { + for (info.Struct.decls) |decl| { + if (std.mem.eql(u8, decl.name, "bar1")) { + expect(decl.data.Fn.lib_name == null); + } else { + std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?); + } + } + } +} -- cgit v1.2.3 From 8ed88280a62f2a400d00b5ac20618539693dad36 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 18 Jun 2019 11:18:53 -0400 Subject: Revert "fixes resolving aligment of child type in slice" This reverts commit aa60d2a688c965dcccf8e2c42afe5c180daba8fc. The copyright ownership of this 10 line patch is under dispute. See #2701 for details. So I'll revert it and then fix it myself without looking at this patch. --- src/ir.cpp | 2 +- test/stage1/behavior.zig | 1 - test/stage1/behavior/bugs/2689.zig | 7 ------- 3 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 test/stage1/behavior/bugs/2689.zig (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 5c09e48b2d..21751b9a96 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16794,7 +16794,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdPromise: case ZigTypeIdVector: { - if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) + if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 707d46fd8c..f477bb64ed 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -27,7 +27,6 @@ comptime { _ = @import("behavior/bugs/2114.zig"); _ = @import("behavior/bugs/2346.zig"); _ = @import("behavior/bugs/2578.zig"); - _ = @import("behavior/bugs/2689.zig"); _ = @import("behavior/bugs/394.zig"); _ = @import("behavior/bugs/421.zig"); _ = @import("behavior/bugs/529.zig"); diff --git a/test/stage1/behavior/bugs/2689.zig b/test/stage1/behavior/bugs/2689.zig deleted file mode 100644 index d1c1062ada..0000000000 --- a/test/stage1/behavior/bugs/2689.zig +++ /dev/null @@ -1,7 +0,0 @@ -test "slice with alignment" { - const S = packed struct { - a: u8, - }; - - var a: []align(8) S = undefined; -} -- cgit v1.2.3 From 9050a07540b7387dade8184d3a3daf957e805e4f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 18 Jun 2019 11:31:05 -0400 Subject: when resolving slice types, might need to... ...resolve alignment if custom alignment is provided fixes #2689 --- src/ir.cpp | 4 +++- test/stage1/behavior/slice.zig | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 21751b9a96..b74a99b37d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16794,7 +16794,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdPromise: case ZigTypeIdVector: { - if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) + ResolveStatus needed_status = (align_bytes == 0) ? + ResolveStatusZeroBitsKnown : ResolveStatusAlignmentKnown; + if ((err = type_resolve(ira->codegen, child_type, needed_status))) return ira->codegen->invalid_instruction; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index 5fa6c24026..d4a8353ca7 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -54,3 +54,14 @@ test "comptime slices are disambiguated" { expect(sliceSum([_]u8{ 1, 2 }) == 3); expect(sliceSum([_]u8{ 3, 4 }) == 7); } + +test "slice type with custom alignment" { + const LazilyResolvedType = struct { + anything: i32, + }; + var slice: []align(32) LazilyResolvedType = undefined; + var array: [10]LazilyResolvedType align(32) = undefined; + slice = &array; + slice[1].anything = 42; + expect(array[1].anything == 42); +} -- cgit v1.2.3