From patchwork Sat Feb 10 22:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 199320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1681485dyd; Sat, 10 Feb 2024 14:43:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQyj8WDbVvqFW6+fNYpODFUZsKzrrUqC2kp+rBMw0em4rysFPubteh83ZDoMp5iE9Dgezc X-Received: by 2002:a05:620a:a02:b0:785:ba90:9acf with SMTP id i2-20020a05620a0a0200b00785ba909acfmr3339677qka.14.1707605011370; Sat, 10 Feb 2024 14:43:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707605011; cv=pass; d=google.com; s=arc-20160816; b=Uzvuq6CMO78zCZP5thR/yIwK2TMEE4dIlJp5wEpNyUZNW9oIFGGXVuQg7YPgbEbnfC J311ERQpKScINZ5HF6jYHCY2Ev2eLecflUfhT0Oh/aVkpr1yQDh+sweDBYUPdDwZboYX hRCFxE+YyS8B5P0kf/rZ0e/opxoA/42W7NuceBebPTcLVewzVySttJP7WGi3zWygcvwn iWv1Bix5sD/Hp6m3NqledHDg9NmpUFqn+lsuHV6eQ3I+ygGYh3xtRYrJRN5vn1cGdlWw H1Z8Ahw0kMs005Z00fpMkOLixbGAxuUMNsVw2kMZazCqx+aoRp04F7pBIT97marIik4M tfRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=7J7UmBLxOLuw/+6nkgEPKCeG6kgTp3J70S4kwJxhf20=; fh=Bq4rFpi7QZZP6MK3MmnmUn4srs01+d/0/A/FBpaI4NQ=; b=TvoffRzUVfhGb07yPXc7hlUrRclmiR83AI/6bftLlyo3ebIffpFi9NzHJAbvcLuTUg TQJiQQpORsECFy553iyfJJCf10MWOJEbYSgTs0qABPcX8iBqIHuHmcJRtbyG5UU5bSOW vUSzZn6rCwrC3adPRnq/j0s4adqHAWkeZwAwUSo335JgGDAyOokYeGN0ohEmr+RXf1+K k/W+yssOOGAM8wGeJplUz+KwqXuyH3NLS/WgPL/7hRGzpxoIR1fPHTIxah5U1urOs5RI r44iowpUDjzDwZXUE3nYkBvOlIGydYFiQmNTt4shTSQPP98Ss5nBPGEaJ03tnCWXqjFo xgQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MVN3Of3U; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCV5oIjPd1W6UFJtO5E5d5ji+iXTkA5tCe4cAdOW5tY5/8DDayhtGW0zCL6p+oEMcusex8ENRZYdtW5TirbbQdKUrFfr8w== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a6-20020a05620a16c600b00785a3b16abesi2605352qkn.194.2024.02.10.14.43.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 14:43:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MVN3Of3U; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FF1D3858D35 for ; Sat, 10 Feb 2024 22:43:31 +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 A4DDE3858D20 for ; Sat, 10 Feb 2024 22:42:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4DDE3858D20 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 A4DDE3858D20 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=1707604975; cv=none; b=sYf/iGrLYjEaav73YkASS7PMkEW3BXvolRfr7cJb2aL7H+2xHucaIYZSsy9dn10hdwtBaecUmG2Jc4upjEv+50uru97i1B77+ICPO8tIgwnJQll2d2KgEGauh0U0ItUL583hIBoVpcxJC1kanrG9FB3EozPoRvzNk7hWKh8WoUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707604975; c=relaxed/simple; bh=CuyjAjsojbNLieSZ2BUEnMQ+4g2TdC/ZV6IRotox83s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h8WGJ6zj+LMtP+XG9CehQ61f+0M5OpOKIen3STchPM8P00TgVxtWM06CpA1FkPKYj4pP59v3o9ekrenbc/n6O/pyqIyZwEnYMhWIobuO25ATtQJUeHmeO/gz0YWRWlQ2BYb0+atNZHQ/LSq8YE7fS0eX6TOP2rawcGUSxpPhB2U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707604964; 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=7J7UmBLxOLuw/+6nkgEPKCeG6kgTp3J70S4kwJxhf20=; b=MVN3Of3UqyCr7IbZTtqXilrq9e2rdGwmhR2bvxrsxFSuxvn9AEMkRJpAfHBKzw2JfE3Q68 b4R92/4DE856yWMmZPH+MN0KbIyMz0uh8gMqxmU/xI+E0oCArbwY4sB51ByPLYrK86ZXDD Z+KRl6ZsCTk4gSoqZByNjBQtIl9Wuuk= 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-508-rSd7Vm92OXueauFdd8sc4Q-1; Sat, 10 Feb 2024 17:42:33 -0500 X-MC-Unique: rSd7Vm92OXueauFdd8sc4Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 4B5041C05EB7 for ; Sat, 10 Feb 2024 22:42:33 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.8.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A9AFC090A9; Sat, 10 Feb 2024 22:42:33 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with reinterpret_cast and switch [PR113545] Date: Sat, 10 Feb 2024 17:42:23 -0500 Message-ID: <20240210224223.2156462-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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_H5, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790553632274407797 X-GMAIL-MSGID: 1790553632274407797 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Jason, this is the patch you proposed for PR113545. It looks very safe so I'm posting it here so that it's not forgotten. PR c++/113545 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_switch_expr): If the condition doesn't reduce to an INTEGER_CST, consider it non-constant. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-reinterpret3.C: Remove dg-ice. --- gcc/cp/constexpr.cc | 10 ++++++++++ gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) base-commit: 93e1559bea434a681208e5e7a21513d7da2844d6 prerequisite-patch-id: 9dda211bd29817f18d2d46c3c5a7bbe3708cf9f2 diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 2ebb1470dd5..fa346fe01c9 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7106,6 +7106,16 @@ cxx_eval_switch_expr (const constexpr_ctx *ctx, tree t, cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue, non_constant_p, overflow_p); VERIFY_CONSTANT (cond); + if (TREE_CODE (cond) != INTEGER_CST) + { + /* If the condition doesn't reduce to an INTEGER_CST it isn't a usable + switch condition even if it's constant enough for other things + (c++/113545). */ + gcc_checking_assert (ctx->quiet); + *non_constant_p = true; + return t; + } + *jump_target = cond; tree body diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C index 51feb2e558e..adc0b418df9 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C @@ -1,7 +1,5 @@ // PR c++/113545 -// { dg-do compile { target c++14 } } -// Please change the above "dg-do compile" to "dg-do run" when the ICE is resolved. -// { dg-ice "PR112545 - constexpr function with switch called for reinterpret_cast" } +// { dg-do run { target c++14 } } char foo;