From patchwork Tue Feb 11 19:54:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1236449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519365-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=L9zTpRD4; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bjc0pJp1; dkim-atps=neutral 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 48HD674t5Mz9s3x for ; Wed, 12 Feb 2020 06:55:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=P0tFKBxgozd1opuq Rifutir2MeCArK4YGoh8EuwcKUxKFmRROboKprwZBD9D7AQDgvkgmqy7R4asj/x3 VPhmesBYwvJg9F0FVxWu54VeqxIyjJ/S+JMH5M213T9M7o83XDLsKWQMBG6Pz98P lZLjNa1xtrcnpx8KFnvRFgIhADk= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=fCbGsb5GrbepCVZ+soNgV2 2yhko=; b=L9zTpRD4aIaTiWbFP6LPoMZEk3AB6Ua69JarViTvFStycPGxS7Oj4r 6T0Vo84bh3BygVQRHJo7i7NHBh1geJS9fGCtEAi4bX0fADG3E6azJvDr3SY5GhTZ zyaYZx3eoYoyMxP3RrfYJR2rIR124oSHcoaIW9f2TMCxeUYD1sOsk= Received: (qmail 28687 invoked by alias); 11 Feb 2020 19:55:34 -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 28674 invoked by uid 89); 11 Feb 2020 19:55:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1907 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 19:55:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581450930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kZutOhZvSiaqtzuQrnGmdRD+hzF2D6lX2XNeY+gm7As=; b=bjc0pJp1O6kPxOZhT6kWS0vDlHvb263t4fvBt/Z43vUsZfpeOVfInrJGAHNaoJ5jIGECk9 pCZgKRJvUClkIvdghuw3tpm0mjh/22uY6s0Of9A2IL47J8cRJxM+Ov3bVlXoXPlA903fRh Khq6O5OYlXaZpUTsBBqs6VjYqX5b2dw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-NZxVBNzNO_6hZ59_ZWQFbg-1; Tue, 11 Feb 2020 14:55:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4619189F762 for ; Tue, 11 Feb 2020 19:55:08 +0000 (UTC) Received: from pdp-11.bss.redhat.com (unknown [10.20.4.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 370BF60BF1; Tue, 11 Feb 2020 19:55:08 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Fix value-init crash in template [PR93676] Date: Tue, 11 Feb 2020 14:54:59 -0500 Message-Id: <20200211195459.358172-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Since we attempt to value-initialize in build_vec_init even when there's no initializer but the type has a constexpr default constructor. But build_value_init doesn't work in templates, so I think let's avoid this scenario; we'll go to the normal build_aggr_init path then. Bootstrapped/regtested on x86_64-linux, ok for trunk and branches? PR c++/93676 - value-init crash in template. * init.c (build_vec_init): Don't perform value-init in a template. * g++.dg/cpp0x/nsdmi-template19.C: New test. --- gcc/cp/init.c | 2 +- gcc/testsuite/g++.dg/cpp0x/nsdmi-template19.C | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template19.C base-commit: 7a775242ea296849a34ce27de179eaaec411e880 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index d480660445e..c9c0f03c58b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -4520,7 +4520,7 @@ build_vec_init (tree base, tree maxindex, tree init, We do need to keep going if we're copying an array. */ - if (try_const && !init) + if (try_const && !init && !processing_template_decl) /* With a constexpr default constructor, which we checked for when setting try_const above, default-initialization is equivalent to value-initialization, and build_value_init gives us something more diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template19.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template19.C new file mode 100644 index 00000000000..f3e2cb87fd6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template19.C @@ -0,0 +1,13 @@ +// PR c++/93676 - value-init crash in template. +// { dg-do compile { target c++11 } } + +struct P { + int x = 0; +}; + +template +struct S { + S() { new P[2][2]; } +}; + +S s;