8396 uts: vm_dep.h error: left shift of negative value

Review Request #585 — Created June 15, 2017 and submitted

tsoome
illumos-gate
8396
98c211c...
general
In file included from ../../common/vm/vm_pagelist.c:59:0:
../../common/vm/vm_pagelist.c: In function 'page_ctr_sub_internal':
../../i86pc/vm/vm_dep.h:70:36: error: left shift of negative value [-Werror=shift-negative-value]
  plcnt_inc_dec(pp, mtype, szc, -1l << PAGE_BSZS_SHIFT(szc), flags)
                                    ^
../../common/vm/vm_pagelist.c:879:2: note: in expansion of macro 'PLCNT_DECR'
  PLCNT_DECR(pp, mnode, mtype, pp->p_szc, flags);
  ^~~~~~~~~~
cc1: all warnings being treated as errors


  • 0
  • 0
  • 1
  • 0
  • 1
Description From Last Updated
rm
  1. 
      
  2. usr/src/uts/i86pc/vm/vm_dep.h (Diff revision 1)
     
     
    So the function takes a long as an argument. I suspect that the reason we're here is that the compiler doesn't want to shift the negative number and assume the two's complement layout necessarily or something similar.
    
    Should we be casting the result of the ULONG_MAX << ... to a long explicitly?
    1. seems like good idea.

  3. 
      
tsoome
rm
  1. Ship It!
  2. 
      
vgusev
  1. 
      
  2. usr/src/uts/i86pc/vm/vm_dep.h (Diff revision 2)
     
     
    What if use "-1UL" ?
    1. I do not see why we should - the -1 is used just because it is giving us 0xffffffff and ULONG_MAX does the same except we are not depending on how the negative numbers are represented. And the point there is not about using the negative number, but about getting value with all bits set. And as constant -1UL does not really make any sense IMO:)

    2. Right, I agree. We do not want to use values that are outside of the defined range of the type.
    3. I just wanted to propose the most short form. For your purpose can be used ~0UL as well. It looks short and easy.

    4. yes, the ~0UL would give us the same value, nevertheless, I think the named constant would be a bit more clear. As in general we rather use named constants anyhow. The value of using ~ is about that this operator is giving us ones complement of integer, but here we do specify the type explicitly anyhow. So as an author of this update, I would rather go with the named constant:)

  3. 
      
yuripv
  1. Ship It!
  2. 
      
vgusev
  1. Ship It!
  2. 
      
tsoome
Review request changed

Status: Closed (submitted)

Loading...