Skip to content

Commit

Permalink
Parser: handle lval_to_rval cast when computing pointer offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Dec 7, 2024
1 parent d80080e commit 5c38b6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7134,6 +7134,7 @@ fn computeOffsetExtra(p: *Parser, node: NodeIndex, offset_so_far: *Value) !Value
const cast_data = data[@intFromEnum(node)].cast;
return switch (cast_data.kind) {
.array_to_pointer => p.computeOffsetExtra(cast_data.operand, offset_so_far),
.lval_to_rval => .{},
else => unreachable,
};
},
Expand Down
7 changes: 7 additions & 0 deletions test/cases/relocations.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ void foo(void) {
_Static_assert(&local < &local + 1, "");
_Static_assert(&(int){5} != &(int){5}, "");
}

char *bar(char *p) {
_Static_assert(&p[0] == &p[0], "");
char *p2 = &p[1];
return p2;
}
#define EXPECTED_ERRORS "relocations.c:24:1: error: static assertion failed" \
"relocations.c:29:16: error: static_assert expression is not an integral constant expression" \
"relocations.c:30:16: error: static_assert expression is not an integral constant expression" \
Expand All @@ -67,4 +73,5 @@ void foo(void) {
"relocations.c:50:26: warning: subtraction of pointers to type 'union Empty' of zero size has undefined behavior [-Wpointer-arith]" \
"relocations.c:50:16: error: static_assert expression is not an integral constant expression" \
"relocations.c:60:20: error: static_assert expression is not an integral constant expression" \
"relocations.c:64:20: error: static_assert expression is not an integral constant expression" \

0 comments on commit 5c38b6d

Please sign in to comment.