On Sat, Mar 20, 2021 at 6:46 AM Martin Liška <mli...@suse.cz> wrote:
>
> On 3/20/21 1:21 PM, H.J. Lu wrote:
> > |Since construct_container may be called with cfun == NULL, check cfun != 
> > NULL before accessing silent_p. |
>
> Thank you for the quick fix.
>
> Please use the minimal reproducer for a test-case:
>
> $ cat va-arg-pack-1.C
> #include <stdarg.h>
> void abort() {
>    double ld;
>    va_list ap;
>    ld = va_arg(ap, long double);
>    if (ld)
>      abort();
> }
>

Fixed.  I also added a testcase for SSE register.

Here is the v2 patch.  OK for master?

Thanks.

-- 
H.J.
From 5abf5691a075a9e992b527a1f1a3018b68ac8768 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Sat, 20 Mar 2021 05:17:36 -0700
Subject: [PATCH v2] x86: Check cfun != NULL before accessing silent_p

Since construct_container may be called with cfun == NULL, check
cfun != NULL before accessing silent_p.

gcc/

	PR target/99679
	* config/i386/i386.c (construct_container): Check cfun != NULL
	before accessing silent_p.

gcc/testsuite/

	PR target/99679
	* g++.target/i386/pr99679-1.C: New test.
	* g++.target/i386/pr99679-2.C: Likewise.
---
 gcc/config/i386/i386.c                    |  4 ++--
 gcc/testsuite/g++.target/i386/pr99679-1.C | 17 +++++++++++++++++
 gcc/testsuite/g++.target/i386/pr99679-2.C | 17 +++++++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr99679-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/pr99679-2.C

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 714349094bd..7c41302c75b 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2540,7 +2540,7 @@ construct_container (machine_mode mode, machine_mode orig_mode,
     {
       /* Return early if we shouldn't raise an error for invalid
 	 calls.  */
-      if (cfun->machine->silent_p)
+      if (cfun != NULL && cfun->machine->silent_p)
 	return NULL;
       if (in_return)
 	{
@@ -2568,7 +2568,7 @@ construct_container (machine_mode mode, machine_mode orig_mode,
 	{
 	  /* Return early if we shouldn't raise an error for invalid
 	     calls.  */
-	  if (cfun->machine->silent_p)
+	  if (cfun != NULL && cfun->machine->silent_p)
 	    return NULL;
 	  if (!issued_x87_ret_error)
 	    {
diff --git a/gcc/testsuite/g++.target/i386/pr99679-1.C b/gcc/testsuite/g++.target/i386/pr99679-1.C
new file mode 100644
index 00000000000..36640a4e0a1
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr99679-1.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-options "-Ofast -fipa-pta -mno-80387" }
+
+#include <stdarg.h>
+
+extern "C" void abort (void);
+
+void
+foo (int x, ...)
+{
+  long double ld;
+  va_list ap;
+  va_start (ap, x);
+  ld = va_arg (ap, long double);
+  if (ld)
+    abort ();
+} // { dg-error "x87 register return with x87 disabled" "" { target { ! ia32 } } }
diff --git a/gcc/testsuite/g++.target/i386/pr99679-2.C b/gcc/testsuite/g++.target/i386/pr99679-2.C
new file mode 100644
index 00000000000..cbd3c4958db
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr99679-2.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-options "-Ofast -fipa-pta -mgeneral-regs-only" }
+
+#include <stdarg.h>
+
+extern "C" void abort (void);
+
+void
+foo (int x, ...)
+{
+  double ld;
+  va_list ap;
+  va_start (ap, x);
+  ld = va_arg (ap, double); // { dg-error "SSE register argument with SSE disabled" "" { target { ! ia32 } } }
+  if (ld)
+    abort ();
+} // { dg-error "SSE register return with SSE disabled" "" { target { ! ia32 } } }
-- 
2.30.2

Reply via email to