1 Star 0 Fork 139

misaka00251/gcc

forked from src-openEuler/gcc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0023-StructReorderFields-Add-pointer-offset-check.patch 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
eastb233 提交于 2021-09-14 11:33 . [Sync] Sync patch from openeuler/gcc
From 83a35da4910fc7d8f29ced3e0ff8adddeb537731 Mon Sep 17 00:00:00 2001
From: huangxiaoquan <huangxiaoquan1@huawei.com>
Date: Fri, 27 Aug 2021 14:53:18 +0800
Subject: [PATCH 23/24] [StructReorderFields] Add pointer offset check
The pointer offset check is added for the expr that is dereferenced
in the memory, and escapes struct pointer offset operations involving
field order.
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 85986ce5803..b0d4fe80797 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -3876,6 +3876,17 @@ ipa_struct_reorg::get_type_field (tree expr, tree &base, bool &indirect,
return false;
}
+ /* Escape the operation of fetching field with pointer offset such as:
+ *(&(t->right)) = malloc (0); -> MEM[(struct node * *)_1 + 8B] = malloc (0);
+ */
+ if (current_mode != NORMAL
+ && (TREE_CODE (expr) == MEM_REF) && (offset != 0))
+ {
+ gcc_assert (can_escape);
+ t->mark_escape (escape_non_multiply_size, NULL);
+ return false;
+ }
+
if (wholeaccess (expr, base, accesstype, t))
{
field = NULL;
diff --git a/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c b/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
index 190b9418275..2ae46fb3112 100644
--- a/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
+++ b/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
@@ -84,4 +84,4 @@ main ()
return cnt;
}
-/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "reorder_fields" } } */
\ No newline at end of file
+/* { dg-final { scan-ipa-dump "No structures to transform." "reorder_fields" } } */
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c b/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c
new file mode 100644
index 00000000000..317aafa5f72
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct node
+{
+ struct node *left, *right;
+ double a, b, c, d, e, f;
+}
+*a;
+int b, c;
+void
+CreateNode (struct node **p1)
+{
+ *p1 = calloc (10, sizeof (struct node));
+}
+
+int
+main ()
+{
+ a->left = 0;
+ struct node *t = a;
+ CreateNode (&t->right);
+
+ struct node p = *a;
+ b = 1;
+ if (p.left)
+ b = 0;
+ if (b)
+ printf (" Tree.\n");
+}
+
+/* { dg-final { scan-ipa-dump "No structures to transform." "reorder_fields" } } */
\ No newline at end of file
--
2.21.0.windows.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/misaka00251/gcc.git
git@gitee.com:misaka00251/gcc.git
misaka00251
gcc
gcc
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385