mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
stage2: test coverage for inline asm return type not type
This commit is contained in:
parent
edfbf85ecd
commit
1f0fd64302
66
BRANCH_TODO
66
BRANCH_TODO
@ -55,72 +55,6 @@
|
||||
natural alignment for fields and do not have any comptime fields. this
|
||||
will save 16 bytes per struct field in the compilation.
|
||||
|
||||
fn getAnonTypeName(mod: *Module, scope: *Scope, base_token: std.zig.ast.TokenIndex) ![]u8 {
|
||||
// TODO add namespaces, generic function signatrues
|
||||
const tree = scope.tree();
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
const base_name = switch (token_tags[base_token]) {
|
||||
.keyword_struct => "struct",
|
||||
.keyword_enum => "enum",
|
||||
.keyword_union => "union",
|
||||
.keyword_opaque => "opaque",
|
||||
else => unreachable,
|
||||
};
|
||||
const loc = tree.tokenLocation(0, base_token);
|
||||
return std.fmt.allocPrint(mod.gpa, "{s}:{d}:{d}", .{ base_name, loc.line, loc.column });
|
||||
}
|
||||
|
||||
|
||||
/// Returns `true` if the Decl type changed.
|
||||
/// Returns `true` if this is the first time analyzing the Decl.
|
||||
/// Returns `false` otherwise.
|
||||
fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {
|
||||
switch (node_tags[decl_node]) {
|
||||
.@"usingnamespace" => {
|
||||
decl.analysis = .in_progress;
|
||||
|
||||
var code: Zir = blk: {
|
||||
var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);
|
||||
defer astgen.deinit();
|
||||
|
||||
var gen_scope: Scope.GenZir = .{
|
||||
.force_comptime = true,
|
||||
.parent = &decl.namespace.base,
|
||||
.astgen = &astgen,
|
||||
};
|
||||
defer gen_scope.instructions.deinit(mod.gpa);
|
||||
|
||||
const ns_type = try AstGen.typeExpr(&gen_scope, &gen_scope.base, type_expr);
|
||||
|
||||
};
|
||||
try decl.namespace.usingnamespace_set.put(mod.gpa, ty.getNamespace().?, is_pub);
|
||||
|
||||
decl.analysis = .complete;
|
||||
decl.generation = mod.generation;
|
||||
return true;
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
if (mod.lookupIdentifier(scope, ident_name)) |decl| {
|
||||
const msg = msg: {
|
||||
const msg = try mod.errMsg(
|
||||
scope,
|
||||
name_src,
|
||||
"redeclaration of '{s}'",
|
||||
.{ident_name},
|
||||
);
|
||||
errdefer msg.destroy(gpa);
|
||||
try mod.errNoteNonLazy(decl.srcLoc(), msg, "previously declared here", .{});
|
||||
break :msg msg;
|
||||
};
|
||||
return mod.failWithOwnedErrorMsg(scope, msg);
|
||||
}
|
||||
|
||||
// when implementing this be sure to add test coverage for the asm return type
|
||||
// not resolving into a type (the node_offset_asm_ret_ty field of LazySrcLoc)
|
||||
|
||||
pub fn analyzeNamespace(
|
||||
mod: *Module,
|
||||
namespace: *Scope.Namespace,
|
||||
|
||||
@ -1008,7 +1008,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
"Hello, World!\n",
|
||||
);
|
||||
try case.files.append(.{
|
||||
.src =
|
||||
.src =
|
||||
\\pub fn print() void {
|
||||
\\ asm volatile ("syscall"
|
||||
\\ :
|
||||
@ -1067,7 +1067,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
},
|
||||
);
|
||||
try case.files.append(.{
|
||||
.src =
|
||||
.src =
|
||||
\\// dummy comment to make print be on line 2
|
||||
\\fn print() void {
|
||||
\\ asm volatile ("syscall"
|
||||
@ -1657,4 +1657,19 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
"",
|
||||
);
|
||||
}
|
||||
{
|
||||
var case = ctx.exe("inline assembly", linux_x64);
|
||||
|
||||
case.addError(
|
||||
\\pub fn main() void {
|
||||
\\ const number = 1234;
|
||||
\\ const x = asm volatile ("syscall"
|
||||
\\ : [o] "{rax}" (-> number)
|
||||
\\ : [number] "{rax}" (231),
|
||||
\\ [arg1] "{rdi}" (code)
|
||||
\\ : "rcx", "r11", "memory"
|
||||
\\ );
|
||||
\\}
|
||||
, &[_][]const u8{":4:27: error: expected type, found comptime_int"});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user