Bug#1057635: Fix gcc-13 test failures during package build

2023-12-06 Thread Gwenole Beauchesne
Package: gcc-13
Version: 13.2.0-7

The gcc-ice-dump.diff patch causes the GCC driver to test for the
DEB_BUILD_OPTIONS environment variable and generate extra debug output
when an ICE occurs, for instance. This is an interesting feature,
while building other packages, but not while building GCC itself IMHO.
Dejagnu would consider that as excess errors.

I suggest to add variables to DEB_BUILD_OPTIONS to disable that
feature, and use them accordingly for the gcc-13 package itself.
Patches attached. Regression tested on x86_64-linux-gnu for
--enable-languages=c,c++ on bullseye and bookworm. Not essential, but
interesting to have for testing / trixie.

gcc-ice=norepro

   FAIL: gcc.dg/plugin/crash-test-ice-sarif.c
-fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-ice-stderr.c
-fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-write-though-null-sarif.c
-fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-write-though-null-stderr.c
-fplugin=./crash_test_plugin.so (test for excess errors)

gcc-ice=nodump

FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-3.c
-std=c++14 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-3.c
-std=c++17 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-3.c
-std=c++20 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-3.c
-std=c++98 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-4.c
-std=c++14 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-4.c
-std=c++17 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-4.c
-std=c++20 (test for excess errors)
FAIL: c-c++-common/goacc/kernels-decompose-pr100400-1-4.c
-std=c++98 (test for excess errors)
FAIL: g++.dg/cpp0x/vt-88982.C  -std=c++14 (test for excess errors)
FAIL: g++.dg/cpp0x/vt-88982.C  -std=c++17 (test for excess errors)
FAIL: g++.dg/cpp0x/vt-88982.C  -std=c++20 (test for excess errors)
FAIL: g++.dg/cpp1y/auto-fn61.C  -std=c++14 (test for excess errors)
FAIL: g++.dg/cpp1y/auto-fn61.C  -std=c++17 (test for excess errors)
FAIL: g++.dg/cpp1y/auto-fn61.C  -std=c++20 (test for excess errors)
From c046ddaa942288ba15816a94d697b0f45a702424 Mon Sep 17 00:00:00 2001
From: Gwenole Beauchesne 
Date: Sat, 2 Dec 2023 08:02:10 +0100
Subject: [PATCH 2/2] gcc: no ICE repro if DEB_BUILD_OPTIONS contains
 gcc-ice=norepro.

Don't try to reproduce the ICE if DEB_BUILD_OPTIONS environment variable
contains gcc-ice=norepro. This fixes the following testsuite failures:

FAIL: gcc.dg/plugin/crash-test-ice-sarif.c -fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-ice-stderr.c -fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-write-though-null-sarif.c -fplugin=./crash_test_plugin.so (test for excess errors)
FAIL: gcc.dg/plugin/crash-test-write-though-null-stderr.c -fplugin=./crash_test_plugin.so (test for excess errors)

Signed-off-by: Gwenole Beauchesne 
---
 gcc/gcc.cc | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 28164c83c8f..691cf81007b 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -3108,6 +3108,21 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
+/* Check whether DEB_BUILD_OPTIONS environment variable is set, and
+   that it does not contain the specified exclusion keyword.  */
+
+static bool
+has_deb_build_options (const char *exclude_str = nullptr)
+{
+  const char *const deb_build_options = env.get ("DEB_BUILD_OPTIONS");
+  if (!deb_build_options)
+return false;
+
+  if (exclude_str && strstr (deb_build_options, exclude_str))
+return false;
+  return true;
+}
+
 /* Callback for find_a_file.  Appends the file name to the directory
path.  If the resulting file exists in the right mode, return the
full pathname to the file.  */
@@ -3634,7 +3649,8 @@ execute (void)
 	/* For ICEs in cc1, cc1obj, cc1plus see if it is
 	   reproducible or not.  */
 	const char *p;
