mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Merge pull request #12286 from ziglang/division-safety
Division safety improvements
This commit is contained in:
commit
64dc1b05d6
@ -63,8 +63,7 @@ stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
|
||||
stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Denable-llvm
|
||||
stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
|
||||
stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
|
||||
# https://github.com/ziglang/zig/issues/12144
|
||||
stage3/bin/zig build test-cases -fqemu -fwasmtime
|
||||
stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
|
||||
stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm
|
||||
|
||||
$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
|
||||
|
||||
@ -1784,6 +1784,7 @@ pub fn updateSegfaultHandler(act: ?*const os.Sigaction) error{OperationNotSuppor
|
||||
try os.sigaction(os.SIG.SEGV, act, null);
|
||||
try os.sigaction(os.SIG.ILL, act, null);
|
||||
try os.sigaction(os.SIG.BUS, act, null);
|
||||
try os.sigaction(os.SIG.FPE, act, null);
|
||||
}
|
||||
|
||||
/// Attaches a global SIGSEGV handler which calls @panic("segmentation fault");
|
||||
@ -1845,6 +1846,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
|
||||
os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
|
||||
os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
|
||||
os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
|
||||
os.SIG.FPE => stderr.print("Arithmetic exception at address 0x{x}\n", .{addr}),
|
||||
else => unreachable,
|
||||
} catch os.abort();
|
||||
}
|
||||
|
||||
@ -111,8 +111,9 @@ pub const Inst = struct {
|
||||
div_floor,
|
||||
/// Same as `div_floor` with optimized float mode.
|
||||
div_floor_optimized,
|
||||
/// Integer or float division. Guaranteed no remainder.
|
||||
/// For integers, wrapping is undefined behavior.
|
||||
/// Integer or float division.
|
||||
/// If a remainder would be produced, undefined behavior occurs.
|
||||
/// For integers, overflow is undefined behavior.
|
||||
/// Both operands are guaranteed to be the same type, and the result type
|
||||
/// is the same as both operands.
|
||||
/// Uses the `bin_op` field.
|
||||
|
||||
1020
src/Sema.zig
1020
src/Sema.zig
File diff suppressed because it is too large
Load Diff
16
src/type.zig
16
src/type.zig
@ -5201,10 +5201,20 @@ pub const Type = extern union {
|
||||
};
|
||||
}
|
||||
|
||||
// Works for vectors and vectors of integers.
|
||||
pub fn minInt(ty: Type, arena: Allocator, target: Target) !Value {
|
||||
const scalar = try minIntScalar(ty.scalarType(), arena, target);
|
||||
if (ty.zigTypeTag() == .Vector) {
|
||||
return Value.Tag.repeated.create(arena, scalar);
|
||||
} else {
|
||||
return scalar;
|
||||
}
|
||||
}
|
||||
|
||||
/// Asserts that self.zigTypeTag() == .Int.
|
||||
pub fn minInt(self: Type, arena: Allocator, target: Target) !Value {
|
||||
assert(self.zigTypeTag() == .Int);
|
||||
const info = self.intInfo(target);
|
||||
pub fn minIntScalar(ty: Type, arena: Allocator, target: Target) !Value {
|
||||
assert(ty.zigTypeTag() == .Int);
|
||||
const info = ty.intInfo(target);
|
||||
|
||||
if (info.signedness == .unsigned) {
|
||||
return Value.zero;
|
||||
|
||||
@ -3,14 +3,14 @@ pub const List = struct {
|
||||
allocator: *Allocator,
|
||||
|
||||
pub fn init(allocator: *Allocator) List {
|
||||
return List {
|
||||
return List{
|
||||
.len = 0,
|
||||
.allocator = allocator,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub var global_allocator = Allocator {
|
||||
pub var global_allocator = Allocator{
|
||||
.field = 1234,
|
||||
};
|
||||
|
||||
@ -28,4 +28,4 @@ export fn foo() void {
|
||||
// target=native
|
||||
//
|
||||
// :23:6: error: no field or member function named 'init' in 'tmp.List'
|
||||
// :1:14: note: struct declared here
|
||||
// :1:18: note: struct declared here
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
pub fn main() void {
|
||||
var i: u32 = 16;
|
||||
assert(i >> 1, 8);
|
||||
}
|
||||
fn assert(a: u32, b: u32) void {
|
||||
if (a != b) unreachable;
|
||||
}
|
||||
|
||||
// run
|
||||
// backend=llvm
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
@ -1,10 +0,0 @@
|
||||
pub fn main() void {
|
||||
var i: u32 = 16;
|
||||
assert(i << 1, 32);
|
||||
}
|
||||
fn assert(a: u32, b: u32) void {
|
||||
if (a != b) unreachable;
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
Loading…
x
Reference in New Issue
Block a user