diff mbox series

[ovs-dev] tc: Fix -Wgnu-variable-sized-type-not-at-end warning with Clang 18.

Message ID 20240426174454.221057-1-i.maximets@ovn.org
State Accepted
Commit 169ff9ea933f74854eab8d27457990a52706eec4
Headers show
Series [ovs-dev] tc: Fix -Wgnu-variable-sized-type-not-at-end warning with Clang 18. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/intel-ovs-compilation success test: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Ilya Maximets April 26, 2024, 5:44 p.m. UTC
Clang 18.1.3-2.fc41 throws a warning:

  lib/tc.c:3060:25: error: field 'sel' with variable sized type
            'struct tc_pedit_sel' not at the end of a struct or class is a
            GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]

   3060 |         struct tc_pedit sel;
        |                         ^

Refactor the structure into a proper union to avoid the build failure.

Interestingly, clang 18.1.3-2.fc41 on Fedora throws a warning, but
relatively the same version 18.1.3 (1) on Ubuntu 23.04 does not.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 lib/tc.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Comments

Ilya Maximets April 29, 2024, 9:15 a.m. UTC | #1
On 4/26/24 19:44, Ilya Maximets wrote:
> Clang 18.1.3-2.fc41 throws a warning:
> 
>   lib/tc.c:3060:25: error: field 'sel' with variable sized type
>             'struct tc_pedit_sel' not at the end of a struct or class is a
>             GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
> 
>    3060 |         struct tc_pedit sel;
>         |                         ^
> 
> Refactor the structure into a proper union to avoid the build failure.
> 
> Interestingly, clang 18.1.3-2.fc41 on Fedora throws a warning, but
> relatively the same version 18.1.3 (1) on Ubuntu 23.04 does not.
> 
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---

Recheck-request: github-robot

(Robot was down and didn't check the patch.  Same for a few other
patches on a list.)
Ales Musil April 30, 2024, 10:41 a.m. UTC | #2
On Fri, Apr 26, 2024 at 7:44 PM Ilya Maximets <i.maximets@ovn.org> wrote:

