-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from sno2/casts
fix cast result types and support more casts
- Loading branch information
Showing
9 changed files
with
211 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
void foo(void) { | ||
int a[10]; | ||
int* x = a; | ||
|
||
char b[6]; | ||
char* y = b; | ||
} | ||
|
||
// translate | ||
// | ||
// pub export fn foo() void { | ||
// var a: [10]c_int = undefined; | ||
// _ = &a; | ||
// var x: [*c]c_int = @ptrCast(@alignCast(&a)); | ||
// _ = &x; | ||
// var b: [6]u8 = undefined; | ||
// _ = &b; | ||
// var y: [*c]u8 = @ptrCast(@alignCast(&b)); | ||
// _ = &y; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/cases/translate/casting_pointers_to_ints_and_ints_to_pointers_simple.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
void foo(void) { | ||
int x = 23; | ||
int y = (int*)y; | ||
} | ||
|
||
// translate | ||
// | ||
// pub export fn foo() void { | ||
// var x: c_int = 23; | ||
// _ = &x; | ||
// var y: c_int = @intFromPtr(@as([*c]c_int, @ptrFromInt(y))); | ||
// _ = &y; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
int foo(void) { | ||
int v1; | ||
_Bool b1 = v1; | ||
double v2; | ||
_Bool b2 = v2; | ||
void* v3; | ||
_Bool b3 = v3; | ||
|
||
int v4 = b1; | ||
double v5 = b2; | ||
void* v6 = b3; | ||
} | ||
|
||
// translate | ||
// | ||
// pub export fn foo() c_int { | ||
// var v1: c_int = undefined; | ||
// _ = &v1; | ||
// var b1: bool = v1 != 0; | ||
// _ = &b1; | ||
// var v2: f64 = undefined; | ||
// _ = &v2; | ||
// var b2: bool = v2 != 0; | ||
// _ = &b2; | ||
// var v3: ?*anyopaque = undefined; | ||
// _ = &v3; | ||
// var b3: bool = v3 != null; | ||
// _ = &b3; | ||
// var v4: c_int = @intFromBool(b1); | ||
// _ = &v4; | ||
// var v5: f64 = @floatFromInt(@intFromBool(b2)); | ||
// _ = &v5; | ||
// var v6: ?*anyopaque = @ptrFromInt(@intFromBool(b3)); | ||
// _ = &v6; | ||
// return undefined; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ int* foo(void) { | |
} | ||
|
||
// translate | ||
// expect=fail | ||
// | ||
// pub export fn foo() [*c]c_int { | ||
// return null; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters