[v3] dom0-build: fix build with clang5
diff mbox series

Message ID 4d9bf13e-8f1b-4c9c-a4c4-5680a85dfbf0@suse.com
State New
Headers show
Series
  • [v3] dom0-build: fix build with clang5
Related show

Commit Message

Jan Beulich Jan. 23, 2020, 11:36 a.m. UTC
With non-empty CONFIG_DOM0_MEM clang5 produces

dom0_build.c:344:24: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand]
    if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
                       ^  ~~~~~~~~~~~~~~~~~~
dom0_build.c:344:24: note: use '&' for a bitwise operation
    if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
                       ^~
                       &
dom0_build.c:344:24: note: remove constant to silence this warning
    if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
                      ~^~~~~~~~~~~~~~~~~~~~~
1 error generated.

Obviously neither of the two suggestions are an option here. Oddly
enough swapping the operands of the && helps, while e.g. casting or
parenthesizing doesn't. Another workable variant looks to be the use of
!! on the constant.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien@xen.org>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
v3: Add comments.
v2: Also adjust the Arm incarnation of the same construct.
---
I'm open to going the !! or yet some different route (but not really the
suggested strlen() one). No matter which one we choose, I'm afraid it is
going to remain guesswork what newer (and future) versions of clang will
choke on.

Comments

Jan Beulich Feb. 5, 2020, 11 a.m. UTC | #1
On 23.01.2020 12:36, Jan Beulich wrote:
> With non-empty CONFIG_DOM0_MEM clang5 produces
> 
> dom0_build.c:344:24: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand]
>     if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
>                        ^  ~~~~~~~~~~~~~~~~~~
> dom0_build.c:344:24: note: use '&' for a bitwise operation
>     if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
>                        ^~
>                        &
> dom0_build.c:344:24: note: remove constant to silence this warning
>     if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
>                       ~^~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> 
> Obviously neither of the two suggestions are an option here. Oddly
> enough swapping the operands of the && helps, while e.g. casting or
> parenthesizing doesn't. Another workable variant looks to be the use of
> !! on the constant.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Acked-by: Julien Grall <julien@xen.org>
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Btw, rather than keeping the issue unfixed, I think I'll commit this
within the next couple of days, unless I hear an explicit objection
accompanied by an alternative suggestion better than the strlen()
one. Of course an ack by you would be much appreciated and even
better.

Jan

Patch
diff mbox series

--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2513,7 +2513,8 @@  int __init construct_dom0(struct domain
 
     printk("*** LOADING DOMAIN 0 ***\n");
 
-    if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
+    /* The ordering of operands is to work around a clang5 issue. */
+    if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set )
         parse_dom0_mem(CONFIG_DOM0_MEM);
 
     if ( dom0_mem <= 0 )
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -317,7 +317,8 @@  unsigned long __init dom0_compute_nr_pag
     unsigned long avail = 0, nr_pages, min_pages, max_pages;
     bool need_paging;
 
-    if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
+    /* The ordering of operands is to work around a clang5 issue. */
+    if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set )
         parse_dom0_mem(CONFIG_DOM0_MEM);
 
     for_each_node_mask ( node, dom0_nodes )