Skip to contentSkip to conversation

hw/virtio: Fix brace Werror with clang 6.0.0

PATCH In review Richard Henderson 3 participants 5 messages May 12, 2018 – May 15, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hw/virtio: Fix brace Werror with clang 6.0.0

The warning is

hw/virtio/vhost-user.c:1319:26: error: suggest braces

      around initialization of subobject [-Werror,-Wmissing-braces]
    VhostUserMsg msg = { 0 };
                         ^
                         {}

While the original code is correct, and technically exactly correct as per ISO C89, both GCC and Clang support plain empty set of braces as an extension.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c +1 -1
index 38da8692bb..b455fca394 100644
@@ -1316,7 +1316,7 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev)
 
 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
 {
-    VhostUserMsg msg = { 0 };
+    VhostUserMsg msg = { };
 
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
 
Signature · 1 line
2.17.0
#1 lore raw

PATCH 2/2 target/s390x: Fix brace Werror with clang 6.0.0

The warning is

target/s390x/misc_helper.c:209:21: error: suggest

      braces around initialization of subobject [-Werror,-Wmissing-braces]
    SysIB sysib = { 0 };
                    ^
                    {}

While the original code is correct, and technically exactly correct as per ISO C89, both GCC and Clang support plain empty set of braces as an extension.

Cc Alexander Graf <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Cornelia Huck <[email protected]>
---
 target/s390x/misc_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/misc_helper.c +1 -1
index e0b23c1fd1..1f834f35ef 100644
@@ -206,7 +206,7 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
     const MachineState *ms = MACHINE(qdev_get_machine());
     uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     S390CPU *cpu = s390_env_get_cpu(env);
-    SysIB sysib = { 0 };
+    SysIB sysib = { };
     int i, cc = 0;
 
     if ((r0 & STSI_R0_FC_MASK) > STSI_R0_FC_LEVEL_3) {
Signature · 1 line
2.17.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] target/s390x: Fix brace Werror with clang 6.0.0

Quoted 8 lines · Richard Henderson

The warning is

target/s390x/misc_helper.c:209:21: error: suggest

      braces around initialization of subobject [-Werror,-Wmissing-braces]
    SysIB sysib = { 0 };
                    ^
                    {}
Quoted 8 lines

While the original code is correct, and technically exactly correct as per ISO C89, both GCC and Clang support plain empty set of braces as an extension.

Cc Alexander Graf <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Cornelia Huck <[email protected]>
Quoted 18 lines
---
 target/s390x/misc_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/misc_helper.c +1 -1
index e0b23c1fd1..1f834f35ef 100644
@@ -206,7 +206,7 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
     const MachineState *ms = MACHINE(qdev_get_machine());
     uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     S390CPU *cpu = s390_env_get_cpu(env);
-    SysIB sysib = { 0 };
+    SysIB sysib = { };
     int i, cc = 0;
 
     if ((r0 & STSI_R0_FC_MASK) > STSI_R0_FC_LEVEL_3) {
Reviewed-by on v1 1/2
#3 lore raw
In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

The warning is

hw/virtio/vhost-user.c:1319:26: error: suggest braces

      around initialization of subobject [-Werror,-Wmissing-braces]
    VhostUserMsg msg = { 0 };
                         ^
                         {}
Quoted 6 lines

While the original code is correct, and technically exactly correct as per ISO C89, both GCC and Clang support plain empty set of braces as an extension.

Cc Michael S. Tsirkin <[email protected]>
Quoted 18 lines
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c +1 -1
index 38da8692bb..b455fca394 100644
@@ -1316,7 +1316,7 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev)
 
 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
 {
-    VhostUserMsg msg = { 0 };
+    VhostUserMsg msg = { };
 
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
 
Reviewed-by on v1 1/2
#4 lore raw
In reply to Richard Henderson
Quoted 10 lines · Richard Henderson

The warning is

hw/virtio/vhost-user.c:1319:26: error: suggest braces

       around initialization of subobject [-Werror,-Wmissing-braces]
     VhostUserMsg msg = { 0 };
                          ^
                          {}

While the original code is correct, and technically exactly correct as per ISO C89, both GCC and Clang support plain empty set of braces

s/C89/C99/ (the guarantee of a universal {0} initializer was only added in C99, if I recall correctly)

Quoted 8 lines

as an extension.

Cc Michael S. Tsirkin <[email protected]>
---
  hw/virtio/vhost-user.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

It's annoying that we have to work around clang's bogus warning by resorting to an extension. But such is life.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org