Skip to content

Commit eee752e

Browse files
mluggandrewrk
authored andcommitted
compiler: "illegal behavior", not "undefined behavior", in errors
1 parent ca1fc38 commit eee752e

36 files changed

+6751
-6803
lines changed

src/Air.zig

+15-15
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub const Inst = struct {
3737
/// liveness analysis without any special handling.
3838
/// Uses the `arg` field.
3939
arg,
40-
/// Float or integer addition. For integers, wrapping is undefined behavior.
40+
/// Float or integer addition. For integers, wrapping is illegal behavior.
4141
/// Both operands are guaranteed to be the same type, and the result type
4242
/// is the same as both operands.
4343
/// Uses the `bin_op` field.
@@ -66,7 +66,7 @@ pub const Inst = struct {
6666
/// is the same as both operands.
6767
/// Uses the `bin_op` field.
6868
add_sat,
69-
/// Float or integer subtraction. For integers, wrapping is undefined behavior.
69+
/// Float or integer subtraction. For integers, wrapping is illegal behavior.
7070
/// Both operands are guaranteed to be the same type, and the result type
7171
/// is the same as both operands.
7272
/// Uses the `bin_op` field.
@@ -95,7 +95,7 @@ pub const Inst = struct {
9595
/// is the same as both operands.
9696
/// Uses the `bin_op` field.
9797
sub_sat,
98-
/// Float or integer multiplication. For integers, wrapping is undefined behavior.
98+
/// Float or integer multiplication. For integers, wrapping is illegal behavior.
9999
/// Both operands are guaranteed to be the same type, and the result type
100100
/// is the same as both operands.
101101
/// Uses the `bin_op` field.
@@ -131,23 +131,23 @@ pub const Inst = struct {
131131
div_float,
132132
/// Same as `div_float` with optimized float mode.
133133
div_float_optimized,
134-
/// Truncating integer or float division. For integers, wrapping is undefined behavior.
134+
/// Truncating integer or float division. For integers, wrapping is illegal behavior.
135135
/// Both operands are guaranteed to be the same type, and the result type
136136
/// is the same as both operands.
137137
/// Uses the `bin_op` field.
138138
div_trunc,
139139
/// Same as `div_trunc` with optimized float mode.
140140
div_trunc_optimized,
141-
/// Flooring integer or float division. For integers, wrapping is undefined behavior.
141+
/// Flooring integer or float division. For integers, wrapping is illegal behavior.
142142
/// Both operands are guaranteed to be the same type, and the result type
143143
/// is the same as both operands.
144144
/// Uses the `bin_op` field.
145145
div_floor,
146146
/// Same as `div_floor` with optimized float mode.
147147
div_floor_optimized,
148148
/// Integer or float division.
149-
/// If a remainder would be produced, undefined behavior occurs.
150-
/// For integers, overflow is undefined behavior.
149+
/// If a remainder would be produced, illegal behavior occurs.
150+
/// For integers, overflow is illegal behavior.
151151
/// Both operands are guaranteed to be the same type, and the result type
152152
/// is the same as both operands.
153153
/// Uses the `bin_op` field.
@@ -170,14 +170,14 @@ pub const Inst = struct {
170170
mod_optimized,
171171
/// Add an offset to a pointer, returning a new pointer.
172172
/// The offset is in element type units, not bytes.
173-
/// Wrapping is undefined behavior.
173+
/// Wrapping is illegal behavior.
174174
/// The lhs is the pointer, rhs is the offset. Result type is the same as lhs.
175175
/// The pointer may be a slice.
176176
/// Uses the `ty_pl` field. Payload is `Bin`.
177177
ptr_add,
178178
/// Subtract an offset from a pointer, returning a new pointer.
179179
/// The offset is in element type units, not bytes.
180-
/// Wrapping is undefined behavior.
180+
/// Wrapping is illegal behavior.
181181
/// The lhs is the pointer, rhs is the offset. Result type is the same as lhs.
182182
/// The pointer may be a slice.
183183
/// Uses the `ty_pl` field. Payload is `Bin`.
@@ -577,10 +577,10 @@ pub const Inst = struct {
577577
/// sign but an equal or smaller number of bits.
578578
/// Uses the `ty_op` field.
579579
trunc,
580-
/// ?T => T. If the value is null, undefined behavior.
580+
/// ?T => T. If the value is null, illegal behavior.
581581
/// Uses the `ty_op` field.
582582
optional_payload,
583-
/// *?T => *T. If the value is null, undefined behavior.
583+
/// *?T => *T. If the value is null, illegal behavior.
584584
/// Uses the `ty_op` field.
585585
optional_payload_ptr,
586586
/// *?T => *T. Sets the value to non-null with an undefined payload value.
@@ -589,16 +589,16 @@ pub const Inst = struct {
589589
/// Given a payload value, wraps it in an optional type.
590590
/// Uses the `ty_op` field.
591591
wrap_optional,
592-
/// E!T -> T. If the value is an error, undefined behavior.
592+
/// E!T -> T. If the value is an error, illegal behavior.
593593
/// Uses the `ty_op` field.
594594
unwrap_errunion_payload,
595-
/// E!T -> E. If the value is not an error, undefined behavior.
595+
/// E!T -> E. If the value is not an error, illegal behavior.
596596
/// Uses the `ty_op` field.
597597
unwrap_errunion_err,
598-
/// *(E!T) -> *T. If the value is an error, undefined behavior.
598+
/// *(E!T) -> *T. If the value is an error, illegal behavior.
599599
/// Uses the `ty_op` field.
600600
unwrap_errunion_payload_ptr,
601-
/// *(E!T) -> E. If the value is not an error, undefined behavior.
601+
/// *(E!T) -> E. If the value is not an error, illegal behavior.
602602
/// Uses the `ty_op` field.
603603
unwrap_errunion_err_ptr,
604604
/// *(E!T) => *T. Sets the value to non-error with an undefined payload value.

src/Sema.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -2327,11 +2327,11 @@ fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: ?
23272327
}
23282328

23292329
pub fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
2330-
return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{});
2330+
return sema.fail(block, src, "use of undefined value here causes illegal behavior", .{});
23312331
}
23322332

23332333
pub fn failWithDivideByZero(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
2334-
return sema.fail(block, src, "division by zero here causes undefined behavior", .{});
2334+
return sema.fail(block, src, "division by zero here causes illegal behavior", .{});
23352335
}
23362336

23372337
fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
@@ -15496,7 +15496,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1549615496
}
1549715497

1549815498
// Depending on whether safety is enabled, we will have a slightly different strategy
15499-
// here. The `div_exact` AIR instruction causes undefined behavior if a remainder
15499+
// here. The `div_exact` AIR instruction causes illegal behavior if a remainder
1550015500
// is produced, so in the safety check case, it cannot be used. Instead we do a
1550115501
// div_trunc and check for remainder.
1550215502

@@ -25266,7 +25266,7 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte
2526625266
};
2526725267
if (ptr.byte_offset < byte_subtract) {
2526825268
return sema.failWithOwnedErrorMsg(block, msg: {
25269-
const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{});
25269+
const msg = try sema.errMsg(src, "pointer computation here causes illegal behavior", .{});
2527025270
errdefer msg.destroy(sema.gpa);
2527125271
try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
2527225272
break :msg msg;

test/cases/compile_errors/add_assign_on_undefined_value.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ comptime {
55

66
// error
77
//
8-
// :3:5: error: use of undefined value here causes undefined behavior
8+
// :3:5: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/and_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ comptime {
55
}
66

77
// error
8-
// backend=stage2
9-
// target=native
108
//
11-
// :4:9: error: use of undefined value here causes undefined behavior
9+
// :4:9: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/as_many_ptr_undefined.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ export fn entry1() void {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :2:41: error: use of undefined value here causes undefined behavior
8+
// :2:41: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/branch_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ export fn entry() usize {
55
}
66

77
// error
8-
// backend=stage2
9-
// target=native
108
//
11-
// :1:15: error: use of undefined value here causes undefined behavior
9+
// :1:15: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/catch_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ comptime {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:11: error: use of undefined value here causes undefined behavior
8+
// :3:11: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/comparing_against_undefined_produces_undefined_value.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export fn bar(x: u32) void {
88

99
// error
1010
//
11-
// :2:11: error: use of undefined value here causes undefined behavior
12-
// :6:11: error: use of undefined value here causes undefined behavior
11+
// :2:11: error: use of undefined value here causes illegal behavior
12+
// :6:11: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/comparison_operators_with_undefined_value.zig

+6-8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ comptime {
3636
}
3737

3838
// error
39-
// backend=stage2
40-
// target=native
4139
//
42-
// :5:11: error: use of undefined value here causes undefined behavior
43-
// :11:11: error: use of undefined value here causes undefined behavior
44-
// :17:11: error: use of undefined value here causes undefined behavior
45-
// :23:11: error: use of undefined value here causes undefined behavior
46-
// :29:11: error: use of undefined value here causes undefined behavior
47-
// :35:11: error: use of undefined value here causes undefined behavior
40+
// :5:11: error: use of undefined value here causes illegal behavior
41+
// :11:11: error: use of undefined value here causes illegal behavior
42+
// :17:11: error: use of undefined value here causes illegal behavior
43+
// :23:11: error: use of undefined value here causes illegal behavior
44+
// :29:11: error: use of undefined value here causes illegal behavior
45+
// :35:11: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/compile-time_division_by_zero.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ comptime {
66
}
77

88
// error
9-
// backend=stage2
10-
// target=native
119
//
12-
// :4:19: error: division by zero here causes undefined behavior
10+
// :4:19: error: division by zero here causes illegal behavior

test/cases/compile_errors/compile-time_remainder_division_by_zero.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ comptime {
66
}
77

88
// error
9-
// backend=stage2
10-
// target=native
119
//
12-
// :4:19: error: division by zero here causes undefined behavior
10+
// :4:19: error: division by zero here causes illegal behavior

test/cases/compile_errors/compile_time_division_by_zero.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export fn entry() usize {
88
}
99

1010
// error
11-
// backend=stage2
12-
// target=native
1311
//
14-
// :3:16: error: division by zero here causes undefined behavior
12+
// :3:16: error: division by zero here causes illegal behavior
1513
// :1:14: note: called from here

test/cases/compile_errors/compile_time_undef_ptr_cast.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ comptime {
66
}
77

88
// error
9-
// backend=stage2
10-
// target=native
119
//
12-
// :3:32: error: use of undefined value here causes undefined behavior
10+
// :3:32: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/div_assign_on_undefined_value.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ comptime {
55

66
// error
77
//
8-
// :3:5: error: use of undefined value here causes undefined behavior
8+
// :3:5: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/division_by_zero.zig

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export fn entry4() usize {
1717
} // no error on purpose
1818

1919
// error
20-
// backend=stage2
21-
// target=native
2220
//
23-
// :1:23: error: division by zero here causes undefined behavior
24-
// :2:27: error: division by zero here causes undefined behavior
25-
// :3:29: error: division by zero here causes undefined behavior
21+
// :1:23: error: division by zero here causes illegal behavior
22+
// :2:27: error: division by zero here causes illegal behavior
23+
// :3:29: error: division by zero here causes illegal behavior

test/cases/compile_errors/indexing_a_undefined_slice_at_comptime.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ comptime {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:10: error: use of undefined value here causes undefined behavior
8+
// :3:10: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ export fn foo() void {
77
}
88

99
// error
10-
// backend=stage2
11-
// target=native
1210
//
13-
// :4:28: error: use of undefined value here causes undefined behavior
11+
// :4:28: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/mod_assign_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ comptime {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:5: error: use of undefined value here causes undefined behavior
8+
// :3:5: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/mod_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ comptime {
55
}
66

77
// error
8-
// backend=stage2
9-
// target=native
108
//
11-
// :3:9: error: use of undefined value here causes undefined behavior
9+
// :3:9: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/mult_assign_on_undefined_value.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ comptime {
55

66
// error
77
//
8-
// :3:5: error: use of undefined value here causes undefined behavior
8+
// :3:5: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/negate_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ comptime {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:10: error: use of undefined value here causes undefined behavior
8+
// :3:10: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/or_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ comptime {
55
}
66

77
// error
8-
// backend=stage2
9-
// target=native
108
//
11-
// :4:9: error: use of undefined value here causes undefined behavior
9+
// :4:9: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/orelse_on_undefined_value.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ comptime {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:11: error: use of undefined value here causes undefined behavior
8+
// :3:11: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/pointer_exceeds_containing_value.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export fn entry2() void {
1313

1414
// error
1515
//
16-
// :4:13: error: pointer computation here causes undefined behavior
16+
// :4:13: error: pointer computation here causes illegal behavior
1717
// :4:13: note: resulting pointer exceeds bounds of containing value which may trigger overflow
18-
// :10:55: error: pointer computation here causes undefined behavior
18+
// :10:55: error: pointer computation here causes illegal behavior
1919
// :10:55: note: resulting pointer exceeds bounds of containing value which may trigger overflow

test/cases/compile_errors/refer_to_the_type_of_a_generic_function.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ export fn entry() void {
55
}
66

77
// error
8-
// backend=stage2
9-
// target=native
108
//
11-
// :4:6: error: use of undefined value here causes undefined behavior
9+
// :4:6: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ export fn entry() void {
1111
}
1212

1313
// error
14-
// backend=stage2
15-
// target=native
1614
//
17-
// :1:20: error: use of undefined value here causes undefined behavior
15+
// :1:20: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/reify_type_union_payload_is_undefined.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ comptime {
66
}
77

88
// error
9-
// backend=stage2
10-
// target=native
119
//
12-
// :1:20: error: use of undefined value here causes undefined behavior
10+
// :1:20: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/reify_type_with_undefined.zig

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ comptime {
2525
}
2626

2727
// error
28-
// backend=stage2
29-
// target=native
3028
//
31-
// :2:16: error: use of undefined value here causes undefined behavior
32-
// :5:16: error: use of undefined value here causes undefined behavior
33-
// :17:16: error: use of undefined value here causes undefined behavior
29+
// :2:16: error: use of undefined value here causes illegal behavior
30+
// :5:16: error: use of undefined value here causes illegal behavior
31+
// :17:16: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/slice_end_index_undefined.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ export fn a() void {
44
}
55

66
// error
7-
// backend=stage2
8-
// target=native
97
//
10-
// :3:18: error: use of undefined value here causes undefined behavior
8+
// :3:18: error: use of undefined value here causes illegal behavior

test/cases/compile_errors/sub_assign_on_undefined_value.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ comptime {
55

66
// error
77
//
8-
// :3:5: error: use of undefined value here causes undefined behavior
8+
// :3:5: error: use of undefined value here causes illegal behavior

0 commit comments

Comments
 (0)