authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-16 14:14:57-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-16 14:14:57-04:00
logf4b8850002d5f617450a9d08b05519f390bd3f21
treebed7909e1ef5f5874615261fc7d97f7a40ff02c5
parentaa60d2a688c965dcccf8e2c42afe5c180daba8fc
signaturelock-open Commit is signed but in an unrecognized format.

fix type info crash on extern lib name


2 files changed, 26 insertions(+), 6 deletions(-)

src/ir.cpp+3-2
......@@ -18613,10 +18613,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
1861318613 true, false, PtrLenUnknown,
1861418614 0, 0, 0, false);
1861518615 fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
18616 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) {
18616 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
1861718617 fn_decl_fields[6].data.x_optional = create_const_vals(1);
1861818618 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
18619 init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true);
18619 init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0,
18620 buf_len(fn_node->lib_name), true);
1862018621 } else {
1862118622 fn_decl_fields[6].data.x_optional = nullptr;
1862218623 }
test/stage1/behavior/type_info.zig+23-4
......@@ -1,7 +1,9 @@
1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;
3const TypeInfo = @import("builtin").TypeInfo;
4const TypeId = @import("builtin").TypeId;
1const std = @import("std");
2const expect = std.testing.expect;
3const mem = std.mem;
4const builtin = @import("builtin");
5const TypeInfo = builtin.TypeInfo;
6const TypeId = builtin.TypeId;
57
68test "type info: tag type, void info" {
79 testBasic();
......@@ -317,3 +319,20 @@ test "type info: TypeId -> TypeInfo impl cast" {
317319 _ = passTypeInfo(TypeId.Void);
318320 _ = comptime passTypeInfo(TypeId.Void);
319321}
322
323test "type info: extern fns with and without lib names" {
324 const S = struct {
325 extern fn bar1() void;
326 extern "cool" fn bar2() void;
327 };
328 const info = @typeInfo(S);
329 comptime {
330 for (info.Struct.decls) |decl| {
331 if (std.mem.eql(u8, decl.name, "bar1")) {
332 expect(decl.data.Fn.lib_name == null);
333 } else {
334 std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?);
335 }
336 }
337 }
338}