aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2024-06-13 22:41:02 +0000
committerJoseph Myers <josmyers@redhat.com>2024-06-13 22:41:59 +0000
commit3bb21028698be33ae90115fce507f151182a4450 (patch)
treec345f0ca19de450844e135d1e0c4daf073f845c2 /gcc
parent8c9b4dff6298a203aba41c90377099f7ed678bde (diff)
downloadgcc-3bb21028698be33ae90115fce507f151182a4450.zip
gcc-3bb21028698be33ae90115fce507f151182a4450.tar.gz
gcc-3bb21028698be33ae90115fce507f151182a4450.tar.bz2
c: Implement C2Y complex increment/decrement support
Support for complex increment and decrement (previously supported as an extension) was voted into C2Y today (paper N3259). Thus, change the pedwarn to a pedwarn_c23 and add associated tests. Note: the type of the 1 to be added / subtracted is underspecified (to be addressed in a subsequent paper), but understood to be intended to be a real type (so the sign of a zero imaginary part is never changed) and this is what is implemented; the tests added include verifying that there is no undesired change to the sign of a zero imaginary part. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c/ * c-typeck.cc (build_unary_op): Use pedwarn_c23 for complex increment and decrement. gcc/testsuite/ * gcc.dg/c23-complex-1.c, gcc.dg/c23-complex-2.c, gcc.dg/c23-complex-3.c, gcc.dg/c23-complex-4.c, gcc.dg/c2y-complex-1.c, gcc.dg/c2y-complex-2.c: New tests.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-typeck.cc5
-rw-r--r--gcc/testsuite/gcc.dg/c23-complex-1.c14
-rw-r--r--gcc/testsuite/gcc.dg/c23-complex-2.c15
-rw-r--r--gcc/testsuite/gcc.dg/c23-complex-3.c15
-rw-r--r--gcc/testsuite/gcc.dg/c23-complex-4.c15
-rw-r--r--gcc/testsuite/gcc.dg/c2y-complex-1.c232
-rw-r--r--gcc/testsuite/gcc.dg/c2y-complex-2.c14
7 files changed, 308 insertions, 2 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index a5ca9ea..ffcab7d 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -5079,8 +5079,9 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
{
tree real, imag;
- pedwarn (location, OPT_Wpedantic,
- "ISO C does not support %<++%> and %<--%> on complex types");
+ pedwarn_c23 (location, OPT_Wpedantic,
+ "ISO C does not support %<++%> and %<--%> on complex "
+ "types before C2Y");
if (!atomic_op)
{
diff --git a/gcc/testsuite/gcc.dg/c23-complex-1.c b/gcc/testsuite/gcc.dg/c23-complex-1.c
new file mode 100644
index 0000000..3607336
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-complex-1.c
@@ -0,0 +1,14 @@
+/* Test C2Y complex increment and decrement: disallowed for C23. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+_Complex float a;
+
+void
+f (void)
+{
+ a++; /* { dg-error "does not support" } */
+ ++a; /* { dg-error "does not support" } */
+ a--; /* { dg-error "does not support" } */
+ --a; /* { dg-error "does not support" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c23-complex-2.c b/gcc/testsuite/gcc.dg/c23-complex-2.c
new file mode 100644
index 0000000..301b668
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-complex-2.c
@@ -0,0 +1,15 @@
+/* Test C2Y complex increment and decrement: disallowed for C23 (warning with
+ -pedantic). */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic" } */
+
+_Complex float a;
+
+void
+f (void)
+{
+ a++; /* { dg-warning "does not support" } */
+ ++a; /* { dg-warning "does not support" } */
+ a--; /* { dg-warning "does not support" } */
+ --a; /* { dg-warning "does not support" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c23-complex-3.c b/gcc/testsuite/gcc.dg/c23-complex-3.c
new file mode 100644
index 0000000..6fef301
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-complex-3.c
@@ -0,0 +1,15 @@
+/* Test C2Y complex increment and decrement: allowed for C23 with
+ -Wno-c23-c2y-compat. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors -Wno-c23-c2y-compat" } */
+
+_Complex float a;
+
+void
+f (void)
+{
+ a++;
+ ++a;
+ a--;
+ --a;
+}
diff --git a/gcc/testsuite/gcc.dg/c23-complex-4.c b/gcc/testsuite/gcc.dg/c23-complex-4.c
new file mode 100644
index 0000000..61d50e9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-complex-4.c
@@ -0,0 +1,15 @@
+/* Test C2Y complex increment and decrement: allowed for C23 by default (not
+ pedantic). */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+_Complex float a;
+
+void
+f (void)
+{
+ a++;
+ ++a;
+ a--;
+ --a;
+}
diff --git a/gcc/testsuite/gcc.dg/c2y-complex-1.c b/gcc/testsuite/gcc.dg/c2y-complex-1.c
new file mode 100644
index 0000000..29a8c27
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-complex-1.c
@@ -0,0 +1,232 @@
+/* Test C2Y complex increment and decrement. */
+/* { dg-do run } */
+/* { dg-options "-std=c2y -pedantic-errors" } */
+
+extern void abort (void);
+extern void exit (int);
+
+_Complex float a, ax;
+_Complex double b, bx;
+_Complex long double c, cx;
+
+int
+main ()
+{
+ ax = a++;
+ if (ax != 0
+ || a != 1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || __builtin_signbit (__builtin_cimagf (ax))
+ || __builtin_signbit (__builtin_crealf (a))
+ || __builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = __builtin_complex (0.0f, -0.0f);
+ ax = a++;
+ if (ax != 0
+ || a != 1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || !__builtin_signbit (__builtin_cimagf (ax))
+ || __builtin_signbit (__builtin_crealf (a))
+ || !__builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = 0;
+ ax = ++a;
+ if (ax != 1
+ || a != 1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || __builtin_signbit (__builtin_cimagf (ax))
+ || __builtin_signbit (__builtin_crealf (a))
+ || __builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = __builtin_complex (0.0f, -0.0f);
+ ax = ++a;
+ if (ax != 1
+ || a != 1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || !__builtin_signbit (__builtin_cimagf (ax))
+ || __builtin_signbit (__builtin_crealf (a))
+ || !__builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = 0;
+ ax = a--;
+ if (ax != 0
+ || a != -1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || __builtin_signbit (__builtin_cimagf (ax))
+ || !__builtin_signbit (__builtin_crealf (a))
+ || __builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = __builtin_complex (0.0f, -0.0f);
+ ax = a--;
+ if (ax != 0
+ || a != -1
+ || __builtin_signbit (__builtin_crealf (ax))
+ || !__builtin_signbit (__builtin_cimagf (ax))
+ || !__builtin_signbit (__builtin_crealf (a))
+ || !__builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = 0;
+ ax = --a;
+ if (ax != -1
+ || a != -1
+ || !__builtin_signbit (__builtin_crealf (ax))
+ || __builtin_signbit (__builtin_cimagf (ax))
+ || !__builtin_signbit (__builtin_crealf (a))
+ || __builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+ a = __builtin_complex (0.0f, -0.0f);
+ ax = --a;
+ if (ax != -1
+ || a != -1
+ || !__builtin_signbit (__builtin_crealf (ax))
+ || !__builtin_signbit (__builtin_cimagf (ax))
+ || !__builtin_signbit (__builtin_crealf (a))
+ || !__builtin_signbit (__builtin_cimagf (a)))
+ abort ();
+
+ bx = b++;
+ if (bx != 0
+ || b != 1
+ || __builtin_signbit (__builtin_creal (bx))
+ || __builtin_signbit (__builtin_cimag (bx))
+ || __builtin_signbit (__builtin_creal (b))
+ || __builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = __builtin_complex (0.0, -0.0);
+ bx = b++;
+ if (bx != 0
+ || b != 1
+ || __builtin_signbit (__builtin_creal (bx))
+ || !__builtin_signbit (__builtin_cimag (bx))
+ || __builtin_signbit (__builtin_creal (b))
+ || !__builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = 0;
+ bx = ++b;
+ if (bx != 1
+ || b != 1
+ || __builtin_signbit (__builtin_creal (bx))
+ || __builtin_signbit (__builtin_cimag (bx))
+ || __builtin_signbit (__builtin_creal (b))
+ || __builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = __builtin_complex (0.0, -0.0);
+ bx = ++b;
+ if (bx != 1
+ || b != 1
+ || __builtin_signbit (__builtin_creal (bx))
+ || !__builtin_signbit (__builtin_cimag (bx))
+ || __builtin_signbit (__builtin_creal (b))
+ || !__builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = 0;
+ bx = b--;
+ if (bx != 0
+ || b != -1
+ || __builtin_signbit (__builtin_creal (bx))
+ || __builtin_signbit (__builtin_cimag (bx))
+ || !__builtin_signbit (__builtin_creal (b))
+ || __builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = __builtin_complex (0.0f, -0.0f);
+ bx = b--;
+ if (bx != 0
+ || b != -1
+ || __builtin_signbit (__builtin_creal (bx))
+ || !__builtin_signbit (__builtin_cimag (bx))
+ || !__builtin_signbit (__builtin_creal (b))
+ || !__builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = 0;
+ bx = --b;
+ if (bx != -1
+ || b != -1
+ || !__builtin_signbit (__builtin_creal (bx))
+ || __builtin_signbit (__builtin_cimag (bx))
+ || !__builtin_signbit (__builtin_creal (b))
+ || __builtin_signbit (__builtin_cimag (b)))
+ abort ();
+ b = __builtin_complex (0.0f, -0.0f);
+ bx = --b;
+ if (bx != -1
+ || b != -1
+ || !__builtin_signbit (__builtin_creal (bx))
+ || !__builtin_signbit (__builtin_cimag (bx))
+ || !__builtin_signbit (__builtin_creal (b))
+ || !__builtin_signbit (__builtin_cimag (b)))
+ abort ();
+
+ cx = c++;
+ if (cx != 0
+ || c != 1
+ || __builtin_signbit (__builtin_creall (cx))
+ || __builtin_signbit (__builtin_cimagl (cx))
+ || __builtin_signbit (__builtin_creall (c))
+ || __builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = __builtin_complex (0.0L, -0.0L);
+ cx = c++;
+ if (cx != 0
+ || c != 1
+ || __builtin_signbit (__builtin_creall (cx))
+ || !__builtin_signbit (__builtin_cimagl (cx))
+ || __builtin_signbit (__builtin_creall (c))
+ || !__builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = 0;
+ cx = ++c;
+ if (cx != 1
+ || c != 1
+ || __builtin_signbit (__builtin_creall (cx))
+ || __builtin_signbit (__builtin_cimagl (cx))
+ || __builtin_signbit (__builtin_creall (c))
+ || __builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = __builtin_complex (0.0L, -0.0L);
+ cx = ++c;
+ if (cx != 1
+ || c != 1
+ || __builtin_signbit (__builtin_creall (cx))
+ || !__builtin_signbit (__builtin_cimagl (cx))
+ || __builtin_signbit (__builtin_creall (c))
+ || !__builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = 0;
+ cx = c--;
+ if (cx != 0
+ || c != -1
+ || __builtin_signbit (__builtin_creall (cx))
+ || __builtin_signbit (__builtin_cimagl (cx))
+ || !__builtin_signbit (__builtin_creall (c))
+ || __builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = __builtin_complex (0.0L, -0.0L);
+ cx = c--;
+ if (cx != 0
+ || c != -1
+ || __builtin_signbit (__builtin_creall (cx))
+ || !__builtin_signbit (__builtin_cimagl (cx))
+ || !__builtin_signbit (__builtin_creall (c))
+ || !__builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = 0;
+ cx = --c;
+ if (cx != -1
+ || c != -1
+ || !__builtin_signbit (__builtin_creall (cx))
+ || __builtin_signbit (__builtin_cimagl (cx))
+ || !__builtin_signbit (__builtin_creall (c))
+ || __builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+ c = __builtin_complex (0.0L, -0.0L);
+ cx = --c;
+ if (cx != -1
+ || c != -1
+ || !__builtin_signbit (__builtin_creall (cx))
+ || !__builtin_signbit (__builtin_cimagl (cx))
+ || !__builtin_signbit (__builtin_creall (c))
+ || !__builtin_signbit (__builtin_cimagl (c)))
+ abort ();
+
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2y-complex-2.c b/gcc/testsuite/gcc.dg/c2y-complex-2.c
new file mode 100644
index 0000000..0ca8949
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-complex-2.c
@@ -0,0 +1,14 @@
+/* Test C2Y complex increment and decrement: warning with -Wc23-c2y-compat. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2y -pedantic-errors -Wc23-c2y-compat" } */
+
+_Complex float a;
+
+void
+f (void)
+{
+ a++; /* { dg-warning "does not support" } */
+ ++a; /* { dg-warning "does not support" } */
+ a--; /* { dg-warning "does not support" } */
+ --a; /* { dg-warning "does not support" } */
+}