public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joseph Myers <josmyers@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] c: Implement C2Y complex increment/decrement support
Date: Thu, 13 Jun 2024 22:42:43 +0000 (UTC)	[thread overview]
Message-ID: <2dc13953-8a5-2623-c4ba-e7ff38669d59@redhat.com> (raw)

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.

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index a5ca9ea7db6..ffcab7df4d3 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 00000000000..3607336593d
--- /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 00000000000..301b668ea15
--- /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 00000000000..6fef30105b0
--- /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 00000000000..61d50e9a1dd
--- /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 00000000000..29a8c2771ac
--- /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 00000000000..0ca8949b07d
--- /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" } */
+}

-- 
Joseph S. Myers
josmyers@redhat.com


                 reply	other threads:[~2024-06-13 22:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2dc13953-8a5-2623-c4ba-e7ff38669d59@redhat.com \
    --to=josmyers@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).