From patchwork Fri Mar 22 08:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1914752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U6mxVcyH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V1FNN55YHz1yXy for ; Fri, 22 Mar 2024 19:09:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A19FD3858432 for ; Fri, 22 Mar 2024 08:09:22 +0000 (GMT) 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 ESMTPS id 32D7F3858283 for ; Fri, 22 Mar 2024 08:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32D7F3858283 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 32D7F3858283 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=1711094936; cv=none; b=D8qP8/i6nOr0DF/KeNWdz3QB370eBJy+Q7xAWRAb3G84VkpKeum8KFxFmk7R//geErc08z8waYx3wwq+Uhf3sFbsL8crpxqBNkk8SEOJ2/23J8O/V9qJ1+Yfi6/9+bGMhJ4Wb2uR8PnNFA6ry/BAW0vFv/izNGoApWfGLKWfM4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711094936; c=relaxed/simple; bh=cA1RyFK6Bqvi22l+MjHYA3vm9+Vha6VPi2ZU36xWn+E=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=B03Je/CcYsbliWdw7bFRwcBcXBr0VWS/Jn1bxrLFMJfxs/aURLzDR8sr/QqPW+DP/FdXaLgK8JfsaL5RcfPmZyIK0qgntniN83+kfSWNOwrwSOo6Lh6VkLKH1noXd2FRDiloVnUyZ9fZmUI7qkrRYtNv88kOqrDfyoPcXchMjlk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711094934; 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; bh=j6sy4NzmmxoIpNHRaq7Ce+CoXIK6EEg3565dJyt7Pig=; b=U6mxVcyHLp+Vn0WsRmoD5NeLq4D8KwIF3ry705q2+Fft1axWmPIC3GbFaoaqcYylVmtilL VBhg+KB87yELOjLi+WhGdzQXQh6sDW5x7hPzVUCnZxsy0YMi2ZrvOCtgeUYoyqCy7oyvLW ZgVrqpM6cgOmICqQZB98UJiL8UkX6vs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-j8jqnrFIOiSVJVKpJUqo3w-1; Fri, 22 Mar 2024 04:08:50 -0400 X-MC-Unique: j8jqnrFIOiSVJVKpJUqo3w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07811101A523 for ; Fri, 22 Mar 2024 08:08:50 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD3522166B33; Fri, 22 Mar 2024 08:08:49 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 42M88hJq1473263 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Mar 2024 09:08:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42M88gYb1473262; Fri, 22 Mar 2024 09:08:42 +0100 Date: Fri, 22 Mar 2024 09:08:42 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix bogus warnings about ignored annotations [PR114409] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_TRUTHINESS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The middle-end warns about the ANNOTATE_EXPR added for while/for loops if they declare a var inside of the loop condition. This is because the assumption is that ANNOTATE_EXPR argument is used immediately in a COND_EXPR (later GIMPLE_COND), but simplify_loop_decl_cond wraps the ANNOTATE_EXPR inside of a TRUTH_NOT_EXPR, so it no longer holds. The following patch fixes that by adding the TRUTH_NOT_EXPR inside of the ANNOTATE_EXPR argument if any. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Note, the PR is mostly about ICE with the annotations used in a template, this patch doesn't change anything on that and I really don't know what should be done in that case. 2024-03-22 Jakub Jelinek PR c++/114409 * semantics.cc (simplify_loop_decl_cond): Use cp_build_unary_op with TRUTH_NOT_EXPR on ANNOTATE_EXPR argument (if any) rather than ANNOTATE_EXPR itself. * g++.dg/ext/pr114409.C: New test. Jakub --- gcc/cp/semantics.cc.jj 2024-03-01 17:27:58.862888609 +0100 +++ gcc/cp/semantics.cc 2024-03-21 15:24:57.296857864 +0100 @@ -799,7 +799,11 @@ simplify_loop_decl_cond (tree *cond_p, t *cond_p = boolean_true_node; if_stmt = begin_if_stmt (); - cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error); + cond_p = &cond; + while (TREE_CODE (*cond_p) == ANNOTATE_EXPR) + cond_p = &TREE_OPERAND (*cond_p, 0); + *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false, + tf_warning_or_error); finish_if_stmt_cond (cond, if_stmt); finish_break_stmt (); finish_then_clause (if_stmt); --- gcc/testsuite/g++.dg/ext/pr114409.C.jj 2024-03-21 15:27:44.077661090 +0100 +++ gcc/testsuite/g++.dg/ext/pr114409.C 2024-03-21 15:27:15.331039726 +0100 @@ -0,0 +1,22 @@ +// PR c++/114409 +// { dg-do compile } +// { dg-options "-O2 -Wall" } + +void qux (int); +int foo (int); + +void +bar (int x) +{ + #pragma GCC novector + while (int y = foo (x)) // { dg-bogus "ignoring loop annotation" } + qux (y); +} + +void +baz (int x) +{ + #pragma GCC novector + for (; int y = foo (x); ) // { dg-bogus "ignoring loop annotation" } + qux (y); +}