summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/c-c++-common')
-rw-r--r--gcc/testsuite/c-c++-common/builtin-offsetof.c29
-rw-r--r--gcc/testsuite/c-c++-common/dfp/pr35620.c2
-rw-r--r--gcc/testsuite/c-c++-common/pr41935.c70
-rw-r--r--gcc/testsuite/c-c++-common/restrict-1.c20
-rw-r--r--gcc/testsuite/c-c++-common/restrict-2.c14
-rw-r--r--gcc/testsuite/c-c++-common/restrict-4.c19
6 files changed, 153 insertions, 1 deletions
diff --git a/gcc/testsuite/c-c++-common/builtin-offsetof.c b/gcc/testsuite/c-c++-common/builtin-offsetof.c
new file mode 100644
index 00000000000..6d97775467d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/builtin-offsetof.c
@@ -0,0 +1,29 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/38699
+// { dg-options "-Warray-bounds" }
+// { dg-do compile }
+
+struct A
+{
+ const char *p;
+};
+
+struct B
+{
+ char p[10];
+ struct A a;
+};
+
+void
+f0 ()
+{
+ __builtin_offsetof(struct A, p); // OK
+ __builtin_offsetof(struct A, p[0]); // { dg-error "non constant address" }
+ __builtin_offsetof(struct B, p[0]); // OK
+ __builtin_offsetof(struct B, p[9]); // OK
+ __builtin_offsetof(struct B, p[10]); // OK
+ __builtin_offsetof(struct B, p[11]); // { dg-warning "greater than size" }
+ __builtin_offsetof(struct B, a.p); // OK
+ __builtin_offsetof(struct B, p[0]); // OK
+ __builtin_offsetof(struct B, a.p[0]); // { dg-error "non constant address" }
+}
diff --git a/gcc/testsuite/c-c++-common/dfp/pr35620.c b/gcc/testsuite/c-c++-common/dfp/pr35620.c
index 37a9c4044ed..2d56ab76b84 100644
--- a/gcc/testsuite/c-c++-common/dfp/pr35620.c
+++ b/gcc/testsuite/c-c++-common/dfp/pr35620.c
@@ -9,7 +9,7 @@ extern void foo (_Decimal32);
_Decimal32 *p;
extern int i;
-union { _Decimal32 a; int b; } u;
+union U { _Decimal32 a; int b; } u;
void
blatz (void)
diff --git a/gcc/testsuite/c-c++-common/pr41935.c b/gcc/testsuite/c-c++-common/pr41935.c
new file mode 100644
index 00000000000..3279e75593d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr41935.c
@@ -0,0 +1,70 @@
+/* { dg-options "-Warray-bounds" } */
+/* { dg-do compile } */
+
+struct A
+{
+ int i;
+ char p[1];
+};
+
+struct B
+{
+ struct A a;
+ int i;
+};
+
+struct C
+{
+ int i;
+ struct A a;
+};
+
+union D
+{
+ char p[1];
+ struct A a;
+ struct B b;
+ struct C c;
+};
+
+struct E
+{
+ int i;
+ union D d;
+};
+
+struct F
+{
+ union D d;
+ int i;
+};
+
+union G
+{
+ int i;
+ union D d;
+};
+
+void
+f0 ()
+{
+ __builtin_offsetof (struct A, p[4]); /* OK */
+ __builtin_offsetof (struct B, a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (struct C, a.p[4]); /* OK */
+ __builtin_offsetof (union D, p[4]); /* OK */
+ __builtin_offsetof (union D, a.p[4]); /* OK */
+ __builtin_offsetof (union D, b.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (union D, c.a.p[4]); /* OK */
+ __builtin_offsetof (struct E, d.p[4]); /* OK */
+ __builtin_offsetof (struct E, d.a.p[4]); /* OK */
+ __builtin_offsetof (struct E, d.b.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (struct E, d.c.a.p[4]); /* OK */
+ __builtin_offsetof (struct F, d.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (struct F, d.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (struct F, d.b.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (struct F, d.c.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (union G, d.p[4]); /* OK */
+ __builtin_offsetof (union G, d.a.p[4]); /* OK */
+ __builtin_offsetof (union G, d.b.a.p[4]); /* { dg-warning "greater than size" } */
+ __builtin_offsetof (union G, d.c.a.p[4]); /* OK */
+}
diff --git a/gcc/testsuite/c-c++-common/restrict-1.c b/gcc/testsuite/c-c++-common/restrict-1.c
new file mode 100644
index 00000000000..08fc10f5609
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/restrict-1.c
@@ -0,0 +1,20 @@
+/* { dg-do link } */
+/* { dg-options "-O -fno-strict-aliasing -fdump-tree-optimized" } */
+
+extern void link_error (void);
+
+void bar0 (int * __restrict__ arr1, int * __restrict__ arr2)
+{
+ arr1[0] = 1;
+ arr2[0] = 1;
+ if (arr1[0] != 1)
+ link_error ();
+}
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/restrict-2.c b/gcc/testsuite/c-c++-common/restrict-2.c
new file mode 100644
index 00000000000..ec824653d5f
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/restrict-2.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-strict-aliasing -fdump-tree-lim-details" } */
+
+void foo (float * __restrict__ a, float * __restrict__ b, int n, int j)
+{
+ int i;
+ for(i = 0; i < n; ++i)
+ a[i] = (b[j+50] + b[j-50]) * 0.5f;
+}
+
+/* We should move the RHS of the store out of the loop. */
+
+/* { dg-final { scan-tree-dump-times "Moving statement" 11 "lim1" } } */
+/* { dg-final { cleanup-tree-dump "lim\[1-2\]" } } */
diff --git a/gcc/testsuite/c-c++-common/restrict-4.c b/gcc/testsuite/c-c++-common/restrict-4.c
new file mode 100644
index 00000000000..3a36def25cc
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/restrict-4.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-lim1-details" } */
+
+struct Foo
+{
+ int n;
+ int * __restrict__ p;
+};
+void bar(struct Foo f, int * __restrict__ q)
+{
+ int i;
+ for (i = 0; i < f.n; ++i)
+ {
+ *q += f.p[i];
+ }
+}
+
+/* { dg-final { scan-tree-dump "Executing store motion" "lim1" } } */
+/* { dg-final { cleanup-tree-dump "lim1" } } */