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: 190224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2706315dyb; Mon, 22 Jan 2024 09:03:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtNy1IzZaGYSjvqHqwWbop5IAKnXk0YjbnDP9cq63UFhc55agQk8ufnpM1Avt/JCDC9Fol X-Received: by 2002:a05:620a:394c:b0:783:3115:f4ce with SMTP id qs12-20020a05620a394c00b007833115f4cemr7773144qkn.26.1705943013004; Mon, 22 Jan 2024 09:03:33 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1705943012; cv=pass; d=google.com; s=arc-20160816; b=QT/UBkcgq5CZQIj/rAFpjXEw+s7uI/GBZ4WZ7E30NfehtR9O3C/j4+PzgdoPrHQl67 aTMhpvE57Ae4Whw5Clw7yA4NtBeEaIA0uxNjgzNVxiah7acbJkXY9XIvWlFsFFpbkCxF FNoc8n+7eN74eBkukv+zeamVC/vb/GYrBCRhxCDeLrbOgZVewBR9YLoMtK5U6Dd+ADVV SBPD3OXBZWEKWm1oMsrO8o5xZhOmgrat+zwwrFsHcPQddKLO+6aIdR2WR0TmfjeoDNPs N3nVlLQ0JPEGESPYwq/2kipi4cTjIXNRlRaMoXwpZ22drBZ0EmoI8T0zwybpc88pYOy8 SAMQ== ARC-Message-Signature: i=3; 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:date:message-id :content-transfer-encoding:mime-version:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=cv80qXfiD3uEnhBpbeWQM/UTNe6RcP1P26M5gVFn8OA=; fh=gk9A5O7Gbglvz1MjrRQ4hZ2i3c68kYkpOZJg1emXh+g=; b=OXpR5xRu7m9AqE/pSekNLF4gwM/Q0/894QvuKIv6mgy3Zm4RfshppPwYgDqcaWDpqQ P9jVmTm5bQi1G81BzkVJNbXaUuyvSuOrDD3wThFid+LwUAs/MpJ3Nus2+B0T0kz4mIOP E6cyKXhSf/o+UieNb26gOZRvTxsYkR0UNx0ArSC9/wdHUx6H0TrnWuAZKzm5ObW9FEes 38Y0J7K8aJ3VosD4znCJZ5NWxhDL1+r9NhlBq1+k8H7R4WtUGopshFcs9wRw3e4HLd+C E9UJEa7wkGhLFYEWd1w7kIJclpWkTNPTK0ht9M5FKUeGiqIFQRWfNMJq77cvY6ekA/m6 ORnw== ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@axis.com header.s=selector1 header.b=EDbIkH9P; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f27-20020a05620a12fb00b007832fa306f5si5803958qkl.237.2024.01.22.09.03.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:03:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@axis.com header.s=selector1 header.b=EDbIkH9P; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A2163857C72 for ; Mon, 22 Jan 2024 17:03:32 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788810901030555637 X-GMAIL-MSGID: 1788810901030555637 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); +}