From patchwork Mon Feb 20 20:38:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 730195 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 3vRwSW3yKgz9s7R for ; Tue, 21 Feb 2017 07:38:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uwmosoZi"; 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=mJvO5GCZz1FT8+nB9W7mNQ5NYWI0G uGYMWGLoiY2MdbMItYoRn9zhU947qSlM42YABGixSA4QE2dQ0fXLYeZ175wNJrXG pMc2FfCdJz/XXQn8lTnOgN956fOmoNsD9UyWIXkc0LzzQSu2a/CvWFaz3iCvjK41 GqW2mg5dcT62P0= 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=dkztHUAKsP9EwfBkvrJcBarl90s=; b=uwm osoZibvZt6BZPSbif7lIfLZaflmPiBPwF7U0QkbOB15NzXCZYf2YlOsk5loVBSel SIjDbYedyNn3GFLXKcU7V4Yr9Z/ct87NEodEzu9kncIMX6cy9PHGqQn2xBzvWby0 Z13u+5Zq4ousM4ElciVwuykQj/x+NDlt/p9jlXFk= Received: (qmail 2457 invoked by alias); 20 Feb 2017 20:38:10 -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 2448 invoked by uid 89); 20 Feb 2017 20:38:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 Feb 2017 20:38:09 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45A6A80476 for ; Mon, 20 Feb 2017 20:38:09 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-76.ams2.redhat.com [10.36.117.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBDBA1CDD69; Mon, 20 Feb 2017 20:38:08 +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 v1KKc41x008009; Mon, 20 Feb 2017 21:38:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v1KKc4sT008008; Mon, 20 Feb 2017 21:38:04 +0100 Date: Mon, 20 Feb 2017 21:38:04 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with decomp gimplification (PR sanitizer/79589) Message-ID: <20170220203804.GG1849@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! When generic is unshared, we generally don't unshare DECL_VALUE_EXPRs, so those are assumed to be not shared, otherwise as in the testcase we can clear first argument of a COMPOUND_EXPR after it has been gimplified in one use and by that clobbering all others. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-02-20 Jakub Jelinek PR sanitizer/79589 * decl.c: Include gimplify.h. (cp_finish_decomp): Make sure there is no sharing of trees in between DECL_VALUE_EXPR of decomposition decls. * g++.dg/ubsan/pr79589.C: New test. Jakub --- gcc/cp/decl.c.jj 2017-02-17 18:29:21.000000000 +0100 +++ gcc/cp/decl.c 2017-02-20 11:45:55.281636544 +0100 @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. #include "plugin.h" #include "cilk.h" #include "builtins.h" +#include "gimplify.h" /* Possible cases of bad specifiers type used by bad_specifiers. */ enum bad_spec_place { @@ -7467,7 +7468,7 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); t = build4_loc (DECL_SOURCE_LOCATION (v[i]), ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE); @@ -7486,7 +7487,7 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); t = build1_loc (DECL_SOURCE_LOCATION (v[i]), i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t); @@ -7504,7 +7505,7 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]), &t, size_int (i)); t = build4_loc (DECL_SOURCE_LOCATION (v[i]), ARRAY_REF, @@ -7603,7 +7604,8 @@ cp_finish_decomp (tree decl, tree first, continue; else { - tree tt = finish_non_static_data_member (field, t, NULL_TREE); + tree tt = finish_non_static_data_member (field, unshare_expr (t), + NULL_TREE); if (REFERENCE_REF_P (tt)) tt = TREE_OPERAND (tt, 0); TREE_TYPE (v[i]) = TREE_TYPE (tt); --- gcc/testsuite/g++.dg/ubsan/pr79589.C.jj 2017-02-20 11:51:36.732130221 +0100 +++ gcc/testsuite/g++.dg/ubsan/pr79589.C 2017-02-20 11:52:09.012704729 +0100 @@ -0,0 +1,13 @@ +// PR sanitizer/79589 +// { dg-do compile } +// { dg-options "-fsanitize=undefined -std=c++1z" } + +struct A { char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } a[64]; + +void +foo () +{ + int z = 0; + for (auto & [ b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s ] : a) + z += b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s; +}