From patchwork Thu Feb 13 17:57:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1237635 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-519491-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=bwOM7CWQ; 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=ReRpUY1P; 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 48JPNn4s3Dz9sPk for ; Fri, 14 Feb 2020 04:57:29 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=vak 2o78VAlqmccYofLUuuwDJ4HnqAUXH0gouFdnLsIdEk7Z0XD68iT8znr/fIlXVgid BLUqWzWVtLg+Y2vrPAYsS1am8Zh+dukvWQJD+hxIAJnVNMIuZ3oKVWYGYwbRXQx8 cNAd8B65r45ga/zK+lUBCu2OP40fYJ3cc6+Cr1cc= 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:content-transfer-encoding; s=default; bh=ARAk12weI zxlZfhuooDKe1tNu7g=; b=bwOM7CWQZMsm6FP8PUjdKFN+xPB0PBdCftRJubZ1d X6VIX0gpnsySWn5kQpF1Rez7JRc5onPXRG2F0UiSyikSCQBG1iX2UYUxGaIlnpAA 3aRy2xs02LgKTjULPKVwk2dUgXoYbX2rS3LS1rhvNJOxsXmywjYpnGVviK3tIuY+ 60= Received: (qmail 64944 invoked by alias); 13 Feb 2020 17:57:22 -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 64932 invoked by uid 89); 13 Feb 2020 17:57:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Languages-Length:2039, c_fully_fold, destructive X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Feb 2020 17:57:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581616639; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VAcTM1iQwm1SyDlbj/RuEYjeLr/tXHLAPZzP+0ChrJE=; b=ReRpUY1PZAidk+IjSlnZpkqKQkFko6ClN9Atxf7AhdIw6P1E1UtvVa0hu/SkbQkw+JSJl6 xj4jdqQPr92RQVg7SeUhV1e+8ymP4jV1utHiiWXtnHlJAwke9+F61dLyOpU9KJZzs/EwKr wo9HljG3hS9Rzpp6NaiogLbu7JAEqvA= 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-390-MLiM1HMiPlm0wHGfNLrFag-1; Thu, 13 Feb 2020 12:57:17 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6700E107ACC5; Thu, 13 Feb 2020 17:57:16 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 735B189E6F; Thu, 13 Feb 2020 17:57:12 +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 01DHvAw1028153; Thu, 13 Feb 2020 18:57:10 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 01DHv8WC028152; Thu, 13 Feb 2020 18:57:08 +0100 Date: Thu, 13 Feb 2020 18:57:08 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Fix ICE with cast to VLA [93576] Message-ID: <20200213175708.GJ17695@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-IsSubscribed: yes Hi! The following testcase ICEs, because the PR84305 changes try to evaluate the size earlier. If size has side-effects, that is desirable, and the side-effects will actually be wrapped in a SAVE_EXPR. The problem on this testcase is that there are no side-effects, and c_fully_fold doesn't fold those COMPOUND_EXPRs to constant, and while before gimplification we unshare trees found in the expressions, the unsharing doesn't involve TYPE_SIZE etc. of used types. Gimplification is destructive though, so when we gimplify the two nested COMPOUND_EXPRs and then try to gimplify it the second time for the TYPE_SIZEs, we ICE. Now, we could use unshare_expr in what we push to *expr, SAVE_EXPRs and their operands in there aren't unshared, but I really don't see a point of evaluating expressions that don't have side-effects before, so instead this just pushes there expressions that do have side-effects. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and release branches? 2020-02-13 Jakub Jelinek PR c/93576 * c-decl.c (grokdeclarator): If this_size_varies, only push size into *expr if it has side effects. * gcc.dg/pr93576.c: New test. Jakub --- gcc/c/c-decl.c.jj 2020-01-15 12:34:15.079253187 +0100 +++ gcc/c/c-decl.c 2020-02-13 13:49:06.427304070 +0100 @@ -6512,11 +6512,14 @@ grokdeclarator (const struct c_declarato } if (this_size_varies) { - if (*expr) - *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size), - *expr, size); - else - *expr = size; + if (TREE_SIDE_EFFECTS (size)) + { + if (*expr) + *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size), + *expr, size); + else + *expr = size; + } *expr_const_operands &= size_maybe_const; } } --- gcc/testsuite/gcc.dg/pr93576.c.jj 2020-02-13 13:53:06.089708612 +0100 +++ gcc/testsuite/gcc.dg/pr93576.c 2020-02-13 13:52:40.041099237 +0100 @@ -0,0 +1,10 @@ +/* PR c/93576 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void +foo (void) +{ + int b[] = { 0 }; + (char (*)[(1, 7, 2)]) 0; +}