From 5c38b6da040e02fa7297e63c5e73f904cd7cb7c0 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Fri, 6 Dec 2024 18:03:39 -0800 Subject: [PATCH] Parser: handle lval_to_rval cast when computing pointer offsets --- src/aro/Parser.zig | 1 + test/cases/relocations.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index 78a8dfda..fc588ef6 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -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, }; }, diff --git a/test/cases/relocations.c b/test/cases/relocations.c index 9fad3ab4..67aa474b 100644 --- a/test/cases/relocations.c +++ b/test/cases/relocations.c @@ -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" \ @@ -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" \