From owner-freebsd-hackers@freebsd.org Thu Jan 14 11:44:48 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 CB1C24DEF50 for ; Thu, 14 Jan 2021 11:44:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4DGjCh2v4Hz3jrR for ; Thu, 14 Jan 2021 11:44:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 633664DF083; Thu, 14 Jan 2021 11:44:48 +0000 (UTC) Delivered-To: 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 6300D4DEF9F for ; Thu, 14 Jan 2021 11:44:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DGjCg41wTz3jYt; Thu, 14 Jan 2021 11:44:46 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 10EBiYhc095215 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 14 Jan 2021 13:44:37 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 10EBiYhc095215 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 10EBiYBY095214; Thu, 14 Jan 2021 13:44:34 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 14 Jan 2021 13:44:34 +0200 From: Konstantin Belousov To: Thierry Thomas Cc: FreeBSD Hackerz Subject: Re: Some fun with -O2 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4DGjCg41wTz3jYt X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] 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: Thu, 14 Jan 2021 11:44:48 -0000 On Thu, Jan 14, 2021 at 12:25:23PM +0100, Thierry Thomas wrote: > Let´s check a small C program, check_mktime.c, fetchable from > . > > $CC -o check_mktime -O2 check_mktime.c > ./check_mktime > > It is OK with clang90. > It loops forever with gcc9, gcc10, clang10 and clang11, > but OK without -O2. > > It is part of the configure script of ports/math/oleo, and I guess that > the same part could be found in other configure scripts. > > Note a similar program is part of glibc: see > . There is no fun with this stuff. The time_t type is signed, then the loop for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) continue; intent is to get signed overflow, which is UB. Modern compilers prefer to shoot into your foot instead of following common sense. Workaround is to add -fwrapv compiler switch.