Skip to content

Commit 24578d8

Browse files
ehaasVexu
authored andcommitted
Parser: handle lval_to_rval cast when computing pointer offsets
1 parent a88c5ac commit 24578d8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/aro/Parser.zig

+1
Original file line numberDiff line numberDiff line change
@@ -7134,6 +7134,7 @@ fn computeOffsetExtra(p: *Parser, node: NodeIndex, offset_so_far: *Value) !Value
71347134
const cast_data = data[@intFromEnum(node)].cast;
71357135
return switch (cast_data.kind) {
71367136
.array_to_pointer => p.computeOffsetExtra(cast_data.operand, offset_so_far),
7137+
.lval_to_rval => .{},
71377138
else => unreachable,
71387139
};
71397140
},

test/cases/relocations.c

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ void foo(void) {
5959
_Static_assert(&local < &local + 1, "");
6060
_Static_assert(&(int){5} != &(int){5}, "");
6161
}
62+
63+
char *bar(char *p) {
64+
_Static_assert(&p[0] == &p[0], "");
65+
char *p2 = &p[1];
66+
return p2;
67+
}
6268
#define EXPECTED_ERRORS "relocations.c:24:1: error: static assertion failed" \
6369
"relocations.c:29:16: error: static_assert expression is not an integral constant expression" \
6470
"relocations.c:30:16: error: static_assert expression is not an integral constant expression" \
@@ -67,4 +73,5 @@ void foo(void) {
6773
"relocations.c:50:26: warning: subtraction of pointers to type 'union Empty' of zero size has undefined behavior [-Wpointer-arith]" \
6874
"relocations.c:50:16: error: static_assert expression is not an integral constant expression" \
6975
"relocations.c:60:20: error: static_assert expression is not an integral constant expression" \
76+
"relocations.c:64:20: error: static_assert expression is not an integral constant expression" \
7077

0 commit comments

Comments
 (0)