public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: Andrew Pinski <pinskia@gmail.com>
Subject: [PATCH] convert_to_complex vs invalid_conversion [PR111903]
Date: Sat, 21 Oct 2023 11:07:12 -0700	[thread overview]
Message-ID: <20231021180712.370694-1-pinskia@gmail.com> (raw)

convert_to_complex when creating a COMPLEX_EXPR does
not currently check if either the real or imag parts
was not error_mark_node. This later on confuses the gimpilfier
when there was a SAVE_EXPR wrapped around that COMPLEX_EXPR.
The simple fix is after calling convert inside convert_to_complex_1,
check that the either result was an error_operand and return
an error_mark_node in that case.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

	PR c/111903

gcc/ChangeLog:

	* convert.cc (convert_to_complex_1): Return
	error_mark_node if either convert was an error
	when converting from a scalar.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/float16-8.c: New test.
---
 gcc/convert.cc                            |  9 +++++++--
 gcc/testsuite/gcc.target/i386/float16-8.c | 12 ++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-8.c

diff --git a/gcc/convert.cc b/gcc/convert.cc
index 80d86fe3708..ac6af7026a7 100644
--- a/gcc/convert.cc
+++ b/gcc/convert.cc
@@ -1006,8 +1006,13 @@ convert_to_complex_1 (tree type, tree expr, bool fold_p)
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
     case BITINT_TYPE:
-      return build2 (COMPLEX_EXPR, type, convert (subtype, expr),
-		     convert (subtype, integer_zero_node));
+      {
+	tree real = convert (subtype, expr);
+	tree imag = convert (subtype, integer_zero_node);
+	if (error_operand_p (real) || error_operand_p (imag))
+	  return error_mark_node;
+	return build2 (COMPLEX_EXPR, type, real, imag);
+      }
 
     case COMPLEX_TYPE:
       {
diff --git a/gcc/testsuite/gcc.target/i386/float16-8.c b/gcc/testsuite/gcc.target/i386/float16-8.c
new file mode 100644
index 00000000000..003f82e7146
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/float16-8.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-mno-sse" } */
+/* PR c/111903 */
+
+int i;
+_Float16 f;
+int bar(...);
+void
+foo (void)
+{
+  i /= bar ((_Complex _Float16) f); /* { dg-error "" } */
+}
-- 
2.39.3


             reply	other threads:[~2023-10-21 18:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-21 18:07 Andrew Pinski [this message]
2023-10-23  7:43 ` Richard Biener

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=20231021180712.370694-1-pinskia@gmail.com \
    --to=pinskia@gmail.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).