From patchwork Mon Mar 20 21:09:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 741192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vn7qt1Wfvz9s0m for ; Tue, 21 Mar 2017 08:09:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Z+PdMWd2"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=QKzLVbQB7lIZx50+LxofXUT0AFwka +FsSYgOigAXtmG84MLhBxG68iiC/Z2IKQdSawexu04jK0Wmxw4+FU2/iSMyde4Zd XgX6XPMzhHBSJhvkieek8pYxu0Uh8BhAQeIRKyc70e53c3lTNCuFkNUhrw5yeDdz w9jAxqHFszegIU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=EU6LaUTKjuWsfx16uMnT0FkkENs=; b=Z+P dMWd2zdde2GjRaRZTBxcXjoPyifCL89ypvdrm+1phMnrtXMeNI6OPlUbwTCvklDF qoedbMaus2HM1iMs8KOm/cT/HU+gm5EZ5C5A9kL6ViZyI3lM20mRXXr1cSWieCzX fCCLr99DVi+PhjtE3JbrW7RJH9zDmOkZB6UEPiNc= Received: (qmail 58061 invoked by alias); 20 Mar 2017 21:09:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 58042 invoked by uid 89); 20 Mar 2017 21:09:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*MI:20170320210925 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Mar 2017 21:09:30 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 680FF61D12; Mon, 20 Mar 2017 21:09:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 680FF61D12 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 680FF61D12 Received: from tucnak.zalov.cz (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70BFD177FC; Mon, 20 Mar 2017 21:09:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v2KL9Que010493; Mon, 20 Mar 2017 22:09:26 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v2KL9P3E010492; Mon, 20 Mar 2017 22:09:25 +0100 Date: Mon, 20 Mar 2017 22:09:25 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix ICE with ubsan instrumentation and EXCESS_PRECISION_EXPR (PR c/80097) Message-ID: <20170320210925.GN11094@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! The C fully folding code expects that EXCESS_PRECISION_EXPR is never the rhs of a COMPOUND_EXPR, instead it should wrap the whole COMPOUND_EXPR if needed. The following patch does that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-03-20 Jakub Jelinek PR c/80097 * c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around optional COMPOUND_EXPR with ubsan instrumentation. * gcc.dg/ubsan/pr80097.c: New test. Jakub --- gcc/c/c-typeck.c.jj 2017-03-16 17:18:24.000000000 +0100 +++ gcc/c/c-typeck.c 2017-03-20 08:59:37.515399725 +0100 @@ -11856,14 +11856,16 @@ build_binary_op (location_t location, en else if (TREE_CODE (ret) != INTEGER_CST && int_operands && !in_late_binary_op) ret = note_integer_operands (ret); - if (semantic_result_type) - ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); protected_set_expr_location (ret, location); if (instrument_expr != NULL) ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret), instrument_expr, ret); + if (semantic_result_type) + ret = build1_loc (location, EXCESS_PRECISION_EXPR, + semantic_result_type, ret); + return ret; } --- gcc/testsuite/gcc.dg/ubsan/pr80097.c.jj 2017-03-20 08:58:24.227483256 +0100 +++ gcc/testsuite/gcc.dg/ubsan/pr80097.c 2017-03-20 08:57:15.000000000 +0100 @@ -0,0 +1,10 @@ +/* PR c/80097 */ +/* { dg-do compile } */ +/* { dg-options "-std=c89 -fsanitize=float-divide-by-zero" } */ + +int +foo (double a) +{ + int b = (1 / a >= 1); + return b; +}