Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Entropy requires no maintenance. -- Markoff Chaney


devel / comp.std.c / Why is shifting too far undefined behvaior?

SubjectAuthor
* Why is shifting too far undefined behvaior?Philipp Klaus Krause
+* Re: Why is shifting too far undefined behvaior?Ike Naar
|`- Re: Why is shifting too far undefined behvaior?Richard Kettlewell
+* Re: Why is shifting too far undefined behvaior?Richard Damon
|`* Re: Why is shifting too far undefined behvaior?Vincent Lefevre
| `* Re: Why is shifting too far undefined behvaior?Keith Thompson
|  +* Re: Why is shifting too far undefined behvaior?James Kuyper
|  |+* Re: Why is shifting too far undefined behvaior?Keith Thompson
|  ||`- Re: Why is shifting too far undefined behvaior?James Kuyper
|  |+* Re: Why is shifting too far undefined behvaior?Richard Damon
|  ||`* Re: Why is shifting too far undefined behvaior?James Kuyper
|  || `- Re: Why is shifting too far undefined behvaior?James Kuyper
|  |`* Re: Why is shifting too far undefined behvaior?Vincent Lefevre
|  | `- Re: Why is shifting too far undefined behvaior?James Kuyper
|  `- Re: Why is shifting too far undefined behvaior?Vincent Lefevre
+* Re: Why is shifting too far undefined behvaior?Keith Thompson
|`- Re: Why is shifting too far undefined behvaior?Philipp Klaus Krause
+- Re: Why is shifting too far undefined behvaior?Vincent Lefevre
+* Re: Why is shifting too far undefined behvaior?David Brown
|`- Re: Why is shifting too far undefined behvaior?Vincent Lefevre
`- Re: Why is shifting too far undefined behvaior?Tim Rentsch

1
Why is shifting too far undefined behvaior?

<siceh0$1lm$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=323&group=comp.std.c#323

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.std.c
Subject: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 13:09:20 +0200
Message-ID: <siceh0$1lm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 21 Sep 2021 11:09:20 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1718"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:v96OlM55B+dnpnXa7Gsv6lDYTCU=
X-User-ID: eJwFwQkBwDAIA0BLPAkUOYUV/xJ2Rw+NSQQDXC5SdredLYou+rNTc7XmAYWpOxCj5Z76TPUHGZsQpg==
Content-Language: en-US
X-Mozilla-News-Host: snews://news.solani.org:563
 by: Philipp Klaus Krause - Tue, 21 Sep 2021 11:09 UTC

Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
same forever), we see that there is undefined behavior, when "An
expression is shifted by a negative number or by an amount greater than
or equal to the width of the promoted expression (6.5.7)." or "An
expression having signed promoted type is left-shifted and either the
value of the expression is negative or the result of shifting would not
be representable in the promoted type (6.5.7)."

Does anyone know why this was made undefined (as opposed to yielding an
unspecified value)? The C99 rationale doesn't mention anything.

The only idea that comes to my mind is that it would be to allow
implementations to trap at runtime when shifting too far, which might
help with debugging.

Re: Why is shifting too far undefined behvaior?

<slrnskjgmp.3ce.ike@faeroes.freeshell.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=324&group=comp.std.c#324

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ike...@faeroes.freeshell.org (Ike Naar)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 11:33:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <slrnskjgmp.3ce.ike@faeroes.freeshell.org>
References: <siceh0$1lm$1@solani.org>
Injection-Date: Tue, 21 Sep 2021 11:33:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9dcc45fa42a1eb4f5fd60be0ccb897fe";
logging-data="9144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5DeLNnEToaoJGeNLTsU1/"
User-Agent: slrn/1.0.3 (Patched for libcanlock3) (NetBSD)
Cancel-Lock: sha1:VsRl49O0vBZVLew/XI4TTRdSy0U=
 by: Ike Naar - Tue, 21 Sep 2021 11:33 UTC

On 2021-09-21, Philipp Klaus Krause <pkk@spth.de> wrote:
> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
> same forever), we see that there is undefined behavior, when "An
> expression is shifted by a negative number or by an amount greater than
> or equal to the width of the promoted expression (6.5.7)." or "An
> expression having signed promoted type is left-shifted and either the
> value of the expression is negative or the result of shifting would not
> be representable in the promoted type (6.5.7)."
>
> Does anyone know why this was made undefined (as opposed to yielding an
> unspecified value)? The C99 rationale doesn't mention anything.
>
> The only idea that comes to my mind is that it would be to allow
> implementations to trap at runtime when shifting too far, which might
> help with debugging.

Another thing that comes to mind is that on a machine with N-bit
wordsize, the machine instruction for shifting might only use log2(N) bits
to specify the number of places to shift.
Shifting N places or more would not be possible on such hardware
(at least, not with a single shift instruction).

