aboutsummaryrefslogtreecommitdiff
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/attr-aligned-1.c24
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr65238-1.c53
-rw-r--r--gcc/testsuite/c-c++-common/pr65556.c23
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/align-9.c21
4 files changed, 121 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/attr-aligned-1.c b/gcc/testsuite/c-c++-common/attr-aligned-1.c
new file mode 100644
index 00000000000..671e86baeb6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-aligned-1.c
@@ -0,0 +1,24 @@
+/* PR c++/65690 */
+/* { dg-do run } */
+
+typedef double T[4][4] __attribute__((aligned (2 * __alignof__ (double))));
+void foo (const T);
+struct S { T s; };
+
+int
+main ()
+{
+ if (__alignof__ (struct S) != 2 * __alignof__ (double)
+ || __alignof__ (T) != 2 * __alignof__ (double)
+ || __alignof__ (const struct S) != 2 * __alignof__ (double)
+ || __alignof__ (const T) != 2 * __alignof__ (double))
+ __builtin_abort ();
+ return 0;
+}
+
+#if defined(__cplusplus) && __cplusplus >= 201103L
+static_assert (alignof (S) == 2 * alignof (double), "alignment of S");
+static_assert (alignof (T) == 2 * alignof (double), "alignment of T");
+static_assert (alignof (const S) == 2 * alignof (double), "alignment of const S");
+static_assert (alignof (const T) == 2 * alignof (double), "alignment of const T");
+#endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr65238-1.c b/gcc/testsuite/c-c++-common/cpp/pr65238-1.c
new file mode 100644
index 00000000000..6d6346535ab
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr65238-1.c
@@ -0,0 +1,53 @@
+/* PR preprocessor/65238 */
+/* { dg-do run } */
+
+#define A unused
+#define B A
+#define C B
+#define D __has_attribute(unused)
+#define E __has_attribute(C)
+#define F(X) __has_attribute(X)
+#if !__has_attribute(unused)
+#error unused attribute not supported - 1
+#endif
+#if !__has_attribute(C)
+#error unused attribute not supported - 2
+#endif
+#if !D
+#error unused attribute not supported - 3
+#endif
+#if !E
+#error unused attribute not supported - 4
+#endif
+#if !F(unused)
+#error unused attribute not supported - 5
+#endif
+#if !F(C)
+#error unused attribute not supported - 6
+#endif
+int a = __has_attribute (unused) + __has_attribute (C) + D + E + F (unused) + F (C);
+int b = __has_attribute (unused);
+int c = __has_attribute (C);
+int d = D;
+int e = E;
+int f = F (unused);
+int g = F (C);
+int h = __has_attribute (
+ unused
+) + __has_attribute (
+
+C) + F (
+unused
+
+) + F
+(
+C
+);
+
+int
+main ()
+{
+ if (a != 6 || b != 1 || c != 1 || d != 1 || e != 1 || f != 1 || g != 1 || h != 4)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/pr65556.c b/gcc/testsuite/c-c++-common/pr65556.c
new file mode 100644
index 00000000000..8629a48fdce
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr65556.c
@@ -0,0 +1,23 @@
+/* PR c++/65556 */
+/* { dg-do compile } */
+
+struct S
+{
+ long l: 1;
+ long l2: 21;
+ unsigned long ul: 1;
+ unsigned long ul2: 21;
+} s;
+
+void
+fn ()
+{
+ switch (s.l)
+ case 0:;
+ switch (s.ul)
+ case 0:;
+ switch (s.l2)
+ case 0:;
+ switch (s.ul2)
+ case 0:;
+}
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-9.c b/gcc/testsuite/c-c++-common/ubsan/align-9.c
new file mode 100644
index 00000000000..24cba94f277
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/align-9.c
@@ -0,0 +1,21 @@
+/* Limit this to known non-strict alignment targets. */
+/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
+/* { dg-options "-O2 -fsanitize=alignment -fsanitize-recover=alignment" } */
+
+__attribute__((noinline, noclone)) void
+foo (void *p, const void *q)
+{
+ *(long int *) p = *(const long int *) q;
+}
+
+int
+main ()
+{
+ struct S { long c; char f[64]; char d; char e[2 * sizeof (long)]; char g[64]; } s;
+ __builtin_memset (&s, '\0', sizeof s);
+ foo (&s.e[0], &s.e[sizeof (long)]);
+ return 0;
+}
+
+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'const long int', which requires \[48] byte alignment.*" } */
+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*store to misaligned address 0x\[0-9a-fA-F]* for type 'long int', which requires \[48] byte alignment" } */