220 35603 <1938158.E5InEKLV7f@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Rotational shift operator
Date: Wed, 29 Nov 2017 10:50:39 -0800
Lines: 55
Approved: news@gmane.org
Message-ID: <1938158.E5InEKLV7f@tjmaciei-mobl1>
References: <69593098-e2cc-487e-bd14-9001b27aa7c1@isocpp.org> <ovm0ce$vi3$1@blaine.gmane.org> <CAHSYqdaRr7wbFNriX9ZzJ1unOzEEBr-Yb+oe0KU4Mz0FNcc4PA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1511981455 10925 195.159.176.226 (29 Nov 2017 18:50:55 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 29 Nov 2017 18:50:55 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBB4D7TIAKGQEUTXBVAQ@isocpp.org Wed Nov 29 19:50:46 2017
Return-path: <std-proposals+bncBCB4TK757YBRBB4D7TIAKGQEUTXBVAQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f197.google.com ([209.85.220.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBB4D7TIAKGQEUTXBVAQ@isocpp.org>)
	id 1eK7RR-0001y4-2X
	for gclcip-std-proposals@m.gmane.org; Wed, 29 Nov 2017 19:50:41 +0100
Original-Received: by mail-qk0-f197.google.com with SMTP id w198sf2745819qka.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 29 Nov 2017 10:50:48 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1511981448; cv=pass;
        d=google.com; s=arc-20160816;
        b=eZAmdQ18prn5TF6qpAphm3sIBVk/1gwDZr3azqoOh47VLzTwmlLwBzUsc+UguiaO3A
         8F10luyqTjsdf7ywP2m57HrrxfdiIHDwx8IAVJ3UlLBVl4HH0b4LkarHuDuyMDwuHtLE
         DFdQczMk7BiNLWyFdr/GahmrubfrEzUNzN7fUcIkP2HJ2+0k/t0xlbjs0WJitLhW8w5B
         Kl4hU7qTrU/cbwwVx81EG6h2grtB+9UQGfY+OEH8u/81oD+itoK/2etVwtx+pvIMDDc4
         h75jR6rCOSW2cbUnDA1pT5FHRBthhDB1zxLUM0DUVGF5VRSUc9tvR3wAArK8TUw+3OZN
         Yztw==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=bqCHunVG9kMvOTOmBcIxcKNKFvOLvad+uQWpmZzLAMA=;
        b=DRmBHdbZJ3tqsqu9Jx9dFCAdeT/HN8xC0rgFTApPuHKZ8NFY/vg+RZHlWIggqNt/QH
         nMhcWdg8XJJPcasWzAX/kqfLwUoEt6ijdal/47kOkSkyi9OPLHkCt/D4ZlHobvo3ngZ4
         fg+yZtxnCXcqPSjQlTaQUPJ95jSD1xno1X7dy3BXMMfjA6zxEtqFBA2u4/IBQXqmVrrL
         FHp7TWOX7T5pspQlTUc4snMNs+3FNsadl6xy3XL+YyITiacSgHCGQaA5qP2grvlzu/D0
         yMIB+IqsKR2h9P7oGpqI6yAsDfmwLXbO9wTTL+MA3T++OqF+fVEPu2TTy4kIXj+E6fc8
         Cz4w==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2001:19f0:5:2221::1:3 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=bqCHunVG9kMvOTOmBcIxcKNKFvOLvad+uQWpmZzLAMA=;
        b=p1O5lHj0HLAPKU74fNRWVG632uOXWITtPx/cExO4J8sINJHW9gO9qmsWeDK/ngxvA5
         cEpdc8BQgkxS81ucdu2gQRhdNwnGyJJMA2hhvczFpHw1VwgJu1RhIWw4a8QO2U8WWxOn
         xzerVUxcPZe3RHJWickBYHY7hw32xGv4BnAJ41B8td82NkRtS5TL94JHH1wf+Ih4gAk8
         a7dCCM0njSdTxAi27sn3mxCIGtgQUZHHo0zS/EmEeXxpv95r3LRZRkH2flkj4Fbi+o1S
         uSG1XiKFWoxn0DQvNChCCBzNttqZtWB+ZZUGqiCulhPFe7vgFWtgUgW8MHnbaE0q9nV/
         nykg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=bqCHunVG9kMvOTOmBcIxcKNKFvOLvad+uQWpmZzLAMA=;
        b=fxkbgVvhxp+cX/mOwzBy8H4cl/CPc1Q4ESZCVkugZugA2WjOnTj1QzTY9OE4abUuwC
         joWA1TYhC7jUrBowpBQg17cDFyElzwzpNx/hNgIeFlNrx0+hZ3LAEowc4Vcp0Y3Il2Lc
         W+XGiGTNUBiEC4hmR87yz1DuQAaEgI6H1KffVC1ND/auxghuX3REphUQA6W/zKYCJTxE
         +cqfGhy9MPbiNEZXDs+rfTPlgWkLllaZL+iu7BkdEgWsQAJ+ySrbn2cFbYfCh7L1NwEM
         BDy6Ln5mwLI/ZylLD8Dqk1u6LnjEM7reK4s4sTo6x+Vd/Wh16qzVfM8CqD/UfgFhbdvx
         LEpA==
X-Gm-Message-State: AJaThX7WGtt2cLn0vJWtxBUKPvwLEKp3O1PDT1pm9NiIbi94cmK5Havx
	5ShvYRSFIh78ftzLzyvmDUt47g==
X-Google-Smtp-Source: AGs4zMat3biW5JmXkHnLMAdhtv6+/mW6AF7Du8RJWfLkOBd1ZQQdFs4uCQ+y7sIOE3DLfYzSR/kDiQ==
X-Received: by 10.233.237.213 with SMTP id c204mr2561526qkg.7.1511981448246;
        Wed, 29 Nov 2017 10:50:48 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.200.3.34 with SMTP id q34ls10063289qtg.10.gmail; Wed, 29 Nov
 2017 10:50:47 -0800 (PST)
X-Received: by 10.55.74.144 with SMTP id x138mr5515918qka.239.1511981447165;
        Wed, 29 Nov 2017 10:50:47 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1511981447; cv=none;
        d=google.com; s=arc-20160816;
        b=sEantsvfMTGnjDbvAQQvToLmOpi5nvgDBTZWhOZCieWuqNehHHrIlO83nC0hRdcjrF
         xFfllWeTfRbn8vDmsK1JMb9i3ZCqg4nLgTO8l3Sowsk3uGtL2BPIngRCxRTLGP+D5zkf
         WP8hwI3u9K2Pc4N4g9wkJhgqJV6Y+XDnR4IwMFV+G4FhKIqLXaITksGiPgxOm6UuTQho
         JLgOgkeLUkxUcxz3pXUhlX2BDfZ5Hn4hCN+Ix3/s9mSt+R19o0FOVW5Bn9LL5BWsfdIg
         G/x/AnqLaG6Cb27H1YTQ6IC1fnhmIrTfIyx5CaDrNfdlFWiF8GACia9X3G2yfqHWUQgU
         pBQA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=Iz8Do8JFNiuQ1x6vXMhIK/VUlyoVljoLOtb9/fe7y0g=;
        b=y28NMqa2fYtiDoX033x9w0qNNRxb+J9AHnsw7jO6fXClCajLvOAkbs2ViiXeuRegL8
         MzK+z/wTeCSYUCDvLaUMFuIRJQz85fJErYJqnwVnXDfg0mJBC/afweHgrvMm7+Ors+EB
         UyBQooRNRq3d+vZyj7QMxBfE6E8oGGxfd9O1XW6D5CP80JvBkr4xHsEjVSNzCkPyAD6N
         NQFcuL7O88qPr/jM3zx0NHWRiTurTHK7WxE03InqkWk1m/Gzmww880oIC9q4TUZxNCX4
         NvzbxVulZrCa0wH55J+FINjF/7giCFwD1RX85FSK9KpOjYxZtpWfd5ngRWDtrKmal2/f
         PTMg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2001:19f0:5:2221::1:3 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from smtp.macieira.info (smtp.macieira.info. [2001:19f0:5:2221::1:3])
        by mx.google.com with ESMTPS id x3si2379686qtf.197.2017.11.29.10.50.46
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 29 Nov 2017 10:50:47 -0800 (PST)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 2001:19f0:5:2221::1:3 as permitted sender) client-ip=2001:19f0:5:2221::1:3;
Original-Received: from tjmaciei-mobl1.localnet (jfdmzpr04-ext.jf.intel.com [134.134.139.73])
	by smtp.macieira.info (Postfix) with ESMTPSA id 4A4F12DA6
	for <std-proposals@isocpp.org>; Wed, 29 Nov 2017 10:50:46 -0800 (PST)
In-Reply-To: <CAHSYqdaRr7wbFNriX9ZzJ1unOzEEBr-Yb+oe0KU4Mz0FNcc4PA@mail.gmail.com>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 2001:19f0:5:2221::1:3 as permitted
 sender) smtp.mailfrom=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:35603
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35603>

