linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: zhong jiang <zhongjiang@huawei.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	akpm@linux-foundation.org, mingo@redhat.com, minchan@kernel.org,
	mhocko@suse.com, hpa@zytor.com, x86@kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative
Date: Thu, 29 Jun 2017 08:33:20 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1706290832140.1861@nanos> (raw)
In-Reply-To: <59545DD6.3030508@huawei.com>

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 ...

Thanks,

	tglx

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-06-29  6:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 11:43 zhong jiang
2017-06-21 16:40 ` Ingo Molnar
2017-06-28  4:35   ` zhong jiang
2017-06-28 21:43     ` hpa
2017-06-29  2:12       ` zhong jiang
2017-06-29  4:29         ` hpa
2017-06-29  5:57           ` zhong jiang
2017-06-28 22:13     ` Thomas Gleixner
2017-06-29  1:54       ` zhong jiang
2017-06-29  6:33         ` Thomas Gleixner [this message]
2017-06-29  7:04           ` zhong jiang
2017-08-25  5:21       ` zhong jiang
2017-08-25 21:13         ` Thomas Gleixner
2017-08-26  2:51           ` zhong jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1706290832140.1861@nanos \
    --to=tglx@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=x86@kernel.org \
    --cc=zhongjiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox