lkml.org 
[lkml]   [2022]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] x86/cpu: fix undefined behavior in bit shift for intel_detect_tlb
On Mon, Oct 31, 2022 at 01:30:57PM +0100, Peter Zijlstra wrote:
> On Mon, Oct 31, 2022 at 07:43:40PM +0800, Gaosheng Cui wrote:
> > Shifting signed 32-bit value by 31 bits is undefined, so changing
> > significant bit to unsigned. The UBSAN warning calltrace like below:
> >
> > UBSAN: shift-out-of-bounds in arch/x86/kernel/cpu/intel.c:948:21
> > left shift of 1 by 31 places cannot be represented in type 'int'
>
> Is it really? Shouldn't -fstrict-overflow define this case?

-fno-strict-overflow that is, which implies -fwrapv which ensures 2s
complement, at which point shifting signed numbers is fully defined.

\
 
 \ /
  Last update: 2022-10-31 13:33    [W:0.098 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site