[Sync] Sync patch from openeuler/gcc

Sync patch from openeuler/gcc - 20230522
This commit is contained in:
huang-xiaoquan 2023-05-22 11:27:18 +08:00
parent 4b0cc3f915
commit 1e715174c3
3 changed files with 323 additions and 1 deletions

View File

@ -0,0 +1,129 @@
From bf537e82d452ee9b79f438df721c2e0dfaae12a0 Mon Sep 17 00:00:00 2001
From: Xiong Zhou <xiongzhou4@huawei.com>
Date: Fri, 5 May 2023 11:57:40 +0800
Subject: [PATCH 1/2] - bogus -Wstringop-overflow with VLA of elements larger
than byte
---
gcc/calls.c | 5 ++
gcc/testsuite/gcc.dg/Wstringop-overflow-67.c | 92 ++++++++++++++++++++
2 files changed, 97 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
diff --git a/gcc/calls.c b/gcc/calls.c
index 26894342c..45c137cee 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -2112,6 +2112,11 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
}
else
{
+ /* If the size cannot be determined clear it to keep it from
+ being taken as real (and excessive). */
+ if (objsize && integer_all_onesp (objsize))
+ objsize = NULL_TREE;
+
/* For read-only and read-write attributes also set the source
size. */
srcsize = objsize;
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
new file mode 100644
index 000000000..7b8f3f014
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
@@ -0,0 +1,92 @@
+/* PR middle-end/100571 - bogus -Wstringop-overflow with VLA of elements
+ larger than byte
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+__attribute__ ((access (read_only, 1, 2))) void fro (int *, int);
+__attribute__ ((access (write_only, 1, 2))) void fwo (int *, int);
+__attribute__ ((access (read_write, 1, 2))) void frw (int *, int);
+
+extern __SIZE_TYPE__ n;
+
+void alloca_ro (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void alloca_wo (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ fwo (a, n);
+}
+
+void alloca_rw (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void calloc_ro (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fro (a, n);
+}
+
+void calloc_wo (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fwo (a, n);
+}
+
+void calloc_rw (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void malloc_ro (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void malloc_wo (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ fwo (a, n);
+}
+
+void malloc_rw (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void vla_ro (void)
+{
+ int a[n];
+ a[0] = 0;
+ fro (a, n);
+}
+
+void vla_wo (void)
+{
+ int a[n];
+ fwo (a, n);
+}
+
+void vla_rw (void)
+{
+ int a[n];
+ a[0] = 0;
+ frw (a, n);
+}
--
2.33.0

View File

@ -0,0 +1,183 @@
From bc6537191e91c854cc6bee3319290d7a86768957 Mon Sep 17 00:00:00 2001
From: zhongyunde <zhongyunde@huawei.com>
Date: Wed, 10 May 2023 18:39:47 +0800
Subject: [PATCH 2/2] [phiopt2] Add option to control the simplify
The phiopt is brought in https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=c4574d23cb07340918793a5a98ae7bb2988b3791
But may be also has some bug fixed by later commit, so disable it default temporary.
This optimization is expected to enable after we update the gcc'base to gcc12's release version.
---
gcc/common.opt | 4 ++++
gcc/testsuite/gcc.dg/tree-ssa/20040514-1.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/bool-1.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/bool-2.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-22.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-4.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-8.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/pr18134.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/pr21829.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c | 4 ++--
gcc/tree-ssa-phiopt.c | 3 +++
13 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index be7bfee60..5ad2def18 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2781,6 +2781,10 @@ ftree-store-ccp
Common Ignore
Does nothing. Preserved for backward compatibility.
+ftree-fold-phiopt
+Common Report Var(flag_fold_phiopt) Init(0) Optimization
+Attempt to simply the phi node with ssa form.
+
ftree-ch
Common Report Var(flag_tree_ch) Optimization
Enable loop header copying on trees.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040514-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040514-1.c
index 364ce6a69..b04316d55 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/20040514-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/20040514-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-phiopt2-details" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-phiopt2-details" } */
int t( int i)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-1.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-1.c
index 401357f2f..892654108 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/bool-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
int f(_Bool x)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-2.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-2.c
index add9cca1e..5ead90f06 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/bool-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-2.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
int f(_Bool x)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
index 4c190e6af..7b678fafc 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
int nem1_phi (unsigned long a) { return a ? -1 : 0; }
int eqm1_phi (unsigned long a) { return a ? 0 : -1; }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-22.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-22.c
index fd3706666..23b679644 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-22.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-22.c
@@ -1,6 +1,6 @@
/* PR tree-optimization/97690 */
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-options "-O2 -ftree-fold-phiopt -fdump-tree-phiopt2" } */
int foo (_Bool d) { return d ? 2 : 0; }
int bar (_Bool d) { return d ? 1 : 0; }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-4.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-4.c
index 3bdb85609..4efd9afc4 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-4.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
_Bool t();
_Bool t1();
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
index 18ecbd52a..60dcc6733 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
int g(int,int);
int f(int t, int c)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-8.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-8.c
index 98c596b6a..aaa71a317 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-8.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-8.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized -fdump-tree-phiopt2" } */
+/* { dg-options "-O -ftree-fold-phiopt -fdump-tree-optimized -fdump-tree-phiopt2" } */
int g(int,int);
int f(int t, int c)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c b/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c
index cd40ab2c1..efb1907cf 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -ftree-fold-phiopt -fdump-tree-optimized" } */
int foo (int a)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c
index 8f5ae5127..8c8ada905 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -ftree-fold-phiopt -fdump-tree-optimized" } */
int test(int v)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
index a2770e5e8..88c13806a 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
@@ -1,9 +1,9 @@
/* PR tree-optimization/96928 */
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-options "-O2 -ftree-fold-phiopt -fdump-tree-phiopt2 -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } } */
/* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } */
-/* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-times " = ~" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 "phiopt2" } } */
/* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 51a2d3684..b7012932f 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -839,6 +839,9 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb,
tree result;
gimple *stmt_to_move = NULL;
+ if (!flag_fold_phiopt)
+ return false;
+
/* Special case A ? B : B as this will always simplify to B. */
if (operand_equal_for_phi_arg_p (arg0, arg1))
return false;
--
2.33.0

View File

@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
Release: 27
Release: 28
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@ -199,6 +199,8 @@ Patch87: 0087-Backport-tree-optimization-97238-fix-typo-causing-IC.patch
Patch88: 0088-Backport-fix-typo-causing-ICE.patch
Patch89: 0089-Backport-libsanitizer-cherry-pick-9cf13067cb5088626b.patch
Patch90: 0090-State-sysroot-option-as-validated-once-processed.patch
Patch91: 0091-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch
Patch92: 0092-phiopt2-Add-option-to-control-the-simplify.patch
%global gcc_target_platform %{_arch}-linux-gnu
@ -743,6 +745,8 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch88 -p1
%patch89 -p1
%patch90 -p1
%patch91 -p1
%patch92 -p1
%build
@ -2767,6 +2771,12 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Mon May 22 2023 huangxiaoquan <huangxiaoquan1@huawei.com> - 10.3.1-28
- Type:Sync
- ID:NA
- SUG:NA
- DESC:Sync patch from openeuler/gcc
* Wed Apr 12 2023 huangxiaoquan <huangxiaoquan1@huawei.com> - 10.3.1-27
- Type:enhancement
- ID:NA