mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
ubsan: resolve the last of the TODOs
This commit is contained in:
parent
50b95562fd
commit
a468929519
@ -213,25 +213,34 @@ fn alignmentAssumptionHandler(
|
|||||||
alignment: ValueHandle,
|
alignment: ValueHandle,
|
||||||
maybe_offset: ?ValueHandle,
|
maybe_offset: ?ValueHandle,
|
||||||
) callconv(.c) noreturn {
|
) callconv(.c) noreturn {
|
||||||
_ = pointer;
|
const real_pointer = @intFromPtr(pointer) - @intFromPtr(maybe_offset);
|
||||||
// TODO: add the hint here?
|
const lsb = @ctz(real_pointer);
|
||||||
// const real_pointer = @intFromPtr(pointer) - @intFromPtr(maybe_offset);
|
const actual_alignment = @as(u64, 1) << @intCast(lsb);
|
||||||
// const lsb = @ctz(real_pointer);
|
const mask = @intFromPtr(alignment) - 1;
|
||||||
// const actual_alignment = @as(u64, 1) << @intCast(lsb);
|
const misalignment_offset = real_pointer & mask;
|
||||||
// const mask = @intFromPtr(alignment) - 1;
|
|
||||||
// const misalignment_offset = real_pointer & mask;
|
|
||||||
// _ = actual_alignment;
|
|
||||||
// _ = misalignment_offset;
|
|
||||||
|
|
||||||
if (maybe_offset) |offset| {
|
if (maybe_offset) |offset| {
|
||||||
logMessage(
|
logMessage(
|
||||||
"assumption of {} byte alignment (with offset of {} byte) for pointer of type {s} failed",
|
"assumption of {} byte alignment (with offset of {} byte) for pointer of type {s} failed\n" ++
|
||||||
.{ alignment.getValue(data), @intFromPtr(offset), data.type_descriptor.getName() },
|
"offset address is {} aligned, misalignment offset is {} bytes",
|
||||||
|
.{
|
||||||
|
alignment.getValue(data),
|
||||||
|
@intFromPtr(offset),
|
||||||
|
data.type_descriptor.getName(),
|
||||||
|
actual_alignment,
|
||||||
|
misalignment_offset,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
logMessage(
|
logMessage(
|
||||||
"assumption of {} byte alignment for pointer of type {s} failed",
|
"assumption of {} byte alignment for pointer of type {s} failed\n" ++
|
||||||
.{ alignment.getValue(data), data.type_descriptor.getName() },
|
"address is {} aligned, misalignment offset is {} bytes",
|
||||||
|
.{
|
||||||
|
alignment.getValue(data),
|
||||||
|
data.type_descriptor.getName(),
|
||||||
|
actual_alignment,
|
||||||
|
misalignment_offset,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +318,26 @@ fn pointerOverflow(
|
|||||||
.{base},
|
.{base},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@panic("TODO");
|
const signed_base: isize = @bitCast(base);
|
||||||
|
const signed_result: isize = @bitCast(result);
|
||||||
|
if ((signed_base >= 0) == (signed_result >= 0)) {
|
||||||
|
if (base > result) {
|
||||||
|
logMessage(
|
||||||
|
"addition of unsigned offset to 0x{x} overflowed to 0x{x}",
|
||||||
|
.{ base, result },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logMessage(
|
||||||
|
"subtraction of unsigned offset to 0x{x} overflowed to 0x{x}",
|
||||||
|
.{ base, result },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logMessage(
|
||||||
|
"pointer index expression with base 0x{x} overflowed to 0x{x}",
|
||||||
|
.{ base, result },
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user