-	const char *deb_build_options = env.get("DEB_BUILD_OPTIONS");
+	const bool deb_build_options
+	  = has_deb_build_options ("gcc-ice=norepro");
 	if ((flag_report_bug || deb_build_options)
 		&& WEXITSTATUS (status) == ICE_EXIT_CODE
 		&& i == 0
@@ -7895,9 +7911,7 @@ do_report_bug (const char **new_argv, const int nargs,
 
   if (status == ATTEMPT_STATUS_SUCCESS)
 {
-  const char *deb_build_options = env.get("DEB_BUILD_OPTIONS");
-  const bool gcc_dump = deb_build_options &&
-	!strstr (deb_build_options, "gcc-ice=nodump");
+  const bool gcc_dump = has_deb_build_options ("gcc-ice=nodump");
   const bool g

Bug#1057653: Fix #pragma GCC target for C++

2023-12-06 Thread Gwenole Beauchesne
Package: gcc-13
Version: 13.2.0-7

#pragma GCC target is useful to compile specific functions with SIMD
extensions, for instance. However, that feature was long broken for
C++ where the relevant macros were not defined on the first
preprocessing pass, thus preventing some target-specific enablement.
e.g. some library wrappers for SIMD extensions usually check for SIMD
ISA macros to define vector sizes and adequate functions. The missing
define would mean a missed optimization.

This patch series addresses this issue, and is a direct backport from
the GCC mainline. Since this is not a regression vs. previous versions
of GCC, I believe there is little chance to get them from r13 branch.
(this looks broken as far as gcc 4.4.x)

0001-preprocessor-c-Support-pragma-GCC-target-macros-PR87.patch
0002-preprocessor-Reinitialize-frontend-parser-after-load.patch
0003-c-Handle-pragma-GCC-target-optimize-early.patch

Patch1 is the core fix, Patch2 is a colateral patch that addresses
ICEs from the first one. Relevant upstream issue numbers are PR
c++/41201, PR c++/48026 and PR preprocessor/87299.

IMHO, this is a nice-to-have series for testing/trixie (and Ubuntu
24.04-LTS). Note: I only regtested on bullseye and bookworm. Thanks!
From c9e56f9ea8c56aa321ce47ca2e677b0dd98b3d21 Mon Sep 17 00:00:00 2001
From: Gwenole Beauchesne 
Date: Sat, 25 Nov 2023 11:43:21 +0100
Subject: [PATCH 3/3] c++: Handle '#pragma GCC target optimize' early.

Handle '#pragma GCC optimize' earlier as the __OPTIMIZE__ macro may need
to be defined as well for certain usages. Add additional tests for the
'#pragma GCC target' case with auto-vectorization enabled and multiple
combinations of namespaces and/or class member functions.

Add more complete tests for PR c++/41201 after git commit 8697d3a1.

gcc/testsuite/ChangeLog:

PR c++/41201
* g++.target/i386/vect-pragma-target-1.C: New test.
* g++.target/i386/vect-pragma-target-2.C: New test.
* gcc.target/i386/vect-pragma-target-1.c: New test.
* gcc.target/i386/vect-pragma-target-1.c: New test.

Signed-off-by: Gwenole Beauchesne 
---
 gcc/c-family/c-pragma.cc  |   4 +-
 .../g++.target/i386/vect-pragma-target-1.C|   6 +
 .../g++.target/i386/vect-pragma-target-2.C|   6 +
 .../gcc.target/i386/vect-pragma-target-1.c| 194 ++
 .../gcc.target/i386/vect-pragma-target-2.c|   7 +
 5 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.target/i386/vect-pragma-target-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/vect-pragma-target-2.C
 create mode 100644 gcc/testsuite/gcc.target/i386/vect-pragma-target-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vect-pragma-target-2.c

diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 8931b5e9cbb..915fbaf3676 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1848,7 +1848,9 @@ init_pragma (void)
   c_register_pragma_with_early_handler ("GCC", "target",
 	handle_pragma_target,
 	handle_pragma_target);
-  c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
+  c_register_pragma_with_early_handler ("GCC", "optimize",
+	handle_pragma_optimize,
+	handle_pragma_optimize);
   c_register_pragma_with_early_handler ("GCC", "push_options",
 	handle_pragma_push_options,
 	handle_pragma_push_options);
diff --git a/gcc/testsuite/g++.target/i386/vect-pragma-target-1.C b/gcc/testsuite/g++.target/i386/vect-pragma-target-1.C
new file mode 100644
index 000..2f360cf50e1
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/vect-pragma-target-1.C
@@ -0,0 +1,6 @@
+/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */
+/* { dg-options "-O0" } */
+/* { dg-final { scan-assembler-times "paddd.+xmm\[0-9]+"1 } }   */
+/* { dg-final { scan-assembler-times "vfmadd132ps.+ymm\[0-9]+"  1 } }   */
+/* { dg-final { scan-assembler-times "vpaddw.+zmm\[0-9]+"   1 } }   */
+#include "../../gcc.target/i386/vect-pragma-target-1.c"
diff --git a/gcc/testsuite/g++.target/i386/vect-pragma-target-2.C b/gcc/testsuite/g++.target/i386/vect-pragma-target-2.C
new file mode 100644
index 000..b85bc93d845
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/vect-pragma-target-2.C
@@ -0,0 +1,6 @@
+/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */
+/* { dg-options "-O0" } */
+/* { dg-final { scan-assembler-times "paddd.+xmm\[0-9]+"1 } }   */
+/* { dg-final { scan-assembler-times "vfmadd132ps.+ymm\[0-9]+"  1 } }   */
+/* { dg-final { scan-assembler-times "vpaddw.+zmm\[0-9]+"   1 } }   */
+#include "../../gcc.target/i386/vect-pragma-target-2.c&qu

Bug#1057635: Fix gcc-13 test failures during package build

2023-12-08 Thread Gwenole Beauchesne
Hi,

New patches attached. I also reformatted them with contrib/clang-format.
For now, only tested with DEB_BUILD_OPTIONS="parallel=12 gcc-ice=XXX"
make -j12 check-gcc-c++ from an existing build, with multiple
combinations of XXX = { "nodump,norepro", "nodump", "norepro",
"default" }.

Also made standalone tests for the has_deb_build_options() function.

Regards,
Gwenole.

Le jeu. 7 déc. 2023 à 10:45, Matthias Klose  a écrit :
>
> On 06.12.23 10:30, Gwenole Beauchesne wrote:
> > Package: gcc-13
> > Version: 13.2.0-7
> >
> > The gcc-ice-dump.diff patch causes the GCC driver to test for the
> > DEB_BUILD_OPTIONS environment variable and generate extra debug output
> > when an ICE occurs, for instance. This is an interesting feature,
> > while building other packages, but not while building GCC itself IMHO.
> > Dejagnu would consider that as excess errors.
> >
> > I suggest to add variables to DEB_BUILD_OPTIONS to disable that
> > feature, and use them accordingly for the gcc-13 package itself.
> > Patches attached. Regression tested on x86_64-linux-gnu for
> > --enable-languages=c,c++ on bullseye and bookworm. Not essential, but
> > interesting to have for testing / trixie.
>
> please change that to also accept gcc-ice=norepro,nodump,
> gcc-ice=nodump,norepro.
>
> please base your patches on
> https://salsa.debian.org/toolchain-team/gcc/tree/gcc-13-debian
> updating the gcc-ice-dump and gcc-ice-apport patches.
>
> thanks, Matthias
# DP: Report an ICE to apport (if apport is available
# DP: and the environment variable GCC_NOAPPORT is not set)

--- a/src/gcc/gcc.cc
+++ b/src/gcc/gcc.cc
@@ -7935,13 +7935,16 @@ do_report_bug (const char **new_argv, const int nargs,
   if (status == ATTEMPT_STATUS_SUCCESS)
 {
   const bool gcc_dump = has_deb_build_options ("gcc-ice", "nodump");
+  const bool gcc_apport
+	= !env.get ("GCC_NOAPPORT")
+	  && !access ("/usr/share/apport/gcc_ice_hook", R_OK | X_OK);
 
   if (gcc_dump)
 	fnotice (stderr,
 		 "Preprocessed source stored into %s file,"
 		 " please attach this to your bugreport.\n",
 		 *out_file);
-  if (gcc_dump)
+  if (gcc_dump || gcc_apport)
 	{
 	  char *cmd = XNEWVEC (char, 50 + strlen (*out_file));
 
@@ -7955,6 +7958,15 @@ do_report_bug (const char **new_argv, const int nargs,
 	  fflush (stderr);
 	  free (cmd);
 	}
+  if (gcc_apport)
+	{
+	  char *cmd
+	= XNEWVEC (char, 50 + strlen (*out_file) + strlen (new_argv[0]));
+	  sprintf (cmd, "/usr/share/apport/gcc_ice_hook %s %s", new_argv[0],
+		   *out_file);
+	  system (cmd);
+	  free (cmd);
+	}
   /* Make sure it is not deleted.  */
   free (*out_file);
   *out_file = NULL;
# DP: For ICEs, dump the preprocessed source file to stderr
# DP: when in a distro build environment.

--- a/src/gcc/gcc.cc
+++ b/src/gcc/gcc.cc
@@ -3108,6 +3108,61 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
+/* Check whether options line contains the specified variable, and
+   optionally set to the supplied value */
+
+static bool
+check_options (const char *options, const char *var = nullptr,
+	   const char *val = nullptr)
+{
+  if (!var)
+return false;
+
+  const char *const var_found = strstr (options, var);
+  if (!var_found)
+return false;
+
+  if (val)
+{
+  if (var_found[strlen (var)] != '=')
+	return false;
+
+  const char *var_end = strchr (var_found, ' ');
+  if (!var_end)
+	var_end = strchr (var_found, '\0');
+
+  const char *const val_found = strstr (var_found, val);
+  if (!val_found || val_found > var_end)
+	return false;
+
+  const char c0 = val_found[-1];
+  const char c1 = val_found[strlen (val)];
+  if ((c0 == '=' || c0 == ',') && (c1 == ',' || c1 == ' ' || c1 == '\0'))
+	return true;
+}
+  else
+{
+  const char c1 = var_found[strlen (var)];
+  if (c1 == ' ' || c1 == '\0')
+	return true;
+}
+  return false;
+}
+
+/* Check whether DEB_BUILD_OPTIONS environment variable is set, and
+   that it does not contain the specified exclusion keyword.  */
+
+static bool
+has_deb_build_options (const char *exclude_var = nullptr,
+		   const char *exclude_val = nullptr)
+{
+  const char *const deb_build_options = env.get ("DEB_BUILD_OPTIONS");
+  if (!deb_build_options)
+return false;
+
+  return !check_options (deb_build_options, exclude_var, exclude_val);
+}
+
 /* Callback for find_a_file.  Appends the file name to the directory
path.  If the resulting file exists in the right mode, return the
full pathname to the file.  */
@@ -3634,9 +3673,10 @@ execute (void)
 	/* For ICEs in cc1, cc1obj, cc1plus see if