From patchwork Mon Sep 30 00:56:39 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: 1990671 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=dkdNLgyI; 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 4XH2j74vCvz1xt8 for ; Mon, 30 Sep 2024 10:57:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 105BE385EC34 for ; Mon, 30 Sep 2024 00:57:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazlp170110001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::1]) by sourceware.org (Postfix) with ESMTPS id 65316385EC0F; Mon, 30 Sep 2024 00:56:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65316385EC0F 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 65316385EC0F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c200::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1727657811; cv=pass; b=exFwvphF4m0qWVAahDfFvFaNH4amISOXPMrIfmj9WknuWG4EaoVcsfbXeHIS9Vl9td+4G48DTpyAbbq3MdMAlsixLJnZxKiorHPeivFhe3OD/7Joaoo6AVWhT93+qKivRLCovQDcMYqRNnoLqM/USFrXaEmzzbDR26yry3Y4/dA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1727657811; c=relaxed/simple; bh=b1WoRmQNL5KoPxQWZx98L+uG6xWq8LZrgxqz/uMH6Ew=; h=DKIM-Signature:From:To:Subject:MIME-Version:Message-ID:Date; b=Rm6gmY3KHXk1o4uQnYCcBdsw6txQ2b33iBZI4LzFfqSZSDLR33xpK4Rg0x0D4/2BlHeR+OyfIX99VR+DXOAIMwR2mCCjrX++vmzyLI+spopfOml7ju3F98QhL/3JucjLdSgRbuVBjrWWLb38Rszsxo51H2hwod4hnu3lUBDNJAk= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bR+kBsA9DA6thw6KBw/MVKUciVVZl5sij6FN3hScLVcrdr7fR+4e3OEOVv8SgxC1ABvfuhWUCr+RA89pbOxLhMuZCZTk249+nFqeWNE9NRUC1U8nbNuJI3nChSksP52cqpdXZMh3xc3CRn7/7+UmQ88+e2KmuCD7wtVxkvXBRswvlzT4sVI/8Vur+9Ou0oIW0koNd0qBh++SdHO+6VYIwAT7V2FTzzSc6u36/6Gn6JblClxHBRcyYNJbHmBQgheF0pTxBL5wesH7BigUTqQxm2F4Fd8hjl6AVdfkGJ8KSnQTsV5klrPJOPbEBeu3oJLoQR57WsC2QZBaXffdrF5ouw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=P/1P+FbHSh66ptsLZcqb5OUVetY1MhkkBkSWrVH5yZ0=; b=eV5tDQLLuggTMFIlmQSgA52XQQZExxyT0MlR87VRamSODCYWcemyFl5f0WjeEqU3zbvT+ZfMtguztKxmAz0Cpb4Qdvfxscd2hxN0udtUVeCHy8sb2Qsew2AMu/qENyq1nNk+KAY4gbMEqaf62f0MS1hrqdDpefGU6z5q9ziMtpOoak26id77B3NM7nJOIxrxXHCgxEGoyz/J/Jj/Sbr+h3H35WZq1iJBcrcQbIsulQvRyx7WAXuHv21D4Gdm+/kll4mxK+PQhf8AYd6jtim/B6zRsGLtCLz9X55Inpa/9f8NgE+gaREvDcpmxAod6gLrkkaJlLP+ahAj4BPkE0P3nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=axis.com; dmarc=pass (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=P/1P+FbHSh66ptsLZcqb5OUVetY1MhkkBkSWrVH5yZ0=; b=dkdNLgyIl7VnenQWqWDAgOziYXVAHrcEFz3Rs+A60JN+LZzvq506+hI1Xux9aWSE8qmTW2ijx8Cfhu26x+35eMZCeDOy/3aBno/vMT4Rgvb9KMgYgm2O3tCZ+JF3dWw5nPrKDwy4VaorEX3Ubd6BXOVuZhgw09ZmwlCcrkF/qgo= Received: from DUZPR01CA0124.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bc::7) by GVXPR02MB10593.eurprd02.prod.outlook.com (2603:10a6:150:156::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.24; Mon, 30 Sep 2024 00:56:43 +0000 Received: from DB5PEPF00014B98.eurprd02.prod.outlook.com (2603:10a6:10:4bc:cafe::71) by DUZPR01CA0124.outlook.office365.com (2603:10a6:10:4bc::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26 via Frontend Transport; Mon, 30 Sep 2024 00:56:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C 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.8026.11 via Frontend Transport; Mon, 30 Sep 2024 00:56:42 +0000 Received: from se-mail01w.axis.com (10.20.40.7) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 30 Sep 2024 02:56:39 +0200 Received: from se-intmail02x.se.axis.com (10.0.5.60) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Mon, 30 Sep 2024 02:56:39 +0200 Received: from pchp3.se.axis.com (pchp3.se.axis.com [10.88.21.53]) by se-intmail02x.se.axis.com (Postfix) with ESMTP id 565F5186; Mon, 30 Sep 2024 02:56:39 +0200 (CEST) Received: by pchp3.se.axis.com (Postfix, from userid 171) id 50DB92043D; Mon, 30 Sep 2024 02:56:39 +0200 (CEST) From: Hans-Peter Nilsson To: , CC: Subject: [PATCH] libstdc++-v3: Fix signed-overflow warning for newlib/ctype_base.h, PR116895 MIME-Version: 1.0 Message-ID: <20240930005639.50DB92043D@pchp3.se.axis.com> Date: Mon, 30 Sep 2024 02:56:39 +0200 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B98:EE_|GVXPR02MB10593:EE_ X-MS-Office365-Filtering-Correlation-Id: dc0d6943-6725-4c00-d499-08dce0eabff7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?iso-8859-1?q?ZiCe2p67RWUQoR+Yc0rFpqIdEz?= =?iso-8859-1?q?5vQe8Dbzx8+QWBdqamt3gHwK3hFQrtA5QY3TwWyKYd7HJH5SWgtGEq1eU0S0?= =?iso-8859-1?q?bL9BG78UkSGMLeZGHkVVZVl3FSC/gdhPiBIWfciyhLNpntXzvim/g6AvaB/3?= =?iso-8859-1?q?tqtg0hPPodCQc2dGvHOWTXbX3ChKv4I2pgcyRv6bqDW5Ct9MxvTfw8vzQ8l4?= =?iso-8859-1?q?JYTbxPEhDT/G67+36WKReuf5Q0sLJUuQsAUqMxEs0Q6gk4FZTTUCdyPL+8VP?= =?iso-8859-1?q?fdSXRMbC9oPP0hpJx0uZV97SshuJxKuu5uoIrFhRXwK8fd3nFWWZr+RKSyxv?= =?iso-8859-1?q?gKejlJW6gUN6FrtKau7EWTT7IuyD5Yu04VTXgW4f0S8SPgRCGuf+7hrmrd/W?= =?iso-8859-1?q?oCADawVwKmMbTFujc9TKnVCOrpAZhPfHU/tMErO/8WqPPxS1FOJx/1LUdNKd?= =?iso-8859-1?q?ur2XF9S2hXPtSN9sbnITNYEfr5m4RCfzfq55dUbywtjjJ4NkCpAA3kWOWN0G?= =?iso-8859-1?q?UWHFTxEkErzbWztRAOMWftUUb7W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3AgCi?= =?iso-8859-1?q?2uRjWHRcMXciw2vMT/Et3F4+MSfRb0ocC8NBbAy4G7bE7vhVR1UjqFDWCCfw?= =?iso-8859-1?q?WvRlgD?= 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:(13230040)(1800799024)(82310400026)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 00:56:42.6645 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dc0d6943-6725-4c00-d499-08dce0eabff7 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: GVXPR02MB10593 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_PASS, TXREP 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 FWIW, I see "typedef char mask;" also for bionic and openbsd. Tested for cris-elf. Ok to commit? -- >8 -- There are 100+ regressions when running the g++ testsuite for newlib targets (probably excepting ARM-based ones) e.g cris-elf after commit r15-3859-g63a598deb0c9fc "libstdc++: #ifdef out #pragma GCC system_header", which effectively no longer silences warnings for gcc-installed system headers. Some of these regressions are fixed by r15-3928. For the remaining ones, there's in g++.log: FAIL: g++.old-deja/g++.robertl/eb79.C -std=c++26 (test for excess errors) Excess errors: /gccobj/cris-elf/libstdc++-v3/include/cris-elf/bits/ctype_base.h:50:53: \ warning: overflow in conversion from 'int' to 'std::ctype_base::mask' \ {aka 'char'} changes value from '151' to '-105' [-Woverflow] This is because the _B macro in newlib's ctype.h (from where the "_" macros come) is bit 7, the sign-bit of 8-bit types: #define _B 0200 Using it in an int-expression that is then truncated to 8 bits will "change" the value to negative for a default-signed char. If this code was created from scratch, it should have been an unsigned type, however it's not advisable to change the type of mask as this affects the API. The least ugly option seems to be to silence the warning by explict casts in the initializer, and for consistency, doing it for all members. PR libstdc++/116895 * config/os/newlib/ctype_base.h: Avoid signed-overflow warnings by explicitly casting initializer expressions to mask. --- libstdc++-v3/config/os/newlib/ctype_base.h | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/config/os/newlib/ctype_base.h b/libstdc++-v3/config/os/newlib/ctype_base.h index 309fdeea7731..5ec43a0c6803 100644 --- a/libstdc++-v3/config/os/newlib/ctype_base.h +++ b/libstdc++-v3/config/os/newlib/ctype_base.h @@ -41,19 +41,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: Offsets into ctype::_M_table force a particular size // on the mask type. Because of this, we don't use an enum. typedef char mask; - static const mask upper = _U; - static const mask lower = _L; - static const mask alpha = _U | _L; - static const mask digit = _N; - static const mask xdigit = _X | _N; - static const mask space = _S; - static const mask print = _P | _U | _L | _N | _B; - static const mask graph = _P | _U | _L | _N; - static const mask cntrl = _C; - static const mask punct = _P; - static const mask alnum = _U | _L | _N; + static const mask upper = mask (_U); + static const mask lower = mask (_L); + static const mask alpha = mask (_U | _L); + static const mask digit = mask (_N); + static const mask xdigit = mask (_X | _N); + static const mask space = mask (_S); + static const mask print = mask (_P | _U | _L | _N | _B); + static const mask graph = mask (_P | _U | _L | _N); + static const mask cntrl = mask (_C); + static const mask punct = mask (_P); + static const mask alnum = mask (_U | _L | _N); #if __cplusplus >= 201103L - static const mask blank = space; + static const mask blank = mask (space); #endif };