On Wednesday, 29 November 2017 09:43:20 PST Hyman Rosen wrote:
> A.  If the platform always causes a trap when indirecting through a null
> pointer,
> the check can be eliminated.

That's the case. Therefore, the check can be eliminated.

The special case of the Linux kernel was that on some MCU, under some special 
circumstance, the zero page *was* mapped and therefore didn't trap. So the GCC 
developers added a special flag to allow that particular case to work. 

In other words, this is *exactly* what you're asking for.

> Notice your own contradictory claims - you first say that the compiler
> should
> assume that programmers know what they are doing, then you say that
> compilers
> should eliminate code that those programmers have written.

The compiler should assume programmers know what they are doing, which means 
programmers don't write UB code. Since they don't, the compiler is allowed to 
discard any UB from the list of possibilities.

The example from Qt was more or less like this:

	if (d->size + newitems > d->alloc)
		realloc(d->size + newitems);

However, due to constant propagation through the inlining, it knows that
	d->alloc = d->size
and it knows newitems is a constant value (1).

So it reduced the expression to:

	if (d->size + 1 > d->size)

Since signed integer overflow is UB, the compiler is allowed to assume I've 
written proper code to ensure that d->size + 1 will not overflow (I have), in 
which case the comparison is a success.

I agree that if the compiler cannot tell things apart, it should leave the 
comparison alone. But it *could* tell things apart. So it should optimise the 
comparison and not leave a useless compare-and-branch which will never be 
true.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1938158.E5InEKLV7f%40tjmaciei-mobl1.

.
