From patchwork Mon Mar 21 22:24:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1607949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m/HpnCB5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KMq2G6Rb7z9s1l for ; Tue, 22 Mar 2022 09:25:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA001385842E for ; Mon, 21 Mar 2022 22:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA001385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647901538; bh=tN5igtmOhVS2YGAjvj6bP/hhWSWk8n4Shv87ysLHNI0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=m/HpnCB51XcnJMBj6+/lvGBYqpxpQe97mcu/02sSHBFS4WO4AlXXLPDdJxZqGhvxA fmL6Lt4M7rOJt+Tttjw6to7QYAKhlJgEgoRZLY1sb/qxcLEICrPW8knOvz6skvfFjH /3dHf4KOhlZNGXw0IWmCFaB97AOvY5oXv4LRXJl4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AEC983858C51 for ; Mon, 21 Mar 2022 22:24:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AEC983858C51 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-6SrZG2SjPOixHpmLwz-Ltw-1; Mon, 21 Mar 2022 18:24:51 -0400 X-MC-Unique: 6SrZG2SjPOixHpmLwz-Ltw-1 Received: by mail-qv1-f69.google.com with SMTP id z1-20020ad44781000000b00440ded04b09so11229778qvy.22 for ; Mon, 21 Mar 2022 15:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tN5igtmOhVS2YGAjvj6bP/hhWSWk8n4Shv87ysLHNI0=; b=Xbx7pIGpU/yzigiTuR/NGmUFwYqIqgcGH1mX9AS/IYp3eF08v+ZUdh60GWPPzYFgwG /0jKkgsbIPCO2l1OoCN1ubFTkw9uSuKUbmBU9yS6BckzhFTP2Lba3Izps50BXdPSuF2r 75LiKiTNwmYlkba+zQc4sF5rbt1oejH8CykHtLF24M7yLamyIgYbHM0OufvsALYbgL09 lcDd8d5JcBJKaTuTQIEfKQTfEH/RdynPC9hlOCuKDls9wlRCqFABaTR5Gspb70P8JkHE i+Mo/RYR9G83TKNZyrVuUBYsfrIseN/wUqWiDZvFj9uKIGM2lHc4AujRli+5Ayh3BdY9 YlNA== X-Gm-Message-State: AOAM531C8GESelGH6i6gp+bGlmGuqZzyCefsAxX1u92ZulPRGLkIHn7S PXS24EKkTngrPpCThtqBA9LPbw7/HvLyxDZvrA5mjp4atShnrcVJD24kNWZ5ngzGsNg1H6Wq2gp vywSxw+q5eSn4HJrGG7ninuBh1cwmGKbepaY2KoHhUi6qQjKV5oxAKXMojtR5kbcWaQ== X-Received: by 2002:a05:620a:1a03:b0:67e:8b29:917e with SMTP id bk3-20020a05620a1a0300b0067e8b29917emr4557931qkb.679.1647901490132; Mon, 21 Mar 2022 15:24:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaY2ZfrVtVaextXzLdCjKvAwesNloNczzj7ymggJ3r+zXYPx/+wBbtie62LpAp5n8LHNExBQ== X-Received: by 2002:a05:620a:1a03:b0:67e:8b29:917e with SMTP id bk3-20020a05620a1a0300b0067e8b29917emr4557915qkb.679.1647901489640; Mon, 21 Mar 2022 15:24:49 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o206-20020a37a5d7000000b0067d42fd49c3sm8364498qke.4.2022.03.21.15.24.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:24:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: initialized array of vla [PR58646] Date: Mon, 21 Mar 2022 18:24:46 -0400 Message-Id: <20220321222446.2596733-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We went into build_vec_init because we're dealing with a VLA, but then build_vec_init thought it was safe to just build an INIT_EXPR because the outer dimension is constant. Nope. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * init.cc (build_vec_init): Check for vla element type. gcc/testsuite/ChangeLog: * g++.dg/ext/vla24.C: New. --- gcc/cp/init.cc | 1 + gcc/testsuite/g++.dg/ext/vla24.C | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/vla24.C base-commit: bec69ac548b0f37b41d07082d6ee52b52d356536 diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 7575597c8fd..08767679dd4 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4395,6 +4395,7 @@ build_vec_init (tree base, tree maxindex, tree init, if (init && TREE_CODE (atype) == ARRAY_TYPE && TREE_CONSTANT (maxindex) + && !vla_type_p (type) && (from_array == 2 ? vec_copy_assign_is_trivial (inner_elt_type, init) : !TYPE_NEEDS_CONSTRUCTING (type)) diff --git a/gcc/testsuite/g++.dg/ext/vla24.C b/gcc/testsuite/g++.dg/ext/vla24.C new file mode 100644 index 00000000000..0a99c003ffb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vla24.C @@ -0,0 +1,7 @@ +// PR c++/58646 +// { dg-additional-options -Wno-vla } + +void foo(int n) +{ + int a[2][n] = {}; +}