Re: Why is shifting too far undefined behvaior?

<877dfab16s.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=325&group=comp.std.c#325

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!nntp.terraraq.uk!.POSTED.nntp.terraraq.uk!not-for-mail
From: inva...@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 12:47:07 +0100
Organization: terraraq NNTP server
Message-ID: <877dfab16s.fsf@LkoBDZeT.terraraq.uk>
References: <siceh0$1lm$1@solani.org>
<slrnskjgmp.3ce.ike@faeroes.freeshell.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: mantic.terraraq.uk; posting-host="nntp.terraraq.uk:2a00:1098:0:86:1000:3f:0:2";
logging-data="548"; mail-complaints-to="usenet@mantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:9pfiDegztnysbrKo29/ixlm+nXo=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Tue, 21 Sep 2021 11:47 UTC

Ike Naar <ike@faeroes.freeshell.org> writes:
> On 2021-09-21, Philipp Klaus Krause <pkk@spth.de> wrote:
>> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
>> same forever), we see that there is undefined behavior, when "An
>> expression is shifted by a negative number or by an amount greater than
>> or equal to the width of the promoted expression (6.5.7)." or "An
>> expression having signed promoted type is left-shifted and either the
>> value of the expression is negative or the result of shifting would not
>> be representable in the promoted type (6.5.7)."
>>
>> Does anyone know why this was made undefined (as opposed to yielding an
>> unspecified value)? The C99 rationale doesn't mention anything.
>>
>> The only idea that comes to my mind is that it would be to allow
>> implementations to trap at runtime when shifting too far, which might
>> help with debugging.
>
> Another thing that comes to mind is that on a machine with N-bit
> wordsize, the machine instruction for shifting might only use log2(N) bits
> to specify the number of places to shift.

True for x86, for example.

> Shifting N places or more would not be possible on such hardware
> (at least, not with a single shift instruction).

That can explain why the standard doesn’t tie the behavior down exactly,
it doesn’t explain why it leaves it as UB rather than matching Philipp’s
suggestion, or making it implementation-defined behavior (so an x86
implementation would define it as equivalent to shifting mod word size,
for instance).

--
https://www.greenend.org.uk/rjk/

Re: Why is shifting too far undefined behvaior?

<sek2J.55967$jm6.46258@fx07.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=326&group=comp.std.c#326

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx07.iad.POSTED!not-for-mail
Subject: Re: Why is shifting too far undefined behvaior?
Newsgroups: comp.std.c
References: <siceh0$1lm$1@solani.org>
From: Rich...@Damon-Family.org (Richard Damon)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <siceh0$1lm$1@solani.org>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <sek2J.55967$jm6.46258@fx07.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 21 Sep 2021 08:29:11 -0400
X-Received-Bytes: 2337
 by: Richard Damon - Tue, 21 Sep 2021 12:29 UTC

On 9/21/21 7:09 AM, Philipp Klaus Krause wrote:
> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
> same forever), we see that there is undefined behavior, when "An
> expression is shifted by a negative number or by an amount greater than
> or equal to the width of the promoted expression (6.5.7)." or "An
> expression having signed promoted type is left-shifted and either the
> value of the expression is negative or the result of shifting would not
> be representable in the promoted type (6.5.7)."
>
> Does anyone know why this was made undefined (as opposed to yielding an
> unspecified value)? The C99 rationale doesn't mention anything.
>
> The only idea that comes to my mind is that it would be to allow
> implementations to trap at runtime when shifting too far, which might
> help with debugging.
>

My impression is that this behavior goes back to early versions of the
standardization process, and 'Unspecified Value' wasn't a term used
then, but that has evolved. There also may have been hardware that would
trap in this case.

The wording probably could be changed to something like an unspecified
value or a trap, but it may be the case that some implementation can
show that there is some significant optimization based on this undefined
behavior (maybe based on the knowledge that the shift value now
effectively has a limited range or no behavior is defined, so can be
igrored.)

Re: Why is shifting too far undefined behvaior?

<87tuidolj1.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=327&group=comp.std.c#327

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 11:01:38 -0700
Organization: None to speak of
Lines: 75
Message-ID: <87tuidolj1.fsf@nosuchdomain.example.com>
References: <siceh0$1lm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="bb72713767aed0d2b74b94bfa2480dba";
logging-data="15816"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BI4Jw8nfzB6MgyA4BJ1rI"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:NMkfJNX5k7WqPS8guaS1/XEn7Ow=
sha1:xMi+wBFNCtPfeYnPs1OBzIn2b7E=
 by: Keith Thompson - Tue, 21 Sep 2021 18:01 UTC

