mirror of
https://github.com/ziglang/zig.git
synced 2026-01-02 19:43:29 +00:00
parent
d24ebf1d12
commit
a5d25fabda
@ -1748,7 +1748,8 @@ fn transBinaryOperator(
|
||||
const lhs_expr = stmt.getLHS();
|
||||
const lhs_qt = getExprQualType(c, lhs_expr);
|
||||
const lhs_qt_translated = try transQualType(c, scope, lhs_qt, lhs_expr.getBeginLoc());
|
||||
const elem_type = lhs_qt_translated.castTag(.c_pointer).?.data.elem_type;
|
||||
const c_pointer = getContainer(c, lhs_qt_translated).?;
|
||||
const elem_type = c_pointer.castTag(.c_pointer).?.data.elem_type;
|
||||
const sizeof = try Tag.sizeof.create(c.arena, elem_type);
|
||||
|
||||
const bitcast = try Tag.bit_cast.create(c.arena, .{ .lhs = ptrdiff_type, .rhs = infixOpNode });
|
||||
|
||||
@ -3916,4 +3916,36 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\ }) != 0) {}
|
||||
\\}
|
||||
});
|
||||
|
||||
if (builtin.os.tag == .windows) {
|
||||
cases.add("Pointer subtraction with typedef",
|
||||
\\typedef char* S;
|
||||
\\void foo() {
|
||||
\\ S a, b;
|
||||
\\ long long c = a - b;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
\\pub export fn foo() void {
|
||||
\\ var a: S = undefined;
|
||||
\\ var b: S = undefined;
|
||||
\\ var c: c_longlong = @divExact(@bitCast(c_longlong, @ptrToInt(a) -% @ptrToInt(b)), @sizeOf(u8));
|
||||
\\ _ = @TypeOf(c);
|
||||
\\}
|
||||
});
|
||||
} else {
|
||||
cases.add("Pointer subtraction with typedef",
|
||||
\\typedef char* S;
|
||||
\\void foo() {
|
||||
\\ S a, b;
|
||||
\\ long c = a - b;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
\\pub export fn foo() void {
|
||||
\\ var a: S = undefined;
|
||||
\\ var b: S = undefined;
|
||||
\\ var c: c_long = @divExact(@bitCast(c_long, @ptrToInt(a) -% @ptrToInt(b)), @sizeOf(u8));
|
||||
\\ _ = @TypeOf(c);
|
||||
\\}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user