> Clang 18.1.3-2.fc41 throws a warning:
>
>   lib/tc.c:3060:25: error: field 'sel' with variable sized type
>             'struct tc_pedit_sel' not at the end of a struct or class is a
>             GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
>
>    3060 |         struct tc_pedit sel;
>         |                         ^
>
> Refactor the structure into a proper union to avoid the build failure.
>
> Interestingly, clang 18.1.3-2.fc41 on Fedora throws a warning, but
> relatively the same version 18.1.3 (1) on Ubuntu 23.04 does not.
>
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
>  lib/tc.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/lib/tc.c b/lib/tc.c
> index e9bcae4e4..e55ba3b1b 100644
> --- a/lib/tc.c
> +++ b/lib/tc.c
> @@ -3056,17 +3056,17 @@ nl_msg_put_flower_rewrite_pedits(struct ofpbuf
> *request,
>                                   struct tc_action *action,
>                                   uint32_t action_pc)
>  {
> -    struct {
> +    union {
>          struct tc_pedit sel;
> -        struct tc_pedit_key keys[MAX_PEDIT_OFFSETS];
> -        struct tc_pedit_key_ex keys_ex[MAX_PEDIT_OFFSETS];
> -    } sel = {
> -        .sel = {
> -            .nkeys = 0
> -        }
> -    };
> +        uint8_t buffer[sizeof(struct tc_pedit)
> +                       + MAX_PEDIT_OFFSETS * sizeof(struct tc_pedit_key)];
> +    } sel;
> +    struct tc_pedit_key_ex keys_ex[MAX_PEDIT_OFFSETS];
>      int i, j, err;
>
> +    memset(&sel, 0, sizeof sel);
> +    memset(keys_ex, 0, sizeof keys_ex);
> +
>      for (i = 0; i < ARRAY_SIZE(flower_pedit_map); i++) {
>          struct flower_key_to_pedit *m = &flower_pedit_map[i];
>          struct tc_pedit_key *pedit_key = NULL;
> @@ -3100,8 +3100,8 @@ nl_msg_put_flower_rewrite_pedits(struct ofpbuf
> *request,
>                  return EOPNOTSUPP;
>              }
>
> -            pedit_key = &sel.keys[sel.sel.nkeys];
> -            pedit_key_ex = &sel.keys_ex[sel.sel.nkeys];
> +            pedit_key = &sel.sel.keys[sel.sel.nkeys];
> +            pedit_key_ex = &keys_ex[sel.sel.nkeys];
>              pedit_key_ex->cmd = TCA_PEDIT_KEY_EX_CMD_SET;
>              pedit_key_ex->htype = m->htype;
>              pedit_key->off = cur_offset;
> @@ -3121,7 +3121,7 @@ nl_msg_put_flower_rewrite_pedits(struct ofpbuf
> *request,
>              }
>          }
>      }
> -    nl_msg_put_act_pedit(request, &sel.sel, sel.keys_ex,
> +    nl_msg_put_act_pedit(request, &sel.sel, keys_ex,
>                           flower->csum_update_flags ? TC_ACT_PIPE :
> action_pc);
>
>      return 0;
> --
> 2.44.0
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
>
Looks good to me, thanks.

Acked-by: Ales Musil <amusil@redhat.com>
Ilya Maximets April 30, 2024, 7:03 p.m. UTC | #3
On 4/30/24 12:41, Ales Musil wrote:
> 
> 
> On Fri, Apr 26, 2024 at 7:44 PM Ilya Maximets <i.maximets@ovn.org <mailto:i.maximets@ovn.org>> wrote:
> 
>     Clang 18.1.3-2.fc41 throws a warning:
> 
>       lib/tc.c:3060:25: error: field 'sel' with variable sized type
>                 'struct tc_pedit_sel' not at the end of a struct or class is a
>                 GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
> 
>        3060 |         struct tc_pedit sel;
>             |                         ^
> 
>     Refactor the structure into a proper union to avoid the build failure.
> 
>     Interestingly, clang 18.1.3-2.fc41 on Fedora throws a warning, but
>     relatively the same version 18.1.3 (1) on Ubuntu 23.04 does not.
> 
>     Signed-off-by: Ilya Maximets <i.maximets@ovn.org <mailto:i.maximets@ovn.org>>
>     ---
>
> Looks good to me, thanks.
> 
> Acked-by: Ales Musil <amusil@redhat.com <mailto:amusil@redhat.com>>


Thanks, Ales!  Applied to all branches down to 2.17.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/lib/tc.c b/lib/tc.c
index e9bcae4e4..e55ba3b1b 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -3056,17 +3056,17 @@  nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request,
                                  struct tc_action *action,
                                  uint32_t action_pc)
 {
-    struct {
+    union {
         struct tc_pedit sel;
-        struct tc_pedit_key keys[MAX_PEDIT_OFFSETS];
-        struct tc_pedit_key_ex keys_ex[MAX_PEDIT_OFFSETS];
-    } sel = {
-        .sel = {
-            .nkeys = 0
-        }
-    };
+        uint8_t buffer[sizeof(struct tc_pedit)
+                       + MAX_PEDIT_OFFSETS * sizeof(struct tc_pedit_key)];
+    } sel;
+    struct tc_pedit_key_ex keys_ex[MAX_PEDIT_OFFSETS];
     int i, j, err;
 
+    memset(&sel, 0, sizeof sel);
+    memset(keys_ex, 0, sizeof keys_ex);
+
     for (i = 0; i < ARRAY_SIZE(flower_pedit_map); i++) {
         struct flower_key_to_pedit *m = &flower_pedit_map[i];
         struct tc_pedit_key *pedit_key = NULL;
@@ -3100,8 +3100,8 @@  nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request,
                 return EOPNOTSUPP;
             }
 
-            pedit_key = &sel.keys[sel.sel.nkeys];
-            pedit_key_ex = &sel.keys_ex[sel.sel.nkeys];
+            pedit_key = &sel.sel.keys[sel.sel.nkeys];
+            pedit_key_ex = &keys_ex[sel.sel.nkeys];
             pedit_key_ex->cmd = TCA_PEDIT_KEY_EX_CMD_SET;
             pedit_key_ex->htype = m->htype;
             pedit_key->off = cur_offset;
@@ -3121,7 +3121,7 @@  nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request,
             }
         }
     }
-    nl_msg_put_act_pedit(request, &sel.sel, sel.keys_ex,
+    nl_msg_put_act_pedit(request, &sel.sel, keys_ex,
                          flower->csum_update_flags ? TC_ACT_PIPE : action_pc);
 
     return 0;