Skip to content

Commit

Permalink
Parser: do not attempt to cast floats to incomplete-size ints
Browse files Browse the repository at this point in the history
Fixes #660
  • Loading branch information
ehaas authored and Vexu committed Apr 1, 2024
1 parent 0493abd commit 57cec30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5962,6 +5962,10 @@ pub const Result = struct {
if (to.is(.bool)) {
res.val.boolCast(p.comp);
} else if (old_float and new_int) {
if (to.hasIncompleteSize()) {
try p.errStr(.cast_to_incomplete_type, l_paren, try p.typeStr(to));
return error.ParsingFailed;
}
// Explicit cast, no conversion warning
_ = try res.val.floatToInt(to, p.comp);
} else if (new_float and old_int) {
Expand Down
2 changes: 2 additions & 0 deletions test/cases/casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void foo(void) {
(enum E)1;
int *ptr;
ptr = (int *)(void)5;
(enum DoesNotExist)2.0;
}

#define EXPECTED_ERRORS "casts.c:5:5: error: cannot cast to non arithmetic or pointer type 'struct Foo'" \
Expand All @@ -27,4 +28,5 @@ void foo(void) {
"casts.c:11:13: error: pointer cannot be cast to type 'float'" \
"casts.c:16:5: error: cast to incomplete type 'enum E'" \
"casts.c:18:18: error: used type 'void' where arithmetic or pointer type is required" \
"casts.c:19:5: error: cast to incomplete type 'enum DoesNotExist'" \

0 comments on commit 57cec30

Please sign in to comment.