From patchwork Mon Jan 22 17:02:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1889283 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=axis.com header.i=@axis.com header.a=rsa-sha256 header.s=selector1 header.b=EDbIkH9P; 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 4TJc3v2Scqz23db for ; Tue, 23 Jan 2024 04:03:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C6713857C65 for ; Mon, 22 Jan 2024 17:03:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2041.outbound.protection.outlook.com [40.107.22.41]) by sourceware.org (Postfix) with ESMTPS id 52B4C3858414 for ; Mon, 22 Jan 2024 17:02:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52B4C3858414 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=axis.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52B4C3858414 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.22.41 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1705942966; cv=pass; b=Iol3GPw23WgnGHF8dhM5YK56YhcMiSVdc1UqEMcQGaPljEjql7gdWCVHHu10MQawcu0ukZ0IgATUkUO4i6VhXL5nBW+veZ3gx/vAq7hC0J443K/FV9vrc+XRvDQRsh0h0iqhlWh735RYc5q/kLybRWJ6pp7nG5I/UNaSq58LygQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1705942966; c=relaxed/simple; bh=vMAzAcmXiSky38WM3q1U2ndvBdZQbSxuXlEsHb5Gsg8=; h=DKIM-Signature:From:To:Subject:MIME-Version:Message-ID:Date; b=hEjPAZ+Vdl4pllnTFIZLPV5rFdxDTAJxcQa5B1ypymt7m+93m2iyEbAYQIjWHbhdv2i3vE5I8Iz9H0blTobB9959ocoV7ZQIkZLJK8a2R/ZQhjyk/CYrkdNUrntBsA0HywHioBqyvBbtzY5BXIfk6n9tc/JgzE+BxNwzsHf9Wkc= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JG+ecvDQUJiPP2MNtEl44Nbfg99wn0oIM/bG2cu5hQxd1TTwVHkeIQgR8/sK0IdK3SaQDOEsTb9UpktD34MAdyfoK5CvwjKFPQymvUc7915AXxx6oOaUcDgkCxZVxjQ/tTSUYM0dfibJcEVpl3+/npwQoz7r7rRR3d2kZnho9ZUB/u3vJ0Te15lFlycVwH68byTb67MRYumNZ57hzn3oOaj9+ig1eLNk+MaXm8RcQOW7PmyuZm1YCXbSgTt0ohUlyHNa8hF5nelBmWi/udVayusbNtqs6jr3eTjHbDzY2MX8bu236PzN34ObgeLdOjQA4SNDP4hGZmJkTWa7ZKEJlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cv80qXfiD3uEnhBpbeWQM/UTNe6RcP1P26M5gVFn8OA=; b=mCeB6udIic7LtVc0xkku6oqBLW5DwfMfbtFIajIkV9/J06XRT25bQDk2EWKA/eETK4NsUDM9+456vJewu3Di/fcGTufM+zBhZHzozZD/MeTDaFLzKkHxjCMxsc2IqW9FDy4DvIthVGlptUSDXgtZsYmlnrKsXqn+k2Ee13wjK9Q98xGFkIt9cKejCHu2pkKoC95t2DI2tGm+HObstwzOI724AS2Ve4oJeqBEvp7gHQX2QT2fXf0vVxi1iVwTkETLgiowuEk9XWRTZpn7Q9PGxM7mRtUOm5lER6ZpLwi2X9vMlIYtazyFcIizf/d22SIvIjAw81CDZTIfGao8RjZJDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 195.60.68.100) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=axis.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cv80qXfiD3uEnhBpbeWQM/UTNe6RcP1P26M5gVFn8OA=; b=EDbIkH9PLNYThEXz1apXaoVppMLyhokQ2SSoRRSnu4ISpGOx2pGwwK/F1fBbbs/fy8RC6sP3vU0UWjFrilDPiq0MzBgteNdllpH+/eBYMF9MvHrgBBcUGgHvuMQKl/T9jD+fvSjm28EHZ73PEMt6lheBt507K72m1u9ud+kC1FQ= Received: from DB8PR09CA0035.eurprd09.prod.outlook.com (2603:10a6:10:a0::48) by PAVPR02MB9451.eurprd02.prod.outlook.com (2603:10a6:102:307::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.31; Mon, 22 Jan 2024 17:02:33 +0000 Received: from DB5PEPF00014B98.eurprd02.prod.outlook.com (2603:10a6:10:a0:cafe::60) by DB8PR09CA0035.outlook.office365.com (2603:10a6:10:a0::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.34 via Frontend Transport; Mon, 22 Jan 2024 17:02:33 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=axis.com; Received-SPF: Fail (protection.outlook.com: domain of axis.com does not designate 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; Received: from mail.axis.com (195.60.68.100) by DB5PEPF00014B98.mail.protection.outlook.com (10.167.8.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Mon, 22 Jan 2024 17:02:33 +0000 Received: from se-mail01w.axis.com (10.20.40.7) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 22 Jan 2024 18:02:32 +0100 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Mon, 22 Jan 2024 18:02:32 +0100 Received: from pchp3.se.axis.com (pchp3.se.axis.com [10.88.21.53]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id CE21612A8C; Mon, 22 Jan 2024 18:02:32 +0100 (CET) Received: by pchp3.se.axis.com (Postfix, from userid 171) id C836A20439; Mon, 22 Jan 2024 18:02:32 +0100 (CET) From: Hans-Peter Nilsson To: Subject: [PATCH] c++: Don't ICE for unknown parameter to constexpr'd switch-statement, PR113545 MIME-Version: 1.0 Message-ID: <20240122170232.C836A20439@pchp3.se.axis.com> Date: Mon, 22 Jan 2024 18:02:32 +0100 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B98:EE_|PAVPR02MB9451:EE_ X-MS-Office365-Filtering-Correlation-Id: 65bb36bc-5a1e-4ad5-4957-08dc1b6bed2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JzFKL0y6xZnpFz+So3tKeBI0/OEVaLvcbd5CeRftWE1aV88hCsiK7ck/j/kTd+lgLfjq8LmIuZIsSy4+u4H6XXwS9QRZpJywJcMeXlm0fBaawEgBvvYxH7YVUeM92Z+X/88oix+qZMgf08aSd+WKMHb6pTqBvlWdG76izu+5tQLfc4bo2JytPW1IGXTX7WZKxI6i0kI575tAwGqLUMUFiMQc8BxtYC1/g69O0Il+k2jXCopPBRLGnFBdQcOogM/DK6E2erME+MAgCihEKQdGwJksfENBrGvmp9uA2uiafzXXW1p4389ConTn+YTnj7GFqXLxALJX8n2bXgLepbKukI0Yt30KqBzARg+CL/LFh1Wp42qLKVA//fcPfa+rv6zXHfLR2f/KjI2C7mIhmPDEpcL1tcWdyU1WDiFLtJgb6KYJmvhWjsPeVpusbt5UOgo68GMajg07TxgRPUFCgtHxsy6GRiFsJGS3t6jckuk/npnJeri4pYGg0Qie4M6BMzslOqllCl6NDgcv84kU2/4fQB0QWWOikFJr2L/MK2BFeV7vok5ebIfL4wcePFj1ofydsqYI7nSSeUCsELPAxZiFfNBUkQKgeBvfEVK5GVJ4s524dtwVLJgmvt/6K6mT5OVo+maDeryssQIy6nJTHF7Yis+I1Tiwn4oZjvDat7PV54wf70SbkvF/vJDYZpFN/oNcSGTfXpQSQwwV3LwhHk6cwGGJ9QF3dbHmJK7Rb3J4Lll4CVoXK0vn6Ow0PFdtF3kBGHgK6JdmAw+52RMk6RlW8w== X-Forefront-Antispam-Report: CIP:195.60.68.100; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.axis.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(136003)(396003)(346002)(376002)(230922051799003)(186009)(451199024)(64100799003)(82310400011)(1800799012)(40470700004)(36840700001)(46966006)(426003)(1076003)(26005)(336012)(6266002)(47076005)(36860700001)(5660300002)(2906002)(8676002)(42186006)(8936002)(83380400001)(70586007)(316002)(70206006)(478600001)(6916009)(356005)(82740400003)(41300700001)(81166007)(33656002)(40480700001)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 17:02:33.3539 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65bb36bc-5a1e-4ad5-4957-08dc1b6bed2c X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af; Ip=[195.60.68.100]; Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B98.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR02MB9451 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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 I don't really know whether this is the right way to treat CONVERT_EXPR as below, but... Regtested native x86_64-linux-gnu. Ok to commit? brgds, H-P -- >8 -- That gcc_unreachable at the default-label seems to be over the top. It seems more correct to just say "that's not constant" to whatever's not known (to be constant), when looking for matches in switch-statements. With this patch, the code generated for the (inlined) call to ifbar equals that to swbar, except for the comparisons being in another order. gcc/cp: PR c++/113545 * constexpr.cc (label_matches): Replace call to_unreachable with return false. gcc/testsuite: * g++.dg/expr/pr113545.C: New text. --- gcc/cp/constexpr.cc | 3 +- gcc/testsuite/g++.dg/expr/pr113545.C | 49 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/expr/pr113545.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 6350fe154085..30caf3322fff 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -6922,7 +6922,8 @@ label_matches (const constexpr_ctx *ctx, tree *jump_target, tree stmt) break; default: - gcc_unreachable (); + /* Something else, like CONVERT_EXPR. Unknown whether it matches. */ + break; } return false; } diff --git a/gcc/testsuite/g++.dg/expr/pr113545.C b/gcc/testsuite/g++.dg/expr/pr113545.C new file mode 100644 index 000000000000..914ffdeb8e16 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/pr113545.C @@ -0,0 +1,49 @@ +// { dg-do run { target c++11 } } + +char foo; + +// This one caught a call to gcc_unreachable in +// cp/constexpr.cc:label_matches, when passed a convert_expr from the +// cast in the call. +constexpr unsigned char swbar(__UINTPTR_TYPE__ baz) +{ + switch (baz) + { + case 13: + return 11; + case 14: + return 78; + case 2048: + return 13; + default: + return 42; + } +} + +// For reference, the equivalent* if-statements. +constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz) +{ + if (baz == 13) + return 11; + else if (baz == 14) + return 78; + else if (baz == 2048) + return 13; + else + return 42; +} + +__attribute__ ((__noipa__)) +void xyzzy(int x) +{ + if (x != 42) + __builtin_abort (); +} + +int main() +{ + unsigned const char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); + xyzzy(c); + unsigned const char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); + xyzzy(d); +}