From patchwork Tue Dec 5 20:31:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1872314 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=O783nYXc; 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 4SlBzB6y9zz23mf for ; Wed, 6 Dec 2023 07:32:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E63A33857C40 for ; Tue, 5 Dec 2023 20:32:02 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 97F3E3858C60 for ; Tue, 5 Dec 2023 20:31:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97F3E3858C60 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 97F3E3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701808312; cv=none; b=qsAJ9sNe+c2z3yqaeBQ0hzmEv7CBrVFZx0TxlUNS+v1V+/QEpPF5s8SKQEWvFqf24+zF26vyiAgUHJ1C5FWMWWfyizJY7ErNC3S2ItyYPpJviW8KRIO7/u5U5dPr7F5b8h5JsWGu89NPJDpef3Usx9K+Zav71SH2bEE9nmaNcxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701808312; c=relaxed/simple; bh=mYCiHDQanRPjCklh7sA5G4RIbouhadV6N16ExStTfmE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tXWhbfAZG7ffGXtTIO4ugL+us+aQFUq/5EOHpVus6lJ/3zcXdjg0MkcuN47WKt+1qxoZwsORkNWgnEa2+oYaUfAe3m0vLY9bUwyjHsJXJDDDH9VOzBuSiF7e1dg7L/HKHty97esk1Lf127LUnY15vopSzy36obyWIgbI4cSIt5Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701808310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rbZFP5/N38lkp0I1S8E9mMdAY3XTA9CP0LRThhO8MIw=; b=O783nYXcTQeMDkjI2YSQT3Q/zPo8dloD5LegxUPFCrIed8OWkAV3Dfxr2RCHDR5qTP/mC5 ebgE+a2zuWymKUlwArBwIGV6GbLSQdn81Ucp8joIe++dTjv1sVP5qwREc80J9MgWAInjP0 yNlSvNQYOf9NynCNkgpkXc243Za0lWo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-aDEgsGJdPkmOTrYsa5qnlg-1; Tue, 05 Dec 2023 15:31:47 -0500 X-MC-Unique: aDEgsGJdPkmOTrYsa5qnlg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 40C1D29ABA0C for ; Tue, 5 Dec 2023 20:31:47 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2066740C6EB9; Tue, 5 Dec 2023 20:31:47 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: fix ICE with sizeof in a template [PR112869] Date: Tue, 5 Dec 2023 15:31:36 -0500 Message-ID: <20231205203136.94832-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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.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+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- This test shows that we cannot clear *walk_subtrees in cp_fold_immediate_r when we're in_immediate_context, because that, as the comment says, affects cp_fold_r as well. Here we had an expression with min ((long int) VIEW_CONVERT_EXPR(bytecount), (long int) <<< Unknown tree: sizeof_expr (int) <<< error >>> >>>) as its sub-expression, and we never evaluated that into min ((long int) bytecount, 4) so the SIZEOF_EXPR leaked into the middle end. (There's still one *walk_subtrees = 0; in cp_fold_immediate_r, but that one should be OK.) PR c++/112869 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold_immediate_r): Don't clear *walk_subtrees for unevaluated operands. gcc/testsuite/ChangeLog: * g++.dg/template/sizeof18.C: New test. --- gcc/cp/cp-gimplify.cc | 8 ++------ gcc/testsuite/g++.dg/template/sizeof18.C | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/sizeof18.C base-commit: 9c3a880feecf81c310b4ade210fbd7004c9aece7 diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 5abb91bbdd3..46c3eb91853 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1177,13 +1177,9 @@ cp_fold_immediate_r (tree *stmt_p, int *walk_subtrees, void *data_) ? tf_error : tf_none); const tree_code code = TREE_CODE (stmt); - /* No need to look into types or unevaluated operands. - NB: This affects cp_fold_r as well. */ + /* No need to look into types or unevaluated operands. */ if (TYPE_P (stmt) || unevaluated_p (code) || in_immediate_context ()) - { - *walk_subtrees = 0; - return NULL_TREE; - } + return NULL_TREE; tree decl = NULL_TREE; bool call_p = false; diff --git a/gcc/testsuite/g++.dg/template/sizeof18.C b/gcc/testsuite/g++.dg/template/sizeof18.C new file mode 100644 index 00000000000..afba9946258 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/sizeof18.C @@ -0,0 +1,8 @@ +// PR c++/112869 +// { dg-do compile } + +void min(long, long); +template void Binaryread(int &, T, unsigned long); +template <> void Binaryread(int &, float, unsigned long bytecount) { + min(bytecount, sizeof(int)); +}