Sema: forbid @breakpoint from being called at comptime

This commit is contained in:
Bogdan Romanyuk
2023-12-11 18:52:19 +03:00
committed by GitHub
parent 5bbacb0c8c
commit f88b523065
4 changed files with 28 additions and 25 deletions

View File

@@ -1292,9 +1292,7 @@ fn analyzeBodyInner(
continue;
},
.breakpoint => {
if (!block.is_comptime) {
_ = try block.addNoOp(.breakpoint);
}
try sema.zirBreakpoint(block, extended);
i += 1;
continue;
},
@@ -5620,6 +5618,13 @@ fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.In
return always_noreturn;
}
fn zirBreakpoint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
if (block.is_comptime)
return sema.fail(block, src, "encountered @breakpoint at comptime", .{});
_ = try block.addNoOp(.breakpoint);
}
fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const tracy = trace(@src());
defer tracy.end();

View File

@@ -1,9 +0,0 @@
export fn entry() void {
comptime @trap();
}
// error
// backend=stage2
// target=native
//
// :2:14: error: encountered @trap at comptime

View File

@@ -1,13 +0,0 @@
export fn entry() void {
comptime {
@panic(
"aoeu",
);
}
}
// error
// backend=stage2
// target=native
//
// :3:9: error: encountered @panic at comptime

View File

@@ -0,0 +1,20 @@
test "comptime @panic call" {
comptime @panic("amogus");
}
test "comptime @trap call" {
comptime @trap();
}
test "comptime @breakpoint call" {
comptime @breakpoint();
}
// error
// backend=stage2
// target=native
// is_test=true
//
// :2:14: error: encountered @panic at comptime
// :6:14: error: encountered @trap at comptime
// :10:14: error: encountered @breakpoint at comptime