[dpdk-dev,v2,2/2] use simple zero initializers

Message ID 1429130956-17828-2-git-send-email-thomas.monjalon@6wind.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Thomas Monjalon April 15, 2015, 8:49 p.m. UTC
  To initialize a structure with zeros, one field was explicitly set
to avoid "missing initializer" bug with old GCC (e.g. 4.4).
This warning is now disabled (commit <insertlater>) for old versions of GCC,
so the workarounds may be removed.

These initializers should not be needed for static variables but they
are still used to workaround an ICC bug (see commit b2595c4aa92d).

There is one remaining exception where {0} initializer doesn't work cleanly,
even with recent GCC:
lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c:735:9:
error: missing braces around initializer [-Werror=missing-braces]
  struct rte_mbuf mb_def = {0}; /* zeroed mbuf */

Tested with GCC 4.4.7 (CentOS), 4.7.2 (Debian) and 4.9.2 (Arch).

Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
changes in v2:
- new patch

 app/test/test_ring_perf.c             | 2 +-
 lib/librte_pmd_e1000/em_ethdev.c      | 2 +-
 lib/librte_pmd_e1000/igb_ethdev.c     | 4 ++--
 lib/librte_pmd_e1000/igb_rxtx.c       | 6 ++----
 lib/librte_pmd_enic/enic_clsf.c       | 2 +-
 lib/librte_pmd_i40e/i40e_rxtx.c       | 2 +-
 lib/librte_pmd_ixgbe/ixgbe_rxtx.c     | 8 +++-----
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 3 +--
 lib/librte_pmd_mlx4/mlx4.c            | 2 +-
 9 files changed, 13 insertions(+), 18 deletions(-)
  

Comments

Olivier Matz April 16, 2015, 10:12 a.m. UTC | #1
Hi Thomas,

On 04/15/2015 10:49 PM, Thomas Monjalon wrote:
> To initialize a structure with zeros, one field was explicitly set
> to avoid "missing initializer" bug with old GCC (e.g. 4.4).
> This warning is now disabled (commit <insertlater>) for old versions of GCC,
> so the workarounds may be removed.
>
> These initializers should not be needed for static variables but they
> are still used to workaround an ICC bug (see commit b2595c4aa92d).
>
> There is one remaining exception where {0} initializer doesn't work cleanly,
> even with recent GCC:
> lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c:735:9:
> error: missing braces around initializer [-Werror=missing-braces]
>    struct rte_mbuf mb_def = {0}; /* zeroed mbuf */
>
> Tested with GCC 4.4.7 (CentOS), 4.7.2 (Debian) and 4.9.2 (Arch).
>
> Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>

I'm trying to compile the head of dpdk (without this patch applied),
and I have this error with clang:

     ixgbe_rxtx.c:2509:41: error: missing field 'driver_name' initializer
          [-Werror,-Wmissing-field-initializers]
             struct rte_eth_dev_info dev_info = { 0 };

I'm wondering if adding more {0} would compile on clang, at least with
the current clang flags.

$ clang --version
Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix


Regards,
Olivier
  
Thomas Monjalon April 16, 2015, 12:55 p.m. UTC | #2
2015-04-16 12:12, Olivier MATZ:
> On 04/15/2015 10:49 PM, Thomas Monjalon wrote:
> > To initialize a structure with zeros, one field was explicitly set
> > to avoid "missing initializer" bug with old GCC (e.g. 4.4).
> > This warning is now disabled (commit <insertlater>) for old versions of GCC,
> > so the workarounds may be removed.
> >
> > These initializers should not be needed for static variables but they
> > are still used to workaround an ICC bug (see commit b2595c4aa92d).
> >
> > There is one remaining exception where {0} initializer doesn't work cleanly,
> > even with recent GCC:
> > lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c:735:9:
> > error: missing braces around initializer [-Werror=missing-braces]
> >    struct rte_mbuf mb_def = {0}; /* zeroed mbuf */
> >
> > Tested with GCC 4.4.7 (CentOS), 4.7.2 (Debian) and 4.9.2 (Arch).
> >
> > Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
> 
> I'm trying to compile the head of dpdk (without this patch applied),
> and I have this error with clang:
> 
>      ixgbe_rxtx.c:2509:41: error: missing field 'driver_name' initializer
>           [-Werror,-Wmissing-field-initializers]
>              struct rte_eth_dev_info dev_info = { 0 };
> 
> I'm wondering if adding more {0} would compile on clang, at least with
> the current clang flags.

It's fixed by adding -Wno-missing-field-initializers to clang flags.

Someone to test with ICC?

Thanks
  
John McNamara April 16, 2015, 4:31 p.m. UTC | #3
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> Sent: Thursday, April 16, 2015 1:55 PM
> To: Olivier MATZ
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 2/2] use simple zero initializers


> > I'm wondering if adding more {0} would compile on clang, at least with
> > the current clang flags.
> 
> It's fixed by adding -Wno-missing-field-initializers to clang flags.
> 
> Someone to test with ICC?
> 
> Thanks


Hi,

I applied patches 4318 and 4319 to the current head and they compile with icc 13.1.1.

I also see the same compilation issues as Oliver with clang 3.3.

I'm not clear on the first statement, are you going to add the -Wno-missing-field-initializers flag for clang?

John
--
  

Patch

diff --git a/app/test/test_ring_perf.c b/app/test/test_ring_perf.c
index 44dda4d..8c47ccb 100644
--- a/app/test/test_ring_perf.c
+++ b/app/test/test_ring_perf.c
@@ -253,7 +253,7 @@  static void
 run_on_core_pair(struct lcore_pair *cores,
 		lcore_function_t f1, lcore_function_t f2)
 {
-	struct thread_params param1 = {.size = 0}, param2 = {.size = 0};
+	struct thread_params param1 = {0}, param2 = {0};
 	unsigned i;
 	for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
 		lcore_count = 0;
diff --git a/lib/librte_pmd_e1000/em_ethdev.c b/lib/librte_pmd_e1000/em_ethdev.c
index 12ecf5f..82e0b7a 100644
--- a/lib/librte_pmd_e1000/em_ethdev.c
+++ b/lib/librte_pmd_e1000/em_ethdev.c
@@ -130,7 +130,7 @@  static struct rte_pci_id pci_id_em_map[] = {
 #define RTE_PCI_DEV_ID_DECL_EM(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
 #include "rte_pci_dev_ids.h"
 
-{.device_id = 0},
+{0},
 };
 
 static const struct eth_dev_ops eth_em_ops = {
diff --git a/lib/librte_pmd_e1000/igb_ethdev.c b/lib/librte_pmd_e1000/igb_ethdev.c
index 1ea2d38..e2b7cf3 100644
--- a/lib/librte_pmd_e1000/igb_ethdev.c
+++ b/lib/librte_pmd_e1000/igb_ethdev.c
@@ -221,7 +221,7 @@  static struct rte_pci_id pci_id_igb_map[] = {
 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
 #include "rte_pci_dev_ids.h"
 
-{.device_id = 0},
+{0},
 };
 
 /*
@@ -232,7 +232,7 @@  static struct rte_pci_id pci_id_igbvf_map[] = {
 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
 #include "rte_pci_dev_ids.h"
 
-{.device_id = 0},
+{0},
 };
 
 static const struct eth_dev_ops eth_igb_ops = {
diff --git a/lib/librte_pmd_e1000/igb_rxtx.c b/lib/librte_pmd_e1000/igb_rxtx.c
index 946b39d..084e45a 100644
--- a/lib/librte_pmd_e1000/igb_rxtx.c
+++ b/lib/librte_pmd_e1000/igb_rxtx.c
@@ -1164,8 +1164,7 @@  igb_reset_tx_queue_stat(struct igb_tx_queue *txq)
 static void
 igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
 {
-	static const union e1000_adv_tx_desc zeroed_desc = { .read = {
-			.buffer_addr = 0}};
+	static const union e1000_adv_tx_desc zeroed_desc = {{0}};
 	struct igb_tx_entry *txe = txq->sw_ring;
 	uint16_t i, prev;
 	struct e1000_hw *hw;
@@ -1330,8 +1329,7 @@  eth_igb_rx_queue_release(void *rxq)
 static void
 igb_reset_rx_queue(struct igb_rx_queue *rxq)
 {
-	static const union e1000_adv_rx_desc zeroed_desc = { .read = {
-			.pkt_addr = 0}};
+	static const union e1000_adv_rx_desc zeroed_desc = {{0}};
 	unsigned i;
 
 	/* Zero out HW ring memory */
diff --git a/lib/librte_pmd_enic/enic_clsf.c b/lib/librte_pmd_enic/enic_clsf.c
index b61d625..a069194 100644
--- a/lib/librte_pmd_enic/enic_clsf.c
+++ b/lib/librte_pmd_enic/enic_clsf.c
@@ -96,7 +96,7 @@  int enic_fdir_add_fltr(struct enic *enic, struct rte_fdir_filter *params,
 	u16 queue, u8 drop)
 {
 	struct enic_fdir_node *key;
-	struct filter fltr = {.type = 0};
+	struct filter fltr = {0};
 	int32_t pos;
 	u8 do_free = 0;
 	u16 old_fltr_id = 0;
diff --git a/lib/librte_pmd_i40e/i40e_rxtx.c b/lib/librte_pmd_i40e/i40e_rxtx.c
index 9c7be6f..abe68f4 100644
--- a/lib/librte_pmd_i40e/i40e_rxtx.c
+++ b/lib/librte_pmd_i40e/i40e_rxtx.c
@@ -1228,7 +1228,7 @@  i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	uint16_t tx_last;
 	uint16_t slen;
 	uint64_t buf_dma_addr;
-	union i40e_tx_offload tx_offload = { .data = 0 };
+	union i40e_tx_offload tx_offload = {0};
 
 	txq = tx_queue;
 	sw_ring = txq->sw_ring;
diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c
index 6475c44..19286c9 100644
--- a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c
+++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c
@@ -579,7 +579,7 @@  ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 	uint64_t tx_ol_req;
 	uint32_t ctx = 0;
 	uint32_t new_ctx;
-	union ixgbe_tx_offload tx_offload = { .data = 0 };
+	union ixgbe_tx_offload tx_offload = {0};
 
 	txq = tx_queue;
 	sw_ring = txq->sw_ring;
@@ -2052,8 +2052,7 @@  ixgbe_dev_tx_queue_release(void *txq)
 static void
 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
 {
-	static const union ixgbe_adv_tx_desc zeroed_desc = { .read = {
-			.buffer_addr = 0}};
+	static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
 	struct ixgbe_tx_entry *txe = txq->sw_ring;
 	uint16_t prev, i;
 
@@ -2445,8 +2444,7 @@  check_rx_burst_bulk_alloc_preconditions(__rte_unused struct ixgbe_rx_queue *rxq)
 static void
 ixgbe_reset_rx_queue(struct ixgbe_hw *hw, struct ixgbe_rx_queue *rxq)
 {
-	static const union ixgbe_adv_rx_desc zeroed_desc = { .read = {
-			.pkt_addr = 0}};
+	static const union ixgbe_adv_rx_desc zeroed_desc = {{0}};
 	unsigned i;
 	uint16_t len = rxq->nb_rx_desc;
 
diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
index 7ac6b61..abd10f6 100644
--- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
+++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
@@ -691,8 +691,7 @@  ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
 static void
 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
 {
-	static const union ixgbe_adv_tx_desc zeroed_desc = { .read = {
-			.buffer_addr = 0} };
+	static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
 	struct ixgbe_tx_entry_v *txe = (struct ixgbe_tx_entry_v *)txq->sw_ring;
 	uint16_t i;
 
diff --git a/lib/librte_pmd_mlx4/mlx4.c b/lib/librte_pmd_mlx4/mlx4.c
index e096071..024282a 100644
--- a/lib/librte_pmd_mlx4/mlx4.c
+++ b/lib/librte_pmd_mlx4/mlx4.c
@@ -3497,7 +3497,7 @@  static void
 mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
 	struct priv *priv = dev->data->dev_private;
-	struct rte_eth_stats tmp = { .ipackets = 0 };
+	struct rte_eth_stats tmp = {0};
 	unsigned int i;
 	unsigned int idx;