From fcefabef1d9e40186810dd898f94cf87f6ad877d Mon Sep 17 00:00:00 2001 From: huzife <634763349@qq.com> Date: Sat, 22 Feb 2025 11:19:00 +0800 Subject: [PATCH] [Bugfix]Fix errors in ipa-struct-sfc(issue:IBMY84, IBN2JO, IBN42Q) (cherry picked from commit e65c6e1dca2ed76007ee8ab385efdb8706228030) --- ...-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch | 154 ++++++++++++++++++ gcc.spec | 10 +- 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 0355-Fix-errors-in-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch diff --git a/0355-Fix-errors-in-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch b/0355-Fix-errors-in-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch new file mode 100644 index 0000000..8be2b1d --- /dev/null +++ b/0355-Fix-errors-in-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch @@ -0,0 +1,154 @@ +From c2444a1259ac0f082f8ce8919a053bd1de504781 Mon Sep 17 00:00:00 2001 +From: huzife <634763349@qq.com> +Date: Thu, 20 Feb 2025 14:52:19 +0800 +Subject: [PATCH] Fix errors in ipa-struct-sfc (IBMY84, IBN2JO, IBN42Q) + +--- + gcc/ipa-struct-reorg/ipa-struct-reorg.cc | 31 ++++++++++++++++--- + .../gcc.dg/struct/sfc-shadow_non_integer.c | 25 +++++++++++++++ + gcc/testsuite/gcc.dg/struct/sfc_non_integer.c | 29 +++++++++++++++++ + 3 files changed, 81 insertions(+), 4 deletions(-) + create mode 100644 gcc/testsuite/gcc.dg/struct/sfc-shadow_non_integer.c + create mode 100644 gcc/testsuite/gcc.dg/struct/sfc_non_integer.c + +diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +index d3beebc00..f2660c952 100644 +--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc ++++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +@@ -4367,6 +4367,20 @@ ipa_struct_reorg::wholeaccess (tree expr, tree base, + if (!handled_type (TREE_TYPE (expr))) + return false; + ++ if (!t || !t->type) ++ return false; ++ ++ tree type = TYPE_MAIN_VARIANT (t->type); ++ if (TREE_CODE (expr) == MEM_REF ++ && POINTER_TYPE_P (TREE_TYPE (expr)) ++ && POINTER_TYPE_P (accesstype) ++ && POINTER_TYPE_P (TREE_TYPE (accesstype)) ++ && POINTER_TYPE_P (TREE_TYPE (base)) ++ && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base))) == type ++ && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr))) == type ++ && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (accesstype))) == type) ++ return false; ++ + srtype *other_type = find_type (inner_type (TREE_TYPE (expr))); + + if (t == other_type) +@@ -5372,12 +5386,9 @@ ipa_struct_reorg::record_function (cgraph_node *node) + function *fn; + tree parm, var; + unsigned int i; +- srfunction *sfn; ++ srfunction *sfn = NULL; + escape_type escapes = does_not_escape; + +- sfn = new srfunction (node); +- functions.safe_push (sfn); +- + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "\nRecording accesses and types from function: %s/%u\n", +@@ -5395,6 +5406,9 @@ ipa_struct_reorg::record_function (cgraph_node *node) + if (!fn) + return sfn; + ++ sfn = new srfunction (node); ++ functions.safe_push (sfn); ++ + current_function = sfn; + + if (DECL_PRESERVE_P (node->decl)) +@@ -8983,6 +8997,10 @@ ipa_struct_reorg::find_static_fc_fields (fc_type_info *info) + + for (auto *srf : info->type->fields) + { ++ /* Avoid compressing non-integer type. */ ++ if (TREE_CODE (srf->fieldtype) != INTEGER_TYPE) ++ continue; ++ + /* We have marked these fields as shadow, so skip them. */ + if (fc_fields_contains (info->static_fc_fields, srf->fielddecl)) + continue; +@@ -9034,6 +9052,11 @@ ipa_struct_reorg::find_shadow_fields (fc_type_info *info) + bool found_shadow = false; + for (auto *field_class : info->field_classes) + { ++ /* Avoid shadowing non-integer type, we can try to do this ++ in the future. */ ++ if (TREE_CODE (field_class->fieldtype) != INTEGER_TYPE) ++ continue; ++ + /* Field shadowing requires two or more fields. */ + if (field_class->size () < 2) + continue; +diff --git a/gcc/testsuite/gcc.dg/struct/sfc-shadow_non_integer.c b/gcc/testsuite/gcc.dg/struct/sfc-shadow_non_integer.c +new file mode 100644 +index 000000000..44769a2a1 +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/struct/sfc-shadow_non_integer.c +@@ -0,0 +1,25 @@ ++/* { dg-do compile } */ ++ ++#include ++#include ++ ++struct arc { ++ double a; ++ double b; ++}; ++typedef struct arc arc_t; ++ ++#define MAX 16 ++ ++int main() { ++ arc_t* arcs = (arc_t*)calloc(MAX, sizeof(arc_t)); ++ for (int i = 0; i < MAX; i++) { ++ arcs[i].a = i; ++ arcs[i].b = i; ++ } ++ printf("%f, %f\n", arcs[10].a, arcs[10].b); ++ ++ return 0; ++} ++ ++/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Fail finding static fc fields" "struct_reorg" } } */ +diff --git a/gcc/testsuite/gcc.dg/struct/sfc_non_integer.c b/gcc/testsuite/gcc.dg/struct/sfc_non_integer.c +new file mode 100644 +index 000000000..e76e30e70 +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/struct/sfc_non_integer.c +@@ -0,0 +1,29 @@ ++/* { dg-do compile } */ ++ ++#include ++#include ++ ++struct arc { ++ double a; ++ float b; ++}; ++typedef struct arc arc_t; ++ ++#define MAX 16 ++ ++int main() { ++ arc_t* arcs = (arc_t*)calloc(MAX, sizeof(arc_t)); ++ for (int i = 0; i < MAX; i++) { ++ arcs[i].b = 2; ++ arcs[i].b = 1.0; ++ } ++ ++ for (int i = 0; i < MAX; i++) { ++ if (arcs[i].a < arcs[i].b) ++ abort (); ++ } ++ ++ return 0; ++} ++ ++/* { dg-final { scan-ipa-dump "\\\[field compress\\\] Fail finding static fc fields" "struct_reorg" } } */ +-- +2.33.0 + diff --git a/gcc.spec b/gcc.spec index 48b37b4..0c22371 100644 --- a/gcc.spec +++ b/gcc.spec @@ -2,7 +2,7 @@ %global gcc_major 12 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 71 +%global gcc_release 72 %global _unpackaged_files_terminate_build 0 %global _performance_build 1 @@ -460,6 +460,7 @@ Patch351: 0351-GCC13-GCC12-Fix-testcase.patch Patch352: 0352-Add-hip10c-machine-discription.patch Patch353: 0353-Add-hip10a-machine-discription.patch Patch354: 0354-Fix-for-hip11-and-hip10c-addrcost_table.patch +Patch355: 0355-Fix-errors-in-ipa-struct-sfc-IBMY84-IBN2JO-IBN42Q.patch # Part 1001-1999 %ifarch sw_64 @@ -1600,6 +1601,7 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch -P352 -p1 %patch -P353 -p1 %patch -P354 -p1 +%patch -P355 -p1 %ifarch sw_64 %patch -P1001 -p1 @@ -4227,6 +4229,12 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Sat Feb 22 2025 huzife <634763349@qq.com> - 12.3.1-72 +- Type:Bugfix +- ID:NA +- SUG:NA +- DESC:Fix errors in ipa-struct-sfc(issue: IBMY84, IBN2JO, IBN42Q) + * Wed Feb 19 2025 liyancheng <412998149@qq.com> - 12.3.1-71 - Type:Sync - ID:NA -- Gitee