Philipp Klaus Krause <pkk@spth.de> writes:
> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
> same forever), we see that there is undefined behavior, when "An
> expression is shifted by a negative number or by an amount greater than
> or equal to the width of the promoted expression (6.5.7)." or "An
> expression having signed promoted type is left-shifted and either the
> value of the expression is negative or the result of shifting would not
> be representable in the promoted type (6.5.7)."
>
> Does anyone know why this was made undefined (as opposed to yielding an
> unspecified value)? The C99 rationale doesn't mention anything.
>
> The only idea that comes to my mind is that it would be to allow
> implementations to trap at runtime when shifting too far, which might
> help with debugging.

Dennis Ritchie wrote about this in comp.arch in 2002, but didn't
specifically explain why it's undefined behavior rather than an
unspecified value.

https://yarchive.net/comp/c_shifts.html

From: Dennis Ritchie <dmr@bell-labs.com>
Newsgroups: comp.arch
Subject: Re: shift instructions on different processors
Date: Tue, 12 Feb 2002 04:47:05 +0000
Message-ID: <3C689E49.65EB9FEB@bell-labs.com>

glen herrmannsfeldt wrote:
>
> There have been questions on both C and Java newsgroups about
> the effect of shift operations when the shift value equals or
> exceeds the number of bits available to be shifted.
>
> I know that the reason for such a restriction is that many architectures
> use only some bits of the shift amount.
>
> x86 uses the low 5 bits for 32 bit shifts, and low 6 bits for 64 bits.
>
> IBM S/360, S/370, S/390 etc., use the low 6 bits for 32 and 64 bits.
...

Meissner followed up with various other architectures as well.

I looked at my Interdata 8/32 manual (1975), which describes
a 32-bit machine, and was amused to find, under the
"Shift Left Logical" instruction,

"... the shift count is specified by the least significant
five bits of the second operand."

I added a contemporaneous hand-written notation "!!" to this.

On the next page, under "Shift Right Logical," it similarly
says, "the least significant five bits of the second operand."

Here my notation is an underlining, accompanied by "Shit!!"

And that, children, is why the C and Java rules are as they are.
The C manual in 6th Edition Unix didn't have the value restriction.
K&R I did.

Dennis

Perhaps it was thought that shifting too far is analagous to integer
overflow, which has undefined behavior for signed types. And Ritchie
may not have wanted to assume that no CPUs trap on a large shift.

K&R1 says "The result is undefined", not that it has undefined behavior
(I don't think K&R1 had the concept of undefined behavior).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why is shifting too far undefined behvaior?

<sid79l$d35$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=328&group=comp.std.c#328

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 20:12:05 +0200
Message-ID: <sid79l$d35$1@solani.org>
References: <siceh0$1lm$1@solani.org>
<87tuidolj1.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 21 Sep 2021 18:12:05 -0000 (UTC)
Injection-Info: solani.org;
logging-data="13413"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:trtXBLUNFrgeI8xrqpoy9VYadq8=
In-Reply-To: <87tuidolj1.fsf@nosuchdomain.example.com>
X-User-ID: eJwFwYcRwEAIA7CVaKaMwznP/iNEgqcmKxIZONx0TJyxryHYV6l0E33lbJhBPxcf2q4zhj8DLRBC
Content-Language: en-US
 by: Philipp Klaus Krause - Tue, 21 Sep 2021 18:12 UTC

Am 21.09.21 um 20:01 schrieb Keith Thompson:

>
> I looked at my Interdata 8/32 manual (1975), which describes
> a 32-bit machine, and was amused to find, under the
> "Shift Left Logical" instruction,
>
> "... the shift count is specified by the least significant
> five bits of the second operand."

The modern Z80N (a Z80 variant used in the ZX Spectrum Next) has a
"shift left arithmetic" that shifts 16-bit register de left by the
number specified in the lower 5 bits of 8-bit register b.

So in SDCC when targeting the Z80N, left-shifting a 16-bit value could,
depending on which register the shifted value gets allocated to, shift
either by the lower 5 bits of the right operand (is the Z80N instruction
is used) or the lower 8 bits of the right operand (if normal code for
Z80 left shift is generated) or by the actual right operand (if the
value of the right operand can be determined at compile time).

Re: Why is shifting too far undefined behvaior?

<20210922010837$1362@zira.vinc17.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=329&group=comp.std.c#329

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!4JUmjLgy+Wx+kwpjMvj36w.user.46.165.242.75.POSTED!not-for-mail
From: vincent-...@vinc17.net (Vincent Lefevre)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 01:13:04 -0000 (UTC)
Organization: a training zoo
Message-ID: <20210922010837$1362@zira.vinc17.org>
References: <siceh0$1lm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="50313"; posting-host="4JUmjLgy+Wx+kwpjMvj36w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.6.0-20210823 ("Coleburn") (Linux/5.10.0-8-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Vincent Lefevre - Wed, 22 Sep 2021 01:13 UTC

In article <siceh0$1lm$1@solani.org>,
Philipp Klaus Krause <pkk@spth.de> wrote:

> Does anyone know why this was made undefined (as opposed to yielding an
> unspecified value)? The C99 rationale doesn't mention anything.

> The only idea that comes to my mind is that it would be to allow
> implementations to trap at runtime when shifting too far, which might
> help with debugging.

Yes, and perhaps to allow optimization that could be invalidated with
an unspecified value (e.g. deduce the range of some values).

--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Re: Why is shifting too far undefined behvaior?

<20210922011447$3630@zira.vinc17.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=330&group=comp.std.c#330

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!4JUmjLgy+Wx+kwpjMvj36w.user.46.165.242.75.POSTED!not-for-mail
From: vincent-...@vinc17.net (Vincent Lefevre)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 01:17:06 -0000 (UTC)
Organization: a training zoo
Message-ID: <20210922011447$3630@zira.vinc17.org>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="52836"; posting-host="4JUmjLgy+Wx+kwpjMvj36w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.6.0-20210823 ("Coleburn") (Linux/5.10.0-8-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Vincent Lefevre - Wed, 22 Sep 2021 01:17 UTC

In article <sek2J.55967$jm6.46258@fx07.iad>,
Richard Damon <Richard@damon-family.org> wrote:

> The wording probably could be changed to something like an unspecified
> value or a trap,
[...]

Note: an unspecified value or a trap = an indeterminate value

--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Re: Why is shifting too far undefined behvaior?

<87zgs5mkk6.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=331&group=comp.std.c#331

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 19:05:29 -0700
Organization: None to speak of
Lines: 22
Message-ID: <87zgs5mkk6.fsf@nosuchdomain.example.com>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b5fd9637bf49c8f43a3bd672d60f3caf";
logging-data="31324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mdGvKTJahz+Apf/n1eKqn"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:cTcxfqI1brsgc/KB7yJHHRbO570=
sha1:BvIn9FJ/3qjqzqgJEjb2ILE2hfI=
 by: Keith Thompson - Wed, 22 Sep 2021 02:05 UTC

Vincent Lefevre <vincent-news@vinc17.net> writes:
> In article <sek2J.55967$jm6.46258@fx07.iad>,
> Richard Damon <Richard@damon-family.org> wrote:
>
>> The wording probably could be changed to something like an unspecified
>> value or a trap,
> [...]
>
> Note: an unspecified value or a trap = an indeterminate value

An indeterminate value is either an unspecified value or a trap
*representation". Richard didn't say "trap representation" (I won't
attempt to guess whether that's what he meant.)

A "trap" (not a term used by the standard) usually means that the
program terminates in some unfriendly way -- which might as well be
undefined behavior.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why is shifting too far undefined behvaior?

<sie9tb$5jg$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=332&group=comp.std.c#332

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 00:02:51 -0400
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <sie9tb$5jg$1@dont-email.me>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Sep 2021 04:02:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="05ba9792fa47d12269730c47a80ee580";
logging-data="5744"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JshEr3j4k9JMEYbuX9LLbs1TFkbDKUMc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:GeWqRxIxRvXzJvhQk0j9XHe/eGk=
In-Reply-To: <87zgs5mkk6.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: James Kuyper - Wed, 22 Sep 2021 04:02 UTC

On 9/21/21 10:05 PM, Keith Thompson wrote:
> Vincent Lefevre <vincent-news@vinc17.net> writes:
>> In article <sek2J.55967$jm6.46258@fx07.iad>,
>> Richard Damon <Richard@damon-family.org> wrote:
>>
>>> The wording probably could be changed to something like an unspecified
>>> value or a trap,
>> [...]
>>
>> Note: an unspecified value or a trap = an indeterminate value
>
> An indeterminate value is either an unspecified value or a trap
> *representation". Richard didn't say "trap representation" (I won't
> attempt to guess whether that's what he meant.)
>
> A "trap" (not a term used by the standard) usually means that the
> program terminates in some unfriendly way -- which might as well be
> undefined behavior.

True. But "perform a trap" is a term defined by the standard as meaning
"interrupt execution of the program such that no further operations are
performed". Per footnote 2, "fetching a trap representation might
perform a trap, but is not required to do so".
While I agree that "trap representation" is most likely what he meant,
"perform a trap" is an alternative possibility.

Re: Why is shifting too far undefined behvaior?

<87v92tmep4.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=333&group=comp.std.c#333

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Tue, 21 Sep 2021 21:12:07 -0700
Organization: None to speak of
Lines: 36
Message-ID: <87v92tmep4.fsf@nosuchdomain.example.com>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b5fd9637bf49c8f43a3bd672d60f3caf";
logging-data="8395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ua5DLnoaZ1KRgwv5gPzfO"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:mL916ulzsBSaRFqbt/x9XP89zUM=
sha1:OPRhbjuSE4PDVPdoCXirFQdJb20=
 by: Keith Thompson - Wed, 22 Sep 2021 04:12 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 9/21/21 10:05 PM, Keith Thompson wrote:
>> Vincent Lefevre <vincent-news@vinc17.net> writes:
>>> In article <sek2J.55967$jm6.46258@fx07.iad>,
>>> Richard Damon <Richard@damon-family.org> wrote:
>>>
>>>> The wording probably could be changed to something like an unspecified
>>>> value or a trap,
>>> [...]
>>>
>>> Note: an unspecified value or a trap = an indeterminate value
>>
>> An indeterminate value is either an unspecified value or a trap
>> *representation". Richard didn't say "trap representation" (I won't
>> attempt to guess whether that's what he meant.)
>>
>> A "trap" (not a term used by the standard) usually means that the
>> program terminates in some unfriendly way -- which might as well be
>> undefined behavior.
>
> True. But "perform a trap" is a term defined by the standard as meaning
> "interrupt execution of the program such that no further operations are
> performed". Per footnote 2, "fetching a trap representation might
> perform a trap, but is not required to do so".

You're right. That definition is N1570 3.19.4.

> While I agree that "trap representation" is most likely what he meant,
> "perform a trap" is an alternative possibility.

(BTW, you sent your reply to me by email as well as posting it here.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why is shifting too far undefined behvaior?

<09E2J.41394$ol1.7632@fx42.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=334&group=comp.std.c#334

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
Subject: Re: Why is shifting too far undefined behvaior?
Newsgroups: comp.std.c
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <sie9tb$5jg$1@dont-email.me>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 33
Message-ID: <09E2J.41394$ol1.7632@fx42.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Wed, 22 Sep 2021 07:08:44 -0400
X-Received-Bytes: 2434
 by: Richard Damon - Wed, 22 Sep 2021 11:08 UTC

On 9/22/21 12:02 AM, James Kuyper wrote:
> On 9/21/21 10:05 PM, Keith Thompson wrote:
>> Vincent Lefevre <vincent-news@vinc17.net> writes:
>>> In article <sek2J.55967$jm6.46258@fx07.iad>,
>>> Richard Damon <Richard@damon-family.org> wrote:
>>>
>>>> The wording probably could be changed to something like an unspecified
>>>> value or a trap,
>>> [...]
>>>
>>> Note: an unspecified value or a trap = an indeterminate value
>>
>> An indeterminate value is either an unspecified value or a trap
>> *representation". Richard didn't say "trap representation" (I won't
>> attempt to guess whether that's what he meant.)
>>
>> A "trap" (not a term used by the standard) usually means that the
>> program terminates in some unfriendly way -- which might as well be
>> undefined behavior.
>
> True. But "perform a trap" is a term defined by the standard as meaning
> "interrupt execution of the program such that no further operations are
> performed". Per footnote 2, "fetching a trap representation might
> perform a trap, but is not required to do so".
> While I agree that "trap representation" is most likely what he meant,
> "perform a trap" is an alternative possibility.
>

Yes, that was the 'trap' I was referring to. The Standard basically uses
perform a trap to mean a hardware based exception that the software may
or might not be able to intercept as a 'signal'.

Re: Why is shifting too far undefined behvaior?

<sif7c9$t46$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=335&group=comp.std.c#335

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 14:25:44 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <sif7c9$t46$1@dont-email.me>
References: <siceh0$1lm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Sep 2021 12:25:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b6fa22e719704be1e9c04105b864a3c5";
logging-data="29830"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jouYaSF3/USIM/rlJYqYQ7xVsd7WIKGE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:yh5nfMUWqdQLn39o4jBurkJZXRw=
In-Reply-To: <siceh0$1lm$1@solani.org>
Content-Language: en-GB
 by: David Brown - Wed, 22 Sep 2021 12:25 UTC

On 21/09/2021 13:09, Philipp Klaus Krause wrote:
> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the
> same forever), we see that there is undefined behavior, when "An
> expression is shifted by a negative number or by an amount greater than
> or equal to the width of the promoted expression (6.5.7)." or "An
> expression having signed promoted type is left-shifted and either the
> value of the expression is negative or the result of shifting would not
> be representable in the promoted type (6.5.7)."
>
> Does anyone know why this was made undefined (as opposed to yielding an
> unspecified value)? The C99 rationale doesn't mention anything.
>
> The only idea that comes to my mind is that it would be to allow
> implementations to trap at runtime when shifting too far, which might
> help with debugging.
>

One possibility for some of the cases is that a target could implement
"x <<= y" in hardware or software as :

while (y--) x <<= 1;

(Other shift operations would be similar.)

For at least some of the cases that are undefined behaviour in the spec,
if these were changed to implementation-defined or unspecified results
then you'd need extra checks to avoid almost-infinite loops.

For the signed integers, the expectation for arithmetic operations is
that the results will always be mathematically correct for integer
results. If you can't get the correct result, it is undefined
behaviour. This allows the compiler a great deal of freedom and
information that can be used for analysis and optimisation - such as
knowing that adding two positive numbers gives a positive result.

However, those are not good reasons for leaving (E1 << E2) undefined for
negative E1 in cases where E1 * 2 ^ E2 fits within the result type, or
for making (E1 >> E2) implementation defined for negative E1.

Re: Why is shifting too far undefined behvaior?

<sifbr8$rrk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=336&group=comp.std.c#336

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 09:42:00 -0400
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <sifbr8$rrk$1@dont-email.me>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
<87v92tmep4.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Sep 2021 13:42:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="05ba9792fa47d12269730c47a80ee580";
logging-data="28532"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lbjwyhdKU47ekd4fpszBQO1txBRnAd0I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:ReRIpR5jsf4x0YuAd+o80iEUWIs=
In-Reply-To: <87v92tmep4.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: James Kuyper - Wed, 22 Sep 2021 13:42 UTC

On 9/22/21 12:12 AM, Keith Thompson wrote:
....
> (BTW, you sent your reply to me by email as well as posting it here.)

Sorry - I'm still failing to adapt to the change in the meaning of
Thunderbird's "Reply" button.

For those who have no idea what I'm talking about - for a decade or
more, I've used Mozilla Thunderbird to post follow-up messages using the
"Reply" button. Several months ago they added a "Follow-Up" button to do
that, and changed the "Reply" button to send a message exclusively to
the e-mail of the person who posted the message. Even though the new
button naming makes more sense and is more consistent with the way
e-mails are handled, breaking a habit of two decades has proven very
difficult for me.

Re: Why is shifting too far undefined behvaior?

<sifbsj$rrk$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=337&group=comp.std.c#337

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Wed, 22 Sep 2021 09:42:43 -0400
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <sifbsj$rrk$2@dont-email.me>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
<09E2J.41394$ol1.7632@fx42.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Sep 2021 13:42:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="05ba9792fa47d12269730c47a80ee580";
logging-data="28532"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OrFt3fcFoeNuDtM4dQxxHfnDtavV2rUQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:HWLP88eqkgL6emrU/Fl27AXuypg=
In-Reply-To: <09E2J.41394$ol1.7632@fx42.iad>
Content-Language: en-US
 by: James Kuyper - Wed, 22 Sep 2021 13:42 UTC

On 9/22/21 7:08 AM, Richard Damon wrote:
> On 9/22/21 12:02 AM, James Kuyper wrote:
....
>> True. But "perform a trap" is a term defined by the standard as meaning
>> "interrupt execution of the program such that no further operations are
>> performed". Per footnote 2, "fetching a trap representation might
>> perform a trap, but is not required to do so".
>> While I agree that "trap representation" is most likely what he meant,
>> "perform a trap" is an alternative possibility.
>>
>
> Yes, that was the 'trap' I was referring to. The Standard basically uses
> perform a trap to mean a hardware based exception that the software may
> or might not be able to intercept as a 'signal'.

I don't think that raising a signal qualifies. The standard specifies
that "no further operations are performed". It doesn't add "unless the
signal is intercepted". I don't think that anything which allows
handlers registered using atexit(), abort_handler_s(),
ignore_handler_s(), or set_constraint_handler_s() to be executed
qualifies as performing a trap, either, since those would also allow
further operations to be performed.

Re: Why is shifting too far undefined behvaior?

<20210923110251$7a8c@zira.vinc17.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=338&group=comp.std.c#338

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!4JUmjLgy+Wx+kwpjMvj36w.user.46.165.242.75.POSTED!not-for-mail
From: vincent-...@vinc17.net (Vincent Lefevre)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Thu, 23 Sep 2021 11:08:05 -0000 (UTC)
Organization: a training zoo
Message-ID: <20210923110251$7a8c@zira.vinc17.org>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad> <20210922011447$3630@zira.vinc17.org> <87zgs5mkk6.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="53312"; posting-host="4JUmjLgy+Wx+kwpjMvj36w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.6.0-20210823 ("Coleburn") (Linux/5.14.0-1-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Vincent Lefevre - Thu, 23 Sep 2021 11:08 UTC

In article <87zgs5mkk6.fsf@nosuchdomain.example.com>,
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

> Vincent Lefevre <vincent-news@vinc17.net> writes:
> > In article <sek2J.55967$jm6.46258@fx07.iad>,
> > Richard Damon <Richard@damon-family.org> wrote:
> >
> >> The wording probably could be changed to something like an unspecified
> >> value or a trap,
> > [...]
> >
> > Note: an unspecified value or a trap = an indeterminate value

> An indeterminate value is either an unspecified value or a trap
> *representation". Richard didn't say "trap representation" (I won't
> attempt to guess whether that's what he meant.)

> A "trap" (not a term used by the standard) usually means that the
> program terminates in some unfriendly way -- which might as well be
> undefined behavior.

Yes, but a "trap" (where the word appears without "representation"
in the standard) is never used to mean a value, contrary to
"trap representation". Since this was applied to "indeterminate value",
I interpreted "trap" as "trap representation".

--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Re: Why is shifting too far undefined behvaior?

<20210923110856$6412@zira.vinc17.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=339&group=comp.std.c#339

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!4JUmjLgy+Wx+kwpjMvj36w.user.46.165.242.75.POSTED!not-for-mail
From: vincent-...@vinc17.net (Vincent Lefevre)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Thu, 23 Sep 2021 11:10:07 -0000 (UTC)
Organization: a training zoo
Message-ID: <20210923110856$6412@zira.vinc17.org>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad> <20210922011447$3630@zira.vinc17.org> <87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="53312"; posting-host="4JUmjLgy+Wx+kwpjMvj36w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.6.0-20210823 ("Coleburn") (Linux/5.14.0-1-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Vincent Lefevre - Thu, 23 Sep 2021 11:10 UTC

In article <sie9tb$5jg$1@dont-email.me>,
James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

> True. But "perform a trap" is a term defined by the standard as meaning
> "interrupt execution of the program such that no further operations are
> performed". Per footnote 2, "fetching a trap representation might
> perform a trap, but is not required to do so".
> While I agree that "trap representation" is most likely what he meant,
> "perform a trap" is an alternative possibility.

I wonder why it is defined, because it does not seem to be used at all
in the standard.

--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Re: Why is shifting too far undefined behvaior?

<20210923111215$08d3@zira.vinc17.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=340&group=comp.std.c#340

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!4JUmjLgy+Wx+kwpjMvj36w.user.46.165.242.75.POSTED!not-for-mail
From: vincent-...@vinc17.net (Vincent Lefevre)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Thu, 23 Sep 2021 11:17:53 -0000 (UTC)
Organization: a training zoo
Message-ID: <20210923111215$08d3@zira.vinc17.org>
References: <siceh0$1lm$1@solani.org> <sif7c9$t46$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61992"; posting-host="4JUmjLgy+Wx+kwpjMvj36w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.6.0-20210823 ("Coleburn") (Linux/5.14.0-1-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Vincent Lefevre - Thu, 23 Sep 2021 11:17 UTC

In article <sif7c9$t46$1@dont-email.me>,
David Brown <david.brown@hesbynett.no> wrote:

> However, those are not good reasons for leaving (E1 << E2) undefined for
> negative E1 in cases where E1 * 2 ^ E2 fits within the result type, or
> for making (E1 >> E2) implementation defined for negative E1.

Yes, and also for non-negative E1.

There was a "bug" in GNU MPFR (only affecting tools checking the
conformance, as in practice, this worked on all processors, AFAIK),
because while we ensured that E1 * 2 ^ E2 always fitted, E2 could
be equal to the type width (this can happen when E1 = 0), which is
currently disallowed by the standard.

--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Re: Why is shifting too far undefined behvaior?

<sii9cf$1bd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=341&group=comp.std.c#341

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Thu, 23 Sep 2021 12:18:22 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sii9cf$1bd$1@dont-email.me>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
<09E2J.41394$ol1.7632@fx42.iad> <sifbsj$rrk$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Sep 2021 16:18:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8a5312355291976619793de923e4c18f";
logging-data="1389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LQZ25qEdrvtPHgUX+9tdsS0XJxPtBu80="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:7C+6PmduwwWGI6BFOCBi3CLn9tM=
In-Reply-To: <sifbsj$rrk$2@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Thu, 23 Sep 2021 16:18 UTC

On 9/22/21 9:42 AM, James Kuyper wrote:
> On 9/22/21 7:08 AM, Richard Damon wrote:
>> On 9/22/21 12:02 AM, James Kuyper wrote:
> ...
>>> True. But "perform a trap" is a term defined by the standard as meaning
>>> "interrupt execution of the program such that no further operations are
>>> performed". Per footnote 2, "fetching a trap representation might
>>> perform a trap, but is not required to do so".
>>> While I agree that "trap representation" is most likely what he meant,
>>> "perform a trap" is an alternative possibility.
>>>
>>
>> Yes, that was the 'trap' I was referring to. The Standard basically uses
>> perform a trap to mean a hardware based exception that the software may
>> or might not be able to intercept as a 'signal'.
>
> I don't think that raising a signal qualifies. The standard specifies
> that "no further operations are performed". It doesn't add "unless the
> signal is intercepted". I don't think that anything which allows
> handlers registered using atexit(), abort_handler_s(),
> ignore_handler_s(), or set_constraint_handler_s() to be executed
> qualifies as performing a trap, either, since those would also allow
> further operations to be performed.
Correction - since the definition of "perform a trap" says explicitly
that "Implementations that support Annex L are permitted to invoke a
runtime-constraint handler when they perform a trap.", I should not have
included set_constraint_handler_s() in that list.

Re: Why is shifting too far undefined behvaior?

<sii9l1$39j$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=342&group=comp.std.c#342

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Thu, 23 Sep 2021 12:22:56 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <sii9l1$39j$1@dont-email.me>
References: <siceh0$1lm$1@solani.org> <sek2J.55967$jm6.46258@fx07.iad>
<20210922011447$3630@zira.vinc17.org>
<87zgs5mkk6.fsf@nosuchdomain.example.com> <sie9tb$5jg$1@dont-email.me>
<20210923110856$6412@zira.vinc17.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Sep 2021 16:22:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8a5312355291976619793de923e4c18f";
logging-data="3379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fuq6VMzwAjdnhrF0iUznt4tY0isX+fWg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:IM+kvqGg6n4voGqu8XVk5QA/DF0=
In-Reply-To: <20210923110856$6412@zira.vinc17.org>
Content-Language: en-US
 by: James Kuyper - Thu, 23 Sep 2021 16:22 UTC

On 9/23/21 7:10 AM, Vincent Lefevre wrote:
> In article <sie9tb$5jg$1@dont-email.me>,
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>
>> True. But "perform a trap" is a term defined by the standard as meaning
>> "interrupt execution of the program such that no further operations are
>> performed". Per footnote 2, "fetching a trap representation might
>> perform a trap, but is not required to do so".
>> While I agree that "trap representation" is most likely what he meant,
>> "perform a trap" is an alternative possibility.
>
> I wonder why it is defined, because it does not seem to be used at all
> in the standard.

Me too. It is used in notes in the descriptions of "bounded undefined
behavior" (L2.2) and "critical undefined behavior" (L2.3). However,
since performing a trap is clearly one of the things permitted for
undefined behavior, it's not clear that mentioning it in those contexts
makes any difference, particularly since notes are non-normative.

Re: Why is shifting too far undefined behvaior?

<87ee8uh1zi.fsf@shamko.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=365&group=comp.std.c#365

  copy link   Newsgroups: comp.std.c
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: txr...@shamko.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: Why is shifting too far undefined behvaior?
Date: Sat, 09 Oct 2021 04:27:45 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <87ee8uh1zi.fsf@shamko.com>
References: <siceh0$1lm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="e386cac8d3920670231b8e03b7881cbe";
logging-data="25602"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/i9EMQQ/lGFONrP6zEHZZZeEu2qeOj2rQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:OoDLik2hbx9wR+BKigrb9Tx2Ybo=
sha1:ieP0SZc44j0xKfhFGC66Bd45urw=
 by: Tim Rentsch - Sat, 9 Oct 2021 11:27 UTC

Philipp Klaus Krause <pkk@spth.de> writes:

> Looking at the C23 draft N2596, section J.2 (but this AFAIK has been
> the same forever), we see that there is undefined behavior, when "An
> expression is shifted by a negative number or by an amount greater
> than or equal to the width of the promoted expression (6.5.7)." or
> "An expression having signed promoted type is left-shifted and
> either the value of the expression is negative or the result of
> shifting would not be representable in the promoted type (6.5.7)."
>
> Does anyone know why this was made undefined (as opposed to yielding
> an unspecified value)?

This question tacitly assumes that there needs to be a reason.
To me it seems quite plausible that these cases were left as
undefined behavior simply because no one saw any reason to
define them. Not everything thinks that just because something
can be done that it should be done.

> The C99 rationale doesn't mention anything.

That observation supports the hypothesis that no one thought it
important to define the behavior in any way.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor