From 39700c77ee8eb0c2e162b81155c5066c6a4c81fe Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 5 Apr 2021 17:31:18 +0800 Subject: [PATCH] Added test case for Issue #1451. --- test/val/bug1451.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/val/bug1451.c diff --git a/test/val/bug1451.c b/test/val/bug1451.c new file mode 100644 index 000000000..c00f19903 --- /dev/null +++ b/test/val/bug1451.c @@ -0,0 +1,39 @@ +/* Bug #1451 - local struct field access via the address of the struct */ + +#include + +typedef struct { + int a; + int b; +} S; + +int failures = 0; + +int main(void) +{ + S a = {2, 5}; + S b = {1, 4}; + S m[1] = {{6, 3}}; + S *p = &a; + + (&a)->a += b.a; + p->b += b.b; + m->a += b.a; + + if ((&a)->a != 3) { + ++failures; + printf("Expected 3, got %d\n", (&a)->a); + } + + if (p->b != 9) { + ++failures; + printf("Expected 9, got %d\n", p->b); + } + + if (m->a != 7) { + ++failures; + printf("Expected 7, got %d\n", m->a); + } + + return failures; +}