https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95818

            Bug ID: 95818
           Summary: wrong "used uninitialized" warning
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ferruh.yigit at intel dot com
  Target Milestone: ---

gcc (GCC) 11.0.0 20200621 (experimental)

Sorry, I couldn't able to reproduce with test code, I will copy-paste the real
code that causes the warning hoping it helps.

Warning [1] and code that causes it [2], struct in question [3].

As you can see all the fields of the struct has been set before used, so not
sure why giving used uninitialized warning.



[1]
.../drivers/net/iavf/iavf_ethdev.c: In function ‘iavf_dev_link_update’:
.../drivers/net/iavf/iavf_ethdev.c:641:6: error: ‘new_link’ is used
uninitialized [-Werror=uninitialized]
  641 |  if (rte_atomic64_cmpset((uint64_t *)&dev->data->dev_link,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  642 |     *(uint64_t *)&dev->data->dev_link,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  643 |     *(uint64_t *)&new_link) == 0)
      |     ~~~~~~~~~~~~~~~~~~~~~~~
.../drivers/net/iavf/iavf_ethdev.c:596:22: note: ‘new_link’ declared here
  596 |  struct rte_eth_link new_link;
      |                      ^~~~~~~~
cc1: all warnings being treated as error



[2]
iavf_dev_link_update(struct rte_eth_dev *dev,
                    __rte_unused int wait_to_complete)
{
        struct rte_eth_link new_link;
        struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);

        /* Only read status info stored in VF, and the info is updated
         *  when receive LINK_CHANGE evnet from PF by Virtchnnl.
         */
        switch (vf->link_speed) {
        case 10:
                new_link.link_speed = ETH_SPEED_NUM_10M;
                break;
        case 100:
                new_link.link_speed = ETH_SPEED_NUM_100M;
                break;
        case 1000:
                new_link.link_speed = ETH_SPEED_NUM_1G;
                break;
        case 10000:
                new_link.link_speed = ETH_SPEED_NUM_10G;
                break;
        case 20000:
                new_link.link_speed = ETH_SPEED_NUM_20G;
                break;
        case 25000:
                new_link.link_speed = ETH_SPEED_NUM_25G;
                break;
        case 40000:
                new_link.link_speed = ETH_SPEED_NUM_40G;
                break;
        case 50000:
                new_link.link_speed = ETH_SPEED_NUM_50G;
                break;
        case 100000:
                new_link.link_speed = ETH_SPEED_NUM_100G;
                break;
        default:
                new_link.link_speed = ETH_SPEED_NUM_NONE;
                break;
        }

        new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
        new_link.link_status = vf->link_up ? ETH_LINK_UP :
                                             ETH_LINK_DOWN;
        new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
                                ETH_LINK_SPEED_FIXED);

        if (rte_atomic64_cmpset((uint64_t *)&dev->data->dev_link,
                                *(uint64_t *)&dev->data->dev_link,
                                *(uint64_t *)&new_link) == 0)
                return -1;

        return 0;
}



[3]
struct rte_eth_link {
        uint32_t link_speed;        /**< ETH_SPEED_NUM_ */
        uint16_t link_duplex  : 1;  /**< ETH_LINK_[HALF/FULL]_DUPLEX */
        uint16_t link_autoneg : 1;  /**< ETH_LINK_[AUTONEG/FIXED] */
        uint16_t link_status  : 1;  /**< ETH_LINK_[DOWN/UP] */
} __rte_aligned(8);      /**< aligned for atomic64 read/write */

Reply via email to