From patchwork Mon Mar 27 17:30:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 743919 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 3vsLfL2hcqz9s79 for ; Tue, 28 Mar 2017 04:31:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VhtccItN"; 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=gArbQGIJ3E3yQevXnqUGhcC3si9F1lD2Bn+MIWyaPTDJA6Y4cRyd0 /zVQ61pHt+IqNQj4DubF0pe6cSkEiVAfhcyHDy227ca+r2AqeeVpBRms1eXRiNH2 97IWrqES4D6ww8938THU+rrxUQGHPylfJWtGGmsm3CxkeRqXqaMejo= 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:subject:message-id:mime-version:content-type; s= default; bh=MM+pgBdKm++J3p1MeOCcZVN2TAc=; b=VhtccItNjlO8bEXjsdVO p+j4c0AZsVJtjRyurh900nmfdJ91PQMNydS9aHxJiTNfRP9perFR3lxrL2tDIZqd +vzG1chzjmgbM1dwRf739tOrbYEl+Z3/hc3BelDk1KeunZCm9e3ySmAs3DrRBDcJ rfjTyE98ceJdzNTLb0DqlpU= Received: (qmail 127843 invoked by alias); 27 Mar 2017 17:30:55 -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 127829 invoked by uid 89); 27 Mar 2017 17:30:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=647, tem, Hx-languages-length:1489 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, 27 Mar 2017 17:30:53 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3E6F33DBF7 for ; Mon, 27 Mar 2017 17:30:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3E6F33DBF7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3E6F33DBF7 Received: from redhat.com (ovpn-204-247.brq.redhat.com [10.40.204.247]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RHUolH019268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 27 Mar 2017 13:30:52 -0400 Date: Mon, 27 Mar 2017 19:30:50 +0200 From: Marek Polacek To: GCC Patches Subject: [PATCH] Fix ICE in fold_comparison with -fsanitize=shift (PR sanitizer/80067) Message-ID: <20170327173050.GJ3172@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) The code in fold_comparison calls save_expr on an expression and then tries to set a location of the expression. But since save_expr calls fold, it can produce an integer constant, so we must be more careful when setting its location. In this case we had (int) a > 646 where 'a' is signed char so we fold it to 0. Bootstrapped/regtested on x86_64-linux, ok for trunk/6? 2017-03-27 Marek Polacek PR sanitizer/80067 * fold-const.c (fold_comparison): Use protected_set_expr_location instead of SET_EXPR_LOCATION. * c-c++-common/ubsan/shift-10.c: New test. Marek diff --git gcc/fold-const.c gcc/fold-const.c index 1a9a264..6db16b5 100644 --- gcc/fold-const.c +++ gcc/fold-const.c @@ -8704,7 +8704,7 @@ fold_comparison (location_t loc, enum tree_code code, tree type, if (save_p) { tem = save_expr (build2 (code, type, cval1, cval2)); - SET_EXPR_LOCATION (tem, loc); + protected_set_expr_location (tem, loc); return tem; } return fold_build2_loc (loc, code, type, cval1, cval2); diff --git gcc/testsuite/c-c++-common/ubsan/shift-10.c gcc/testsuite/c-c++-common/ubsan/shift-10.c index e69de29..9202fcc 100644 --- gcc/testsuite/c-c++-common/ubsan/shift-10.c +++ gcc/testsuite/c-c++-common/ubsan/shift-10.c @@ -0,0 +1,10 @@ +/* PR sanitizer/80067 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift" } */ + +extern signed char a; +void +foo () +{ + 0 << ((647 > a) - 1); +}