aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Schmidt <3405586+schmee@users.noreply.github.com>2023-02-10 14:46:29 +0100
committerGitHub <noreply@github.com>2023-02-10 15:46:29 +0200
commita5d25fabdaf7e68f375874b9bda402acaeb9545d (patch)
treeeaa62bf7c9919efbd5b8ba8d3bd467ad2462df62 /test
parentd24ebf1d12cf66665b52136a2807f97ff021d78d (diff)
downloadzig-a5d25fabdaf7e68f375874b9bda402acaeb9545d.tar.gz
zig-a5d25fabdaf7e68f375874b9bda402acaeb9545d.zip
translate_c: fix typedeffed pointer subtraction
Closes #14560.
Diffstat (limited to 'test')
-rw-r--r--test/translate_c.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/translate_c.zig b/test/translate_c.zig
index d2db895a5a..92dc3038c0 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -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);
+ \\}
+ });
+ }
}