From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id CC364385BF86 for ; Sun, 29 Mar 2020 21:01:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC364385BF86 Received: by mail-io1-xd36.google.com with SMTP id k9so15633275iov.7 for ; Sun, 29 Mar 2020 14:01:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=Y7Xe3KHTsShECae0SkLymYmVIA2yXHFMAH/LYRm4LR4=; b=fdAQqDaDVWykFAgkOqjdCFQsJvXfRnaBW/AxIQAcfeV/3beeCZPFIdSskuavOIFbwC q0CBoJyPNy89mpoXmXu0Bt5X+VPgSy/ESeOsndn7fNrLW8au4kvY1WqyvPP5lYrCuf/1 lE+pUHtsVup12EwOMzpbTjN8rYAajI7MT/3SG+878/VhBlQrpwXr+N/3DfhpjKWUQAG3 0vOKl3gyUtz2EQU3yZfUYwuDlxXFu/ST3SZBP6D3DhdQFR/FZRli5HdsfjNcMcDshFPE rsty88hcTNnY9cEaajaP3Z1qphXj9Hoj5C4gn6obe878cepVGYVkrTesKAESCsnSA+Yo 0l0Q== X-Gm-Message-State: ANhLgQ2rIpnLsln5UN/WWiN9ksnKjYe0CGq9SZ3xj+MR0GFw0ktWbhPs 3YuK1XGGgTdGlYDEJ7bqb3P810313em0E1lN0ZhSocMRJXg= X-Google-Smtp-Source: ADFU+vvXp6Q+kYmUgoNEJl/yov5rIoddniWx/AJyMD7kEaOX13jT3gw7oC3dohiFBuYExLLUUTxM6fOcMGoUm9uZMp4= X-Received: by 2002:a5d:9ec7:: with SMTP id a7mr8072030ioe.66.1585515710283; Sun, 29 Mar 2020 14:01:50 -0700 (PDT) MIME-Version: 1.0 Reply-To: noloader@gmail.com From: Jeffrey Walton Date: Sun, 29 Mar 2020 17:01:39 -0400 Message-ID: Subject: GCC and division by 0 under sanitizers To: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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:01:53 -0000 Hi Everyone, I'm having trouble with floating point arithmetic and division by 0. Undefined behavior sanitizer flags a division by 0 is a runtime error. However, IEEE 754 says it is infinity if the operation does not trap. (Assuming I am looking at the right version of the standard). So to test IEEE floating point for division by 0: void test_floats(void) { ASSERT(INFINITY == 1.0f / 0.0f); ... } It seems like a reasonable test to me. However, we don't really want UBsan findings during testing either. I was looking at pragmas to disable UBsan division-by-zero in the source file, but I don't see one. Confer, https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html and https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html. Given users will CFLAGS="-fsanitize=undefined", what is the way to handle this in a way that avoids asking the user to do something? Asking the user to RTFM and use something like -fsanitize=all,no-divide-by-zero or -fsanitize-recover=float-divide-by-zero is not going to work. If RTFM was going to work, it would have happened in the last 50 years or so. So I want to engineer around the user. Jeff