1 Star 0 Fork 101

杨晨光 / gcc

forked from src-openEuler / gcc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0047-DFE-Fix-the-bug-caused-by-inconsistent-types.patch 9.78 KB
一键复制 编辑 原始数据 按行查看 历史
From 8f51c8c83355cb1b69553e582fb512c6e37b71f5 Mon Sep 17 00:00:00 2001
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
Date: Thu, 18 Aug 2022 17:15:08 +0800
Subject: [PATCH] [DFE] Fix the bug caused by inconsistent types: 1. Update
some functions to fix the bug caused by inconsistent base and node types.
Also we added 3 dejaGNU test cases.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 57 ++++++++-----
.../gcc.dg/struct/dfe_extr_board_init.c | 77 +++++++++++++++++
gcc/testsuite/gcc.dg/struct/dfe_extr_claw.c | 77 +++++++++++++++++
.../gcc.dg/struct/dfe_extr_mv_udc_core.c | 82 +++++++++++++++++++
4 files changed, 273 insertions(+), 20 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/struct/dfe_extr_board_init.c
create mode 100644 gcc/testsuite/gcc.dg/struct/dfe_extr_claw.c
create mode 100644 gcc/testsuite/gcc.dg/struct/dfe_extr_mv_udc_core.c
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 00dc4bf1d..8d3da3540 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -3284,33 +3284,31 @@ ipa_struct_reorg::find_vars (gimple *stmt)
}
}
-/* Update field_access in srfield. */
-
-static void
-update_field_access (tree node, tree op, unsigned access, void *data)
+static HOST_WIDE_INT
+get_offset (tree op, HOST_WIDE_INT offset)
{
- HOST_WIDE_INT offset = 0;
switch (TREE_CODE (op))
{
case COMPONENT_REF:
{
- offset = int_byte_position (TREE_OPERAND (op, 1));
- break;
+ return int_byte_position (TREE_OPERAND (op, 1));
}
case MEM_REF:
{
- offset = tree_to_uhwi (TREE_OPERAND (op, 1));
- break;
+ return tree_to_uhwi (TREE_OPERAND (op, 1));
}
default:
- return;
+ return offset;
}
- tree base = node;
- get_base (base, node);
- srdecl *this_srdecl = ((ipa_struct_reorg *)data)->find_decl (base);
- if (this_srdecl == NULL)
- return;
- srtype *this_srtype = this_srdecl->type;
+ return offset;
+}
+
+/* Record field access. */
+static void
+record_field_access (tree type, HOST_WIDE_INT offset,
+ unsigned access, void *data)
+{
+ srtype *this_srtype = ((ipa_struct_reorg *)data)->find_type (type);
if (this_srtype == NULL)
return;
srfield *this_srfield = this_srtype->find_field (offset);
@@ -3321,12 +3319,33 @@ update_field_access (tree node, tree op, unsigned access, void *data)
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "record field access %d:", access);
- print_generic_expr (dump_file, this_srtype->type);
+ print_generic_expr (dump_file, type);
fprintf (dump_file, " field:");
print_generic_expr (dump_file, this_srfield->fielddecl);
fprintf (dump_file, "\n");
}
return;
+
+}
+
+/* Update field_access in srfield. */
+
+static void
+update_field_access (tree node, tree op, unsigned access, void *data)
+{
+ HOST_WIDE_INT offset = 0;
+ offset = get_offset (op, offset);
+ tree node_type = inner_type (TREE_TYPE (node));
+ record_field_access (node_type, offset, access, data);
+ tree base = node;
+ get_base (base, node);
+ tree base_type = inner_type (TREE_TYPE (base));
+ if (!types_compatible_p (base_type, node_type))
+ {
+ record_field_access (base_type, get_offset (node, offset),
+ access, data);
+ }
+ return;
}
/* A callback for walk_stmt_load_store_ops to visit store. */
@@ -3373,8 +3392,7 @@ ipa_struct_reorg::remove_dead_field_stmt (tree lhs)
return false;
if (f == NULL)
return false;
- if (f->newfield[0] == NULL
- && (f->field_access & WRITE_FIELD))
+ if (f->newfield[0] == NULL)
return true;
return false;
}
@@ -5927,7 +5945,6 @@ ipa_struct_reorg::rewrite_assign (gassign *stmt, gimple_stmt_iterator *gsi)
fprintf (dump_file, "To: \n");
print_gimple_stmt (dump_file, stmt, 0);
}
- return false;
}
if (gimple_clobber_p (stmt))
diff --git a/gcc/testsuite/gcc.dg/struct/dfe_extr_board_init.c b/gcc/testsuite/gcc.dg/struct/dfe_extr_board_init.c
new file mode 100644
index 000000000..4e52564b6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/dfe_extr_board_init.c
@@ -0,0 +1,77 @@
+/* { dg-do compile} */
+
+#define NULL ((void*)0)
+typedef unsigned long size_t;
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+typedef long scalar_t__;
+typedef int bool;
+#define false 0
+#define true 1
+
+typedef struct TYPE_5__ TYPE_2__;
+typedef struct TYPE_4__ TYPE_1__;
+
+struct TYPE_4__
+{
+ int Pin;
+ int Pull;
+ int Mode;
+ int Speed;
+};
+
+struct TYPE_5__
+{
+ int MEMRMP;
+};
+typedef TYPE_1__ GPIO_InitTypeDef;
+
+int BT_RST_PIN;
+int BT_RST_PORT;
+int CONN_POS10_PIN;
+int CONN_POS10_PORT;
+int GPIO_HIGH (int, int);
+int GPIO_MODE_INPUT;
+int GPIO_MODE_OUTPUT_PP;
+int GPIO_NOPULL;
+int GPIO_PULLUP;
+int GPIO_SPEED_FREQ_LOW;
+int HAL_GPIO_Init (int, TYPE_1__ *);
+scalar_t__ IS_GPIO_RESET (int, int);
+TYPE_2__ *SYSCFG;
+int __HAL_RCC_GPIOB_CLK_ENABLE ();
+int __HAL_RCC_GPIOC_CLK_ENABLE ();
+
+__attribute__((used)) static void
+LBF_DFU_If_Needed (void)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+ __HAL_RCC_GPIOC_CLK_ENABLE ();
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ GPIO_InitStruct.Pin = BT_RST_PIN;
+ HAL_GPIO_Init (BT_RST_PORT, &GPIO_InitStruct);
+
+ GPIO_HIGH (BT_RST_PORT, BT_RST_PIN);
+ __HAL_RCC_GPIOB_CLK_ENABLE ();
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Pin = CONN_POS10_PIN;
+ HAL_GPIO_Init (CONN_POS10_PORT, &GPIO_InitStruct);
+
+ if (IS_GPIO_RESET (CONN_POS10_PORT, CONN_POS10_PIN))
+ {
+ SYSCFG->MEMRMP = 0x00000001;
+ asm (
+ "LDR R0, =0x000000\n\t"
+ "LDR SP, [R0, #0]\n\t"
+ );
+ asm (
+ "LDR R0, [R0, #0]\n\t"
+ "BX R0\n\t"
+ );
+ }
+}
+
+/* { dg-final { scan-ipa-dump-times "Dead field elimination" 0 "struct_layout" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/dfe_extr_claw.c b/gcc/testsuite/gcc.dg/struct/dfe_extr_claw.c
new file mode 100644
index 000000000..894e9f460
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/dfe_extr_claw.c
@@ -0,0 +1,77 @@
+/* { dg-do compile} */
+
+#define NULL ((void*)0)
+typedef unsigned long size_t;
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+typedef long scalar_t__;
+typedef int bool;
+#define false 0
+#define true 1
+
+typedef struct TYPE_2__ TYPE_1__;
+
+struct net_device
+{
+ struct claw_privbk* ml_priv;
+};
+struct clawctl
+{
+ int linkid;
+};
+struct claw_privbk
+{
+ int system_validate_comp;
+ TYPE_1__* p_env;
+ int ctl_bk;
+};
+typedef int __u8;
+struct TYPE_2__
+{
+ scalar_t__ packing;
+ int api_type;
+};
+
+int CLAW_DBF_TEXT (int, int, char*);
+int CONNECTION_REQUEST;
+int HOST_APPL_NAME;
+scalar_t__ PACKING_ASK;
+scalar_t__ PACK_SEND;
+int WS_APPL_NAME_IP_NAME;
+int WS_APPL_NAME_PACKED;
+int claw_send_control (struct net_device*, int, int, int, int, int, int);
+int setup;
+
+__attribute__((used)) static int
+claw_snd_conn_req (struct net_device *dev, __u8 link)
+{
+ int rc;
+ struct claw_privbk *privptr = dev->ml_priv;
+ struct clawctl *p_ctl;
+ CLAW_DBF_TEXT (2, setup, "snd_conn");
+ rc = 1;
+ p_ctl = (struct clawctl *)&privptr->ctl_bk;
+ p_ctl->linkid = link;
+ if (privptr->system_validate_comp == 0x00)
+ {
+ return rc;
+ }
+ if (privptr->p_env->packing == PACKING_ASK)
+ {
+ rc = claw_send_control (dev, CONNECTION_REQUEST, 0, 0, 0,
+ WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
+ }
+ if (privptr->p_env->packing == PACK_SEND)
+ {
+ rc = claw_send_control (dev, CONNECTION_REQUEST, 0, 0, 0,
+ WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
+ }
+ if (privptr->p_env->packing == 0)
+ {
+ rc = claw_send_control (dev, CONNECTION_REQUEST, 0, 0, 0,
+ HOST_APPL_NAME, privptr->p_env->api_type);
+ }
+ return rc;
+}
+
+/* { dg-final { scan-ipa-dump-times "Dead field elimination" 1 "struct_layout" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/dfe_extr_mv_udc_core.c b/gcc/testsuite/gcc.dg/struct/dfe_extr_mv_udc_core.c
new file mode 100644
index 000000000..9801f87f1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/dfe_extr_mv_udc_core.c
@@ -0,0 +1,82 @@
+/* { dg-do compile} */
+
+#define NULL ((void*)0)
+typedef unsigned long size_t;
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+typedef long scalar_t__;
+typedef int bool;
+#define false 0
+#define true 1
+
+typedef struct TYPE_4__ TYPE_2__;
+typedef struct TYPE_3__ TYPE_1__;
+typedef int u32;
+
+struct mv_udc
+{
+ TYPE_2__ *op_regs;
+ TYPE_1__ *ep_dqh;
+ struct mv_ep *eps;
+};
+
+struct mv_ep
+{
+ TYPE_1__ *dqh;
+ struct mv_udc *udc;
+};
+
+struct TYPE_4__
+{
+ int *epctrlx;
+};
+
+struct TYPE_3__
+{
+ int max_packet_length;
+ int next_dtd_ptr;
+};
+
+int EP0_MAX_PKT_SIZE;
+int EPCTRL_RX_ENABLE;
+int EPCTRL_RX_EP_TYPE_SHIFT;
+int EPCTRL_TX_ENABLE;
+int EPCTRL_TX_EP_TYPE_SHIFT;
+int EP_QUEUE_HEAD_IOS;
+int EP_QUEUE_HEAD_MAX_PKT_LEN_POS;
+int EP_QUEUE_HEAD_NEXT_TERMINATE;
+int USB_ENDPOINT_XFER_CONTROL;
+int readl (int *);
+int writel (int, int *);
+
+__attribute__((used)) static void
+ep0_reset (struct mv_udc *udc)
+{
+ struct mv_ep *ep;
+ u32 epctrlx;
+ int i = 0;
+ for (i = 0; i < 2; i++)
+ {
+ ep = &udc->eps[i];
+ ep->udc = udc;
+ ep->dqh = &udc->ep_dqh[i];
+ ep->dqh->max_packet_length =
+ (EP0_MAX_PKT_SIZE << EP_QUEUE_HEAD_MAX_PKT_LEN_POS)
+ | EP_QUEUE_HEAD_IOS;
+ ep->dqh->next_dtd_ptr = EP_QUEUE_HEAD_NEXT_TERMINATE;
+ epctrlx = readl (&udc->op_regs->epctrlx[0]);
+ if (i)
+ {
+ epctrlx |= EPCTRL_TX_ENABLE
+ | (USB_ENDPOINT_XFER_CONTROL << EPCTRL_TX_EP_TYPE_SHIFT);
+ }
+ else
+ {
+ epctrlx |= EPCTRL_RX_ENABLE
+ | (USB_ENDPOINT_XFER_CONTROL << EPCTRL_RX_EP_TYPE_SHIFT);
+ }
+ writel (epctrlx, &udc->op_regs->epctrlx[0]);
+ }
+}
+
+/* { dg-final { scan-ipa-dump-times "Dead field elimination" 2 "struct_layout" } } */
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangchen_guang/gcc.git
git@gitee.com:yangchen_guang/gcc.git
yangchen_guang
gcc
gcc
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891