From owner-freebsd-hackers@freebsd.org Fri Jan 15 22:26:39 2021 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8FB7D4F45AC for ; Fri, 15 Jan 2021 22:26:39 +0000 (UTC) (envelope-from "") Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DHbPp2qWzz3tvD for ; Fri, 15 Jan 2021 22:26:38 +0000 (UTC) (envelope-from "") Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 1E49616005C for ; Fri, 15 Jan 2021 23:26:35 +0100 (CET) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DHbPl1H9Vz9rxM; Fri, 15 Jan 2021 23:26:35 +0100 (CET) From: Walter von Entferndt To: Mark Millard Cc: freebsd-hackers@freebsd.org Subject: Re: Implicit assumptions (was: Re: Some fun with -O2) Date: Fri, 15 Jan 2021 23:25:25 +0100 Message-ID: <5358091.mMMZhaHaU6@t450s.local.lan> In-Reply-To: <4E90FC92-D255-4082-9F89-2BEE4D4C4E92@yahoo.com> References: <8830694.EFs4ROYVHJ@t450s.local.lan> <4E90FC92-D255-4082-9F89-2BEE4D4C4E92@yahoo.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart5430162.XOh7uYVVfo" Content-Transfer-Encoding: 7Bit X-Rspamd-Queue-Id: 4DHbPp2qWzz3tvD X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=posteo.net (policy=none); spf=none (mx1.freebsd.org: domain of mout01.posteo.de has no SPF policy when checking 185.67.36.141) smtp.helo=mout01.posteo.de X-Spamd-Result: default: False [-0.70 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; CTE_CASE(0.50)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/mixed,text/plain,text/x-patch]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; HAS_ATTACHMENT(0.00)[]; NEURAL_SPAM_SHORT(1.00)[1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_MED(-0.20)[185.67.36.141:from]; RCPT_COUNT_TWO(0.00)[2]; R_SPF_NA(0.00)[no SPF record]; FREEMAIL_TO(0.00)[yahoo.com]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:+]; ASN(0.00)[asn:8495, ipnet:185.67.36.0/23, country:DE]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers]; DMARC_POLICY_SOFTFAIL(0.10)[posteo.net : No valid SPF, No valid DKIM,none] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jan 2021 22:26:39 -0000 This is a multi-part message in MIME format. --nextPart5430162.XOh7uYVVfo Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" At Freitag, 15. Januar 2021, 21:57:14 CET, Mark Millard wrote: > The rationale vintage that I have a copy of is available at: > > http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf > Thank you very much. Now I found that "The result of shifting by a bit count greater than or equal to the word's size is undefined behavior in C and C++" (https://en.wikipedia.org/wiki/Bitwise_operation#C-family ; likewise http:// www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf). So we'll have to go back to the loop-solution with the multiply-by-2: --- check_mktime.c.patch --- --- check_mktime.c.orig 2021-01-15 03:19:33.962253000 +0100 +++ check_mktime.c 2021-01-15 23:22:01.951385000 +0100 @@ -3,6 +3,10 @@ # include # include # include +# include +# include /* printf() */ +# include /* format spec PRIX64: ll/l + X on 32/64-bit arch */ +# include /* CHAR_BIT */ /* Work around redefinition to rpl_putenv by other config tests. */ #undef putenv @@ -106,9 +110,15 @@ time_t t, delta; int i, j; - for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) - continue; - time_t_max--; + /* portably compute the maximum of a signed type: + * NOTE: << is undefined if the shift width >= word length + * i.e. shifting a 64-bit type by 62 on a 32-bit machine: undef + */ + for (i = t = 1; i < CHAR_BIT*sizeof t - 1; i++) + t *= 2; + time_t_max = t|(t - 1); + printf ("time_t_max = 0x%"PRIX64"\n", time_t_max); + delta = time_t_max / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) { -- =|o) "Stell' Dir vor es geht und keiner kriegt's hin." (Wolfgang Neuss) --nextPart5430162.XOh7uYVVfo Content-Disposition: attachment; filename="check_mktime.c.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="check_mktime.c.patch" --- check_mktime.c.orig 2021-01-15 03:19:33.962253000 +0100 +++ check_mktime.c 2021-01-15 23:22:01.951385000 +0100 @@ -3,6 +3,10 @@ # include # include # include +# include +# include /* printf() */ +# include /* format spec PRIX64: ll/l + X on 32/64-bit arch */ +# include /* CHAR_BIT */ /* Work around redefinition to rpl_putenv by other config tests. */ #undef putenv @@ -106,9 +110,15 @@ time_t t, delta; int i, j; - for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) - continue; - time_t_max--; + /* portably compute the maximum of a signed type: + * NOTE: << is undefined if the shift width >= word length + * i.e. shifting a 64-bit type by 62 on a 32-bit machine: undef + */ + for (i = t = 1; i < CHAR_BIT*sizeof t - 1; i++) + t *= 2; + time_t_max = t|(t - 1); + printf ("time_t_max = 0x%"PRIX64"\n", time_t_max); + delta = time_t_max / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) { --nextPart5430162.XOh7uYVVfo--