middle-end/105140 - fix bogus recursion in fold_convertible_p

Message ID 20220404093351.CDF3413216@imap2.suse-dmz.suse.de
State Committed
Commit eaaf77dd85c333b116111bb1ae6c080154a4e411
Headers
Series middle-end/105140 - fix bogus recursion in fold_convertible_p |

Commit Message

Richard Biener April 4, 2022, 9:33 a.m. UTC
  fold_convertible_p expects an operand and a type to convert to
but recurses with two vector component types.  Fixed by allowing
types instead of an operand as well.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-04-04  Richard Biener  <rguenther@suse.de>

	PR middle-end/105140
	* fold-const.cc (fold_convertible_p): Allow a TYPE_P arg.

	* gcc.dg/pr105140.c: New testcase.
---
 gcc/fold-const.cc               |  5 +++--
 gcc/testsuite/gcc.dg/pr105140.c | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr105140.c
  

Patch

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index b647e5305aa..fb08fa1dbc6 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -2379,12 +2379,13 @@  build_zero_vector (tree type)
   return build_vector_from_val (type, t);
 }
 
-/* Returns true, if ARG is convertible to TYPE using a NOP_EXPR.  */
+/* Returns true, if ARG, an operand or a type, is convertible to TYPE
+   using a NOP_EXPR.  */
 
 bool
 fold_convertible_p (const_tree type, const_tree arg)
 {
-  tree orig = TREE_TYPE (arg);
+  const_tree orig = TYPE_P (arg) ? arg : TREE_TYPE (arg);
 
   if (type == orig)
     return true;
diff --git a/gcc/testsuite/gcc.dg/pr105140.c b/gcc/testsuite/gcc.dg/pr105140.c
new file mode 100644
index 00000000000..14bff2f7f9c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105140.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-options "-Os -w -Wno-psabi" } */
+
+typedef char __attribute__((__vector_size__ (16 * sizeof (char)))) U;
+typedef int __attribute__((__vector_size__ (16 * sizeof (int)))) V;
+
+void bar ();
+
+bar (int i, int j, int k, V v)
+{
+}
+
+void
+foo (void)
+{
+  bar ((V){}, (V){}, (V){}, (U){});
+}