[PATCH v2] OpenMP: Use VOID_TYPE_P to check for void return type in SIMD function clones.

Kevin Stefanov <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
This change fixes an issue where functions
decorated with:
pragma omp declare simd
that return void via a typedef would crash
GCC with an ICE while compiling a program
containing such a function, by using
VOID_TYPE_P instead of directly comparing
to void_type_node. New testcase added.

	PR middle-end/111856

gcc/ChangeLog:

	* omp-simd-clone.cc (simd_clone_adjust_return_type): Use VOID_TYPE_P
	when checking for void return type in adjusted functions.
	(simd_clone_adjust): Likewise.

gcc/testsuite/ChangeLog:

	* gcc.dg/gomp/pr111856.c: New test.

Signed-off-by: Kevin Stefanov <[email protected]>
---

I have replaced my previous use of
TREE_CODE with VOID_TYPE_P as per
the review and added a new test case
to compile the example openMP program
and ensure no ICE.

Bugzilla link:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111856

I have been unable to check for merge
conflicts with trunk. Upon running:
git pull --rebase origin master
I get the following error:
fatal: unable to access 'https://gcc.gnu.org/git/gcc.git/': The requested URL returned error: 429
I'm guessing this has to do with the
recently strengthened security measures
against LLM-related scraping bots?

Bootstrapped and regression tested on
x86_64-pc-linux-gnu with enable-languages=all.


 gcc/omp-simd-clone.cc                |  4 ++--
 gcc/testsuite/gcc.dg/gomp/pr111856.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/pr111856.c

diff --git a/gcc/omp-simd-clone.cc b/gcc/omp-simd-clone.cc
index 7564846fac4..4f189f243a0 100644
--- a/gcc/omp-simd-clone.cc
+++ b/gcc/omp-simd-clone.cc
@@ -715,7 +715,7 @@ simd_clone_adjust_return_type (struct cgraph_node *node)
   tree t;
 
   /* Adjust the function return type.  */
-  if (orig_rettype == void_type_node)
+  if (VOID_TYPE_P (orig_rettype))
     return;
   t = TREE_TYPE (TREE_TYPE (fndecl));
   if (INTEGRAL_TYPE_P (t) || POINTER_TYPE_P (t))
@@ -1370,7 +1370,7 @@ simd_clone_adjust (struct cgraph_node *node)
   simd_clone_adjust_argument_types (node);
   targetm.simd_clone.adjust (node);
   tree retval = NULL_TREE;
-  if (orig_rettype != void_type_node)
+  if (!VOID_TYPE_P (orig_rettype))
     {
       poly_uint64 veclen;
       if (INTEGRAL_TYPE_P (orig_rettype) || POINTER_TYPE_P (orig_rettype))
diff --git a/gcc/testsuite/gcc.dg/gomp/pr111856.c b/gcc/testsuite/gcc.dg/gomp/pr111856.c
new file mode 100644
index 00000000000..ef162f58531
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/pr111856.c
@@ -0,0 +1,11 @@
+/* PR middle-end/111856 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-simd -O2" } */
+
+typedef void T;
+int array[1000];
+#pragma omp declare simd notinbranch simdlen(4)
+T foo (int i)
+{
+  array[i] = 555;
+}
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.