From patchwork Fri Nov 29 02:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 102059 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E64253858D20 for ; Fri, 29 Nov 2024 02:03:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E64253858D20 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FRnJ4lm7 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.133.124]) by sourceware.org (Postfix) with ESMTP id D282E3858D39 for ; Fri, 29 Nov 2024 02:01:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D282E3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D282E3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732845676; cv=none; b=JuIbThl0NrOGUnqE3j0sWTmOCejJqjaVm7LiJigdlSQLAHBPKx5C9B+QH6mLhQlJNdSm6I5d6Op3znvt0200L4piOhn2GKH0pQ2FY37kr3/5ei1gYoVVfQjZdOU0kt0yPOIequ6cFlbp/sAdj/3zvuK+cndfkJsJdcobILxeGd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732845676; c=relaxed/simple; bh=InJifErOky0jFMlo8vMye44UTe0NguZ+vCrZnYQVorg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=oCVFT7YuDRwmjZPCsjVFStvjPWHFmrg6s0RwG4J/O4s12sMKadKhWtusQkA4BXM484P/AaPAxaWB/G8GIytfYa4yX0ESZCxCv4G8lJgdG17A3Sv+dTEt5xR9juT26m/z96vlHoSh3uUYBZYZxQEmk4YlCqPUlgusBzgtydLORGY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D282E3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732845676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=9knhdEX026eE1v8ExlCSsJ7xQwvq8fdtsjHc9+uo2l8=; b=FRnJ4lm7KXNb+xk9kmDT1mty5VYs0BHudPPc+CR4qT7q5EJ37rf50d698vbY/zg5bgzx8U BZOLwzBy7M51cNN7iDGFOKaH9yWe0ejtpTPokX02ISzIDZpJe1m+P3egqw8Y3cKbG3dCz/ l9Ed0v8AlI9Wi5ok6fyT6Wj1vY9uuSk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-dW58v0THMuuCcwFhhNA1nA-1; Thu, 28 Nov 2024 21:01:14 -0500 X-MC-Unique: dW58v0THMuuCcwFhhNA1nA-1 X-Mimecast-MFC-AGG-ID: dW58v0THMuuCcwFhhNA1nA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43498af79a6so7728435e9.0 for ; Thu, 28 Nov 2024 18:01:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732845673; x=1733450473; h=mime-version:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9knhdEX026eE1v8ExlCSsJ7xQwvq8fdtsjHc9+uo2l8=; b=lr02THOKFSpZlPbBjLMCSW/cyQ48RJIa6lC+/0r3tb8AS3WMrjLNBvQpZgUH05ciJw sT4aY7AN6XKuyqcFD0U7nYa/8eitjbdVd3OlPO6ff76yYp675iZW3+o4t6kgK71GvuBY E8CZJ1IayGYhgeQFSEul0wbY/uOuuHnNZXzs1y8EE3njJIfaSOqTrgYguarteuFGMYdR i/fbjWZog36kR8H7DmEOMrZ6bJQbROVfnrWcpo4uaNe9wsdIM5osmcnYxLOVkeiBYPNN VtUsdU2/9pQXMrABQzyFkJbAcv5Q1toeIKaigMKuLDTyGYes+QXKNJFd36Uo8S450dzM w9cQ== X-Gm-Message-State: AOJu0Yyv+PmWTuboCgTQsy2YkIpFXQhPBczbHKyNu2xAiWJFCOeH/7KX mFyE4RNUurfLPJaLI7sGbOvGZ/7/jfRygRMeKjr2kDt/mtfzYJ0TjF5uw0ig3R8LOW4gTlDDMY+ PChlw9dqVVGDY5+7OnCCJ45IGUaiZgKyD+WlCye532v+Wmju3K9E8buvBrxg7+6NJ9fFTOyb+NS riswWLGBB02LRdECdcjDeKrUWnAssMdZhAOw8qktQ= X-Gm-Gg: ASbGncv07i6dguyO4rVe5YLkIf5iUjg+doAVC2UloyXcqFV+SWnvaCnIxMOEsSHAVMc j1YpaCwt6uKtVwnYJmNQjA1FRWzOXBKxtD8hLkJXlubTc8TrnVJSo8J0duKaP2JTG3doxdwjdCq 3Le47i93hAywkD9VV3NOEghF9j7epgBZpJMESS1W88M9IeBYXeRdjz5NYgouVn81DxbkmESruAv GJoYQO1jepm6ipZ+P+2KwdP760RAAUM52MHDsY6l4ccEh/eJvuZXO/5+47WzoiBoCUQB5J2T5LN sXelVQ== X-Received: by 2002:a05:600c:6c8a:b0:434:8e8a:d4ec with SMTP id 5b1f17b1804b1-434afc3b6e1mr47072615e9.13.1732845672678; Thu, 28 Nov 2024 18:01:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaGa2xVwwIM1/MbTgoW4fQxmLoIk5115bb58v9LRsdkba8IK5UAycx0dPPMZWXmIkSxa0eYA== X-Received: by 2002:a05:600c:6c8a:b0:434:8e8a:d4ec with SMTP id 5b1f17b1804b1-434afc3b6e1mr47072195e9.13.1732845672206; Thu, 28 Nov 2024 18:01:12 -0800 (PST) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-385ccd3666csm3026061f8f.23.2024.11.28.18.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 18:01:11 -0800 (PST) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.97) (envelope-from ) id 1tGqJ6-0000000G9x9-32h4 for gcc-patches@gcc.gnu.org; Fri, 29 Nov 2024 02:00:32 +0000 Date: Fri, 29 Nov 2024 02:00:32 +0000 (UTC) From: Joseph Myers To: gcc-patches@gcc.gnu.org Subject: gimplify: Handle void BIND_EXPR as asm input [PR100501] Message-ID: <821087c6-907d-44ff-2d51-841a6cb0462e@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: WQk_xnfpzTl54voF0tTOJdF1h7IJa8hxut04ZBcgqbE_1732845673 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.1 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org As reported in bug 100501 (plus duplicates), the gimplifier ICEs for C tests involving a statement expression not returning a value as an asm input. The expected diagnostic for this case (as seen for C++ input) is one coming from the gimplifier and so it seems reasonable to fix the gimplifier to handle the GENERIC generated for this case by the C front end, rather than trying to make the C front end detect it earlier. Thus, adjust two places in the gimplifier to work with gimplifying a BIND_EXPR changing *expr_p to NULL_TREE. Bootstrapped with no regressions for x86_64-pc-linux-gnu. OK to commit? PR c/100501 gcc/ * gimplify.cc (gimplify_expr): Do not call gimple_test_f on *expr_p when it has become null. (gimplify_asm_expr): Handle TREE_VALUE (link) becoming null. gcc/testsuite/ * gcc.dg/pr100501-1.c: New test. diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index fb0ca23bfb6c..090f8987d5d3 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -7457,6 +7457,13 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) TREE_VALUE (link) = error_mark_node; tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, is_gimple_lvalue, fb_lvalue | fb_mayfail); + if (TREE_VALUE (link) == NULL_TREE) + { + /* This can occur when an asm input is a BIND_EXPR for a + statement expression not returning a value. */ + tret = GS_ERROR; + TREE_VALUE (link) = error_mark_node; + } if (tret != GS_ERROR) { /* Unlike output operands, memory inputs are not guaranteed @@ -19662,10 +19669,11 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, /* Otherwise we're gimplifying a subexpression, so the resulting value is interesting. If it's a valid operand that matches - GIMPLE_TEST_F, we're done. Unless we are handling some - post-effects internally; if that's the case, we need to copy into - a temporary before adding the post-effects to POST_P. */ - if (gimple_seq_empty_p (internal_post) && (*gimple_test_f) (*expr_p)) + GIMPLE_TEST_F, or it's now NULL_TREE, we're done. Unless we are + handling some post-effects internally; if that's the case, we need + to copy into a temporary before adding the post-effects to POST_P. */ + if (gimple_seq_empty_p (internal_post) + && (!*expr_p || (*gimple_test_f) (*expr_p))) goto out; /* Otherwise, we need to create a new temporary for the gimplified diff --git a/gcc/testsuite/gcc.dg/pr100501-1.c b/gcc/testsuite/gcc.dg/pr100501-1.c new file mode 100644 index 000000000000..b5b3781a9c2f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100501-1.c @@ -0,0 +1,26 @@ +/* Test ICE for statement expression returning no value as asm input (bug + 100501). */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int x; +int g (); + +void +f () +{ + __asm__ ("" : : "m" (({}))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ ; }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ (void) 0; }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ f (); }))); /* { dg-error "memory input 0 is not directly addressable|using result of function returning 'void'" } */ + __asm__ ("" : : "m" (({ f (); f (); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ x = g (); f (); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ if (1) g (); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ if (1) g (); else g (); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ test : goto test; }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ return; }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ while (1); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ do {} while (1); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ for (;;); }))); /* { dg-error "memory input 0 is not directly addressable" } */ + __asm__ ("" : : "m" (({ switch (x); }))); /* { dg-error "memory input 0 is not directly addressable" } */ +}