authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-04 14:23:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-04 14:23:53-07:00
log1f0fd643025d4508f84a236453168173290a01a0
treee279d50ef8706562f95a1e1bee2d896e7b263053
parentedfbf85ecdf29ee976534403369323def7905c62

stage2: test coverage for inline asm return type not type


2 files changed, 17 insertions(+), 68 deletions(-)

BRANCH_TODO-66
......@@ -55,72 +55,6 @@
5555 natural alignment for fields and do not have any comptime fields. this
5656 will save 16 bytes per struct field in the compilation.
5757
58fn getAnonTypeName(mod: *Module, scope: *Scope, base_token: std.zig.ast.TokenIndex) ![]u8 {
59 // TODO add namespaces, generic function signatrues
60 const tree = scope.tree();
61 const token_tags = tree.tokens.items(.tag);
62 const base_name = switch (token_tags[base_token]) {
63 .keyword_struct => "struct",
64 .keyword_enum => "enum",
65 .keyword_union => "union",
66 .keyword_opaque => "opaque",
67 else => unreachable,
68 };
69 const loc = tree.tokenLocation(0, base_token);
70 return std.fmt.allocPrint(mod.gpa, "{s}:{d}:{d}", .{ base_name, loc.line, loc.column });
71}
72
73
74/// Returns `true` if the Decl type changed.
75/// Returns `true` if this is the first time analyzing the Decl.
76/// Returns `false` otherwise.
77fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {
78 switch (node_tags[decl_node]) {
79 .@"usingnamespace" => {
80 decl.analysis = .in_progress;
81
82 var code: Zir = blk: {
83 var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);
84 defer astgen.deinit();
85
86 var gen_scope: Scope.GenZir = .{
87 .force_comptime = true,
88 .parent = &decl.namespace.base,
89 .astgen = &astgen,
90 };
91 defer gen_scope.instructions.deinit(mod.gpa);
92
93 const ns_type = try AstGen.typeExpr(&gen_scope, &gen_scope.base, type_expr);
94
95 };
96 try decl.namespace.usingnamespace_set.put(mod.gpa, ty.getNamespace().?, is_pub);
97
98 decl.analysis = .complete;
99 decl.generation = mod.generation;
100 return true;
101 },
102 else => unreachable,
103 }
104}
105
106 if (mod.lookupIdentifier(scope, ident_name)) |decl| {
107 const msg = msg: {
108 const msg = try mod.errMsg(
109 scope,
110 name_src,
111 "redeclaration of '{s}'",
112 .{ident_name},
113 );
114 errdefer msg.destroy(gpa);
115 try mod.errNoteNonLazy(decl.srcLoc(), msg, "previously declared here", .{});
116 break :msg msg;
117 };
118 return mod.failWithOwnedErrorMsg(scope, msg);
119 }
120
121 // when implementing this be sure to add test coverage for the asm return type
122 // not resolving into a type (the node_offset_asm_ret_ty field of LazySrcLoc)
123
12458pub fn analyzeNamespace(
12559 mod: *Module,
12660 namespace: *Scope.Namespace,
test/stage2/test.zig+17-2
......@@ -1008,7 +1008,7 @@ pub fn addCases(ctx: *TestContext) !void {
10081008 "Hello, World!\n",
10091009 );
10101010 try case.files.append(.{
1011 .src =
1011 .src =
10121012 \\pub fn print() void {
10131013 \\ asm volatile ("syscall"
10141014 \\ :
......@@ -1067,7 +1067,7 @@ pub fn addCases(ctx: *TestContext) !void {
10671067 },
10681068 );
10691069 try case.files.append(.{
1070 .src =
1070 .src =
10711071 \\// dummy comment to make print be on line 2
10721072 \\fn print() void {
10731073 \\ asm volatile ("syscall"
......@@ -1657,4 +1657,19 @@ pub fn addCases(ctx: *TestContext) !void {
16571657 "",
16581658 );
16591659 }
1660 {
1661 var case = ctx.exe("inline assembly", linux_x64);
1662
1663 case.addError(
1664 \\pub fn main() void {
1665 \\ const number = 1234;
1666 \\ const x = asm volatile ("syscall"
1667 \\ : [o] "{rax}" (-> number)
1668 \\ : [number] "{rax}" (231),
1669 \\ [arg1] "{rdi}" (code)
1670 \\ : "rcx", "r11", "memory"
1671 \\ );
1672 \\}
1673 , &[_][]const u8{":4:27: error: expected type, found comptime_int"});
1674 }
16601675}