Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751890AbdF2HFq (ORCPT ); Thu, 29 Jun 2017 03:05:46 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:8400 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751612AbdF2HFl (ORCPT ); Thu, 29 Jun 2017 03:05:41 -0400 Message-ID: <5954A66D.0@huawei.com> Date: Thu, 29 Jun 2017 15:04:13 +0800 From: zhong jiang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Thomas Gleixner CC: Ingo Molnar , , , , , , , , Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative References: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> <20170621164036.4findvvz7jj4cvqo@gmail.com> <595331FE.3090700@huawei.com> <59545DD6.3030508@huawei.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.5954A681.0088,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: bc40e2ccfed27148a0ab083dbda6b773 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 854 Lines: 32 On 2017/6/29 14:33, Thomas Gleixner wrote: > On Thu, 29 Jun 2017, zhong jiang wrote: >> On 2017/6/29 6:13, Thomas Gleixner wrote: >>> That's simply wrong. If oparg is negative and the SHIFT bit is set then the >>> result is undefined today and there is no way that this can be used at >>> all. >>> >>> On x86: >>> >>> 1 << -1 = 0x80000000 >>> 1 << -2048 = 0x00000001 >>> 1 << -2047 = 0x00000002 >> but I test the cases in x86_64 all is zero. I wonder whether it is related to gcc or not >> >> zj.c:15:8: warning: left shift count is negative [-Wshift-count-negative] >> j = 1 << -2048; >> ^ >> [root@localhost zhongjiang]# ./zj >> j = 0 > Which is not a surprise because the compiler can detect it as the shift is > a constant. oparg is not so constant ... I get it. Thanks Thanks zhongjiang > Thanks, > > tglx > > . >