From patchwork Tue Nov 5 07:39:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1189378 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-512399-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.b="TjrGuoof"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YjTDwvY4"; 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 476hQN6zbQz9sNT for ; Tue, 5 Nov 2019 18:39:56 +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=LmX sLBA2/KTek1z1fRVfR142PEMHOtX7sA/PhBYKa5heiTkvYjwpzVxLTcfyeS8w9Lz F0xVY3LjgPK7yJCCI0e9hokUHl02MgaUNz+AXeqtHIXbLXRajSuNBfig2jno10f4 KW7rk8BGWuatTNeBr+U+I4v0/k0n/RjlPbuNkJu8= 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=4u1tUzcSp FTaMc03ZJgRiIoOklE=; b=TjrGuoofrNaBu5IlcrAwsDK4g73dTR+6lSxiLT5t7 d+0+fpv4BaTO3wdds6lWOnATlhuHM3nYjNGBw8dgySfe3J6NQvX0V38p36tklUlw ayRkUeDNBlXN7LBx/go+CptkPMBxAbp+oNhpfR/c6UgC+gnlb/LPKsyrxKTpilIf 1M= Received: (qmail 108502 invoked by alias); 5 Nov 2019 07:39:50 -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 108489 invoked by uid 89); 5 Nov 2019 07:39:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=gimplifycjj, gimplify.c.jj, UD:gimplify.c.jj 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, 05 Nov 2019 07:39:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572939587; 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=Qs0/R3s2Px07RCSPrdru/xz69fn8kWS6YSEPpMs9PcI=; b=YjTDwvY4WB0mY5Fvz48oVOEkelicyAcEYiU3VfpqJh+W+WeETnZplbEtpe5qDyldeZV2gW lK3HIZH7+nJcSQbP9NHPmr2cCmf92GijsEcjKq6uMT+Pv52HWBmBU8v+eCYonU/4atfg3g qKc+QcjVsoOQJ5h4DBdUWNOu9iTRkJg= 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-30-0cxCS-GXM-CJXQvL6G6Awg-1; Tue, 05 Nov 2019 02:39:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9915107ACC2; Tue, 5 Nov 2019 07:39:42 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FEA65DA66; Tue, 5 Nov 2019 07:39:42 +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 xA57det3032205; Tue, 5 Nov 2019 08:39:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xA57ddku032204; Tue, 5 Nov 2019 08:39:39 +0100 Date: Tue, 5 Nov 2019 08:39:39 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Reject VLAs in inline asm operands that require registers (PR inline-asm/92352) Message-ID: <20191105073939.GP4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! On VLAs with register only constraints we ICE, because during gimplification we try to create temporaries for them and force_constant_size aborts in that case. The following patch diagnoses those early, like we diagnose already C++ non-PODs. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-11-05 Jakub Jelinek PR inline-asm/92352 * gimplify.c (gimplify_asm_expr): Reject VLA in output or input operands with non-memory constraints. * c-c++-common/pr92352.c: New test. Jakub --- gcc/gimplify.c.jj 2019-11-02 10:00:59.595253274 +0100 +++ gcc/gimplify.c 2019-11-05 00:21:01.585958514 +0100 @@ -6235,8 +6235,14 @@ gimplify_asm_expr (tree *expr_p, gimple_ is_inout = false; } - /* If we can't make copies, we can only accept memory. */ - if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link)))) + /* If we can't make copies, we can only accept memory. + Similarly for VLAs. */ + tree outtype = TREE_TYPE (TREE_VALUE (link)); + if (outtype != error_mark_node + && (TREE_ADDRESSABLE (outtype) + || !COMPLETE_TYPE_P (outtype) + || (!tree_fits_poly_uint64_p (TYPE_SIZE_UNIT (outtype)) + && max_int_size_in_bytes (outtype)))) { if (allows_mem) allows_reg = 0; @@ -6392,7 +6398,12 @@ gimplify_asm_expr (tree *expr_p, gimple_ oconstraints, &allows_mem, &allows_reg); /* If we can't make copies, we can only accept memory. */ - if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link)))) + tree intype = TREE_TYPE (TREE_VALUE (link)); + if (intype != error_mark_node + && (TREE_ADDRESSABLE (intype) + || !COMPLETE_TYPE_P (intype) + || (!tree_fits_poly_uint64_p (TYPE_SIZE_UNIT (intype)) + && max_int_size_in_bytes (intype)))) { if (allows_mem) allows_reg = 0; --- gcc/testsuite/c-c++-common/pr92352.c.jj 2019-11-04 14:03:18.725275255 +0100 +++ gcc/testsuite/c-c++-common/pr92352.c 2019-11-04 14:02:55.211629675 +0100 @@ -0,0 +1,15 @@ +/* PR inline-asm/92352 */ + +void +foo (int x) +{ + int var[x]; + asm volatile ("" : "+r" (var)); /* { dg-error "impossible constraint in 'asm'" } */ +} /* { dg-error "non-memory output 0 must stay in memory" "" { target *-*-* } .-1 } */ + +void +bar (int x) +{ + int var[x]; + asm volatile ("" : "+m" (var)); +}