--- /dev/null
+struct Foo {
+ int *p;
+ int *q;
+};
+
+void __attribute__((noinline))
+bar (int **x)
+{
+ struct Foo *f = (struct Foo *)x;
+ *(f->q) = 0;
+}
+
+int foo(void)
+{
+ struct Foo f;
+ int i = 1, j = 2;
+ f.p = &i;
+ f.q = &j;
+ bar(&f.p);
+ return j;
+}
+
+extern void abort (void);
+int main()
+{
+ if (foo () != 0)
+ abort ();
+}
--- /dev/null
+struct Foo {
+ int *p;
+ int *q;
+};
+
+void __attribute__((noinline))
+bar (int **x)
+{
+ struct Foo *f = (struct Foo *)(x - 1);
+ *(f->p) = 0;
+}
+
+int foo(void)
+{
+ struct Foo f;
+ int i = 1, j = 2;
+ f.p = &i;
+ f.q = &j;
+ bar(&f.q);
+ return i;
+}
+
+extern void abort (void);
+int main()
+{
+ if (foo () != 0)
+ abort ();
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-tree-sra" } */
+
+extern void abort (void);
+struct Bar {
+ struct Foo {
+ int *p;
+ } x;
+ int *q;
+};
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo(struct Foo f)
+{
+ *f.p = 0;
+}
+int main()
+{
+ int a, b;
+ a = 0;
+ b = 1;
+ struct Bar f;
+ f.x = bar (&b);
+ f.q = &a;
+ foo(f.x);
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+typedef unsigned long uintptr_t;
+
+void __attribute__((noinline))
+foo(uintptr_t l)
+{
+ int *p = (int *)l;
+ *p = 1;
+}
+
+extern void abort (void);
+int main()
+{
+ int b = 0;
+ uintptr_t l = (uintptr_t)&b;
+ foo(l);
+ if (b != 1)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-tree-sra" } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+};
+struct Bar {
+ struct Foo *x;
+ int *q;
+};
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo(struct Foo f)
+{
+ *f.p = 0;
+}
+int main()
+{
+ int a, b;
+ a = 0;
+ b = 1;
+ struct Bar f;
+ struct Foo g = bar (&b);
+ f.x = &g;
+ f.q = &a;
+ foo(*f.x);
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+};
+struct Bar {
+ struct Foo *x;
+ int *q;
+};
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo(struct Foo f)
+{
+ *f.p = 0;
+}
+int main()
+{
+ int a, b;
+ a = 0;
+ b = 1;
+ struct Bar f;
+ struct Foo g = bar (&b);
+ f.x = &g;
+ f.q = &a;
+ foo(*f.x);
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+ int *q;
+};
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo(struct Foo f)
+{
+ *f.p = 0;
+}
+int main()
+{
+ int a, b;
+ a = 0;
+ b = 1;
+ struct Foo f;
+ f = bar (&b);
+ f.q = &a;
+ foo(f);
+ if (b != 0)
+ abort ();
+ return 0;
+}
+
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-tree-sra" } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+ int *q;
+};
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo(struct Foo f)
+{
+ *f.p = 0;
+}
+int main()
+{
+ int a, b;
+ a = 0;
+ b = 1;
+ struct Foo f;
+ f = bar (&b);
+ f.q = &a;
+ foo(f);
+ if (b != 0)
+ abort ();
+ return 0;
+}
+
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-tree-sra" } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+} x;
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo()
+{
+ *x.p = 0;
+}
+int main()
+{
+ int b;
+ b = 1;
+ struct Foo g = bar (&b);
+ x = g;
+ foo();
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+} x;
+struct Foo __attribute__((noinline))
+bar(int *p)
+{
+ struct Foo f;
+ f.p = p;
+ return f;
+}
+void __attribute__((noinline))
+foo()
+{
+ *x.p = 0;
+}
+int main()
+{
+ int b;
+ b = 1;
+ struct Foo g = bar (&b);
+ x = g;
+ foo();
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-tree-sra" } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+} x;
+void __attribute__((noinline))
+foo()
+{
+ *x.p = 0;
+}
+int main()
+{
+ int b;
+ struct Foo g;
+ b = 1;
+ g.p = &b;
+ x = g;
+ foo();
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+extern void abort (void);
+struct Foo {
+ int *p;
+} x;
+void __attribute__((noinline))
+foo()
+{
+ *x.p = 0;
+}
+int main()
+{
+ int b;
+ struct Foo g;
+ b = 1;
+ g.p = &b;
+ x = g;
+ foo();
+ if (b != 0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+
+struct barstruct { char const* some_string; };
+
+void changethepointer(struct barstruct***);
+
+void baz()
+{
+ struct barstruct bar1;
+ struct barstruct* barptr = &bar1;
+ struct barstruct** barptr2 = &barptr;
+ changethepointer(&barptr2);
+ barptr->some_string = "Everything OK";
+}
+
+/* { dg-final { scan-assembler "Everything OK" } } */