From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 7B7BB385B835 for ; Sun, 29 Mar 2020 21:43:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7B7BB385B835 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=segher@kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 02TLh3FQ029961; Sun, 29 Mar 2020 16:43:03 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 02TLh31w029960; Sun, 29 Mar 2020 16:43:03 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Sun, 29 Mar 2020 16:43:03 -0500 From: Segher Boessenkool To: noloader@gmail.com Cc: gcc-help Subject: Re: GCC and division by 0 under sanitizers Message-ID: <20200329214303.GO22482@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-47.5 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, TXREP, T_SPF_HELO_PERMERROR, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Mar 2020 21:43:05 -0000 On Sun, Mar 29, 2020 at 05:01:39PM -0400, Jeffrey Walton via Gcc-help wrote: > I'm having trouble with floating point arithmetic and division by 0. > Undefined behavior sanitizer flags a division by 0 is a runtime error. int f(int x) { return x / 0; } float g(float x) { return x / 0; } This actually warns during build for both functions: $ gcc -Wall -W -O2 -fsanitize=undefined dz.c dz.c: In function 'f': dz.c:1:25: warning: division by zero [-Wdiv-by-zero] 1 | int f(int x) { return x / 0; } | ^ dz.c: In function 'g': dz.c:2:29: warning: division by zero [-Wdiv-by-zero] 2 | float g(float x) { return x / 0; } | ^ but only f does anything with ubsan, as it should. (Please open a PR for the warning: '-Wno-div-by-zero' Do not warn about compile-time integer division by zero. Floating-point division by zero is not warned about, as it can be a legitimate way of obtaining infinities and NaNs. We clearly have a floating point division here.) What do you do to see ubsan misfire? Segher