From patchwork Thu Feb 13 19:56:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1237704 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-519499-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=BBeLn9tU; 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=bT3rrEil; 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 48JS2910nmz9s29 for ; Fri, 14 Feb 2020 06:56:31 +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=yHWo5Xa/ABWgd5UV yeQR1k0NV7Inngh7aSYYn5FmV+gfA7tmA4twuB9gUc1FYmLgvlfEF7A+6f4i9FDy WvalgH8L6FakRv9CXm0KS6wm4L7kNIrbBtxEFVz9IeGPWMhuPnTRPXwHEGD4yxnn uFpM6SNCNFZemoU0AiesB0w/o70= 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=2fugQ+VtyJiE9i64L8q2JT jHTQU=; b=BBeLn9tUBXSf/tEeFNeIMphoAq97e59EHw1BSZ3gF0F56jPLLGi/HA UvTh75CTqZ3x1nlEglG6+t7Ck/9eFBM7mtRUAIDtPXljcUNMa0p8P4gkXw0wL5cT oPnyjIHeWF51e0ZtjSVawLiFFx06Z+xzbO0LwYyWv6ljjYebZ13YU= Received: (qmail 49621 invoked by alias); 13 Feb 2020 19:56:23 -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 49613 invoked by uid 89); 13 Feb 2020 19:56:22 -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, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=7460, 7467, 7458 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Feb 2020 19:56:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581623780; 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=NeOHaNEe/0GZpiU7rvvmU/xQTbwBist1K/fDs8sScXU=; b=bT3rrEilTqzO5ohBgUh5e0Wkwd2sw4WCW4wr08bwBLbyrKDez1i1q5i6PcOd8V8JBBJO86 MlqYn/dVO2NDrEasOw1r/5qZYLMji9/1Lpka/17n18n8/d+082QZpKRL3aZJNH98NuzI4I ZI4sWmsdsEpeeaw0C6oA0T5EKoJjTUQ= 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-271-67Znz1yXMXKoWKCToOvUVQ-1; Thu, 13 Feb 2020 14:56:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 039AD1005512 for ; Thu, 13 Feb 2020 19:56:17 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-124-216.rdu2.redhat.com [10.10.124.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CCDA790F7; Thu, 13 Feb 2020 19:56:16 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Fix ICE with ill-formed array list-initialization [PR93712] Date: Thu, 13 Feb 2020 14:56:00 -0500 Message-Id: <20200213195600.495394-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com My P0388R4 patch changed build_array_conv to create an identity conversion at the start of the conversion chain. That was a sound change but now we crash in convert_like_real 7457 case ck_identity: 7458 if (BRACE_ENCLOSED_INITIALIZER_P (expr)) 7459 { 7460 int nelts = CONSTRUCTOR_NELTS (expr); 7461 if (nelts == 0) 7462 expr = build_value_init (totype, complain); 7463 else if (nelts == 1) 7464 expr = CONSTRUCTOR_ELT (expr, 0)->value; 7465 else 7466 gcc_unreachable (); // HERE 7467 } in a test like this int f (int const (&)[2]) { return f({1, " "}); } I considered fixing this when performing overload resolution (clang says "no matching function for call to 'f'"), but then it occured to me that we crash in different contexts too, so I'm just turning the assert into an early return. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2020-02-13 Marek Polacek PR c++/93712 - ICE with ill-formed array list-initialization. * call.c (convert_like_real): Turn an assert into a return. * g++.dg/cpp0x/initlist-array11.C: New test. --- gcc/cp/call.c | 2 +- gcc/testsuite/g++.dg/cpp0x/initlist-array11.C | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array11.C base-commit: 1d69147af203d4dcd2270429f90c93f1a37ddfff diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 51621b7dd87..eba0ed8041d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7463,7 +7463,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, else if (nelts == 1) expr = CONSTRUCTOR_ELT (expr, 0)->value; else - gcc_unreachable (); + return error_mark_node; } expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p, /*read_p=*/true, UNKNOWN_LOCATION, diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C new file mode 100644 index 00000000000..7e76b588471 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C @@ -0,0 +1,10 @@ +// PR c++/93712 - ICE with ill-formed array list-initialization. +// { dg-do compile { target c++11 } } + +int f (const int (&)[2]); + +int g () +{ + const int (&r)[2] = {1, "foo"}; // { dg-error "invalid conversion" } + return f({1, "foo"}); // { dg-error "invalid conversion" } +}