From patchwork Tue Nov 14 22:45:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 165131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2279250rwb; Tue, 14 Nov 2023 15:57:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGk+UIr1N459xt57EQ4zXtwe19hJPqrBY7EjKP2dllY1KkjqWnS1DB2LzkRerl12IAjVOzq X-Received: by 2002:a1f:a650:0:b0:4ac:7098:4992 with SMTP id p77-20020a1fa650000000b004ac70984992mr9594943vke.14.1700006266761; Tue, 14 Nov 2023 15:57:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700006266; cv=pass; d=google.com; s=arc-20160816; b=qRBtsLZ8oHJcZkQwIuZxvBWgbAcngJAhxZ4f2JG1YkgW9wxlq8AmYeoSBslVmdaqZu mLltE4JNGXAIs2mMKF1YdI8lVig3NbMGUvt7fsPVz0BX2WA3pgSsCookcwNsz5XHyxVu MuZDgkyPESZx3s3/KmpH0TD0Xtkyynu+3dVzWoebbL8zC/lnUhz+GYEgCp7gjb83S19M SJXuWt7Ept487JBGG7p6n4E4CTS+FE1g+Y2K3WlnR2uZ5u2Ts9z0B5JQ0oWwZQ0kTJSg EbDVtuJFTyt17y5lcAn6z9PvywDjlWdC17k3reRf5r0BFm7Y5eBin2pWUbQ9xxopGKEu 1u5A== 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=JPbKLzIohvbLtMMf8GAmjDT2crgTPvzh3+O+5dwKZ2A=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=qMinxpSHgqm5nqWV8vnh7ELAQk1iUAvhOmjFvDHZf4QpREgIEZiLGykSe4bnMEUpjo PKZGLPhgI5/cERHrvz21tRAKgedEa2biJVHal8RyoehPobh2Rj8B7496K5vaToeGpxJW S7ecODhMrhbi38RyPw1ki3r7A8oeuC5oT/jMdGba3EmdYIGwL/XAgkSwu7W+ZBpAWE6V axQnSMX7uFz9MW3w/KoB1pJYVPxjmaRW96nfCQqHj5r8hDjjVuBRC9rLSQYDO3PQodzd CpGiXJwLxvbdOkSwz3gINTz4Vxhtjf3/0TGVfDHatsWM8mVFWsqGLw0FEy51nw5ctwdw i00g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="MS/dE8+l"; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q19-20020a05622a04d300b0041981d576b4si8043894qtx.733.2023.11.14.15.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 15:57:46 -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=@redhat.com header.s=mimecast20190719 header.b="MS/dE8+l"; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2EE6385AC27 for ; Tue, 14 Nov 2023 22:46:09 +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 AA97B3858D37 for ; Tue, 14 Nov 2023 22:45:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA97B3858D37 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 AA97B3858D37 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=1700001946; cv=none; b=Iu1+xMXTj6WhwB+U+Yw5VWnTSaDmdJeTkBSK1CVHY57tZ7wwjSGAgHUpG5O5ciY3WddNuaPwztPWjYgzVZXKOVFOgO8BScg6dgfqXw7diPK76AnM0UcpqGupwcvjAfY9aO/8HR6+RnRuLixpATkeWA7DIU6KSJQHuyna9+yuyCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700001946; c=relaxed/simple; bh=rIYX4m09nmUUgEAejiV3EOL5TqmO7h5LNNOX7Aip89k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Kv8BronLFTl3MS//M90xktZohCjsxeQWQFsuWXPbGkh3y32/46dqLAi0aRBNhb2PJzWWht90XIG6mfhGpVCynwGaX7mE5IEEGpp+Jo7f+XIYxvbEYkP12H5Z/Py/vtuRVMpkEgdOPEjrO9FzF1T+hDyTWE6apvhzAxNTns6GJ1E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700001942; 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=JPbKLzIohvbLtMMf8GAmjDT2crgTPvzh3+O+5dwKZ2A=; b=MS/dE8+lfCZ/D60MAV9nzKF9N4oKRfThqKP63S0TeGOkoCiOGNFBZn8o6XU8aW0SKEY3wi JdLVawwqewOwqNnzP9j96oIuTeaCg7YY1lLk9XFvieomDmI1hVsEn+YCIo/bDDh4Rq3FLt TZVgn7yJLn7pnLGBDiFl7i0iQIbz2hg= 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-451-Q_tAlOKrNgSY7vDSBBiSuQ-1; Tue, 14 Nov 2023 17:45:40 -0500 X-MC-Unique: Q_tAlOKrNgSY7vDSBBiSuQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 7B7041C29EAD; Tue, 14 Nov 2023 22:45:40 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 467A125C0; Tue, 14 Nov 2023 22:45:40 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix uses of signed types with functions Date: Tue, 14 Nov 2023 22:45:23 +0000 Message-ID: <20231114224539.988344-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782585771165734973 X-GMAIL-MSGID: 1782585771165734973 Tested x86_64-linux. Pushed to trunk. Backports needed too. -- >8 -- In we pass the int __base parameter to our internal versions of functions, __bit_width and __countr_zero. Those functions are only defined for unsigned types, so we need to convert the base to unsigned. The base must be in the range [2,36] so we can mask off the low bits and then convert that to unsigned, so that we don't need to care about negative values becoming large unsigned values. libstdc++-v3/ChangeLog: * include/std/charconv (__from_chars_pow2_base): Convert base to unsigned for call to __countr_zero. (__from_chars_alnum): Likewise for call to __bit_width. --- libstdc++-v3/include/std/charconv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 6cb7fecff87..54632968f5a 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -465,7 +465,7 @@ namespace __detail // __glibcxx_assert((__base & (__base - 1)) == 0); // __glibcxx_assert(_DecOnly ? __base <= 8 : __base <= 32); - const int __log2_base = __countr_zero(__base); + const int __log2_base = __countr_zero(unsigned(__base & 0x3f)); const ptrdiff_t __len = __last - __first; ptrdiff_t __i = 0; @@ -517,9 +517,9 @@ namespace __detail __from_chars_alnum(const char*& __first, const char* __last, _Tp& __val, int __base) { - // __glibcxx_assert(!_DecOnly || __base <= 10); + // __glibcxx_assert(_DecOnly ? __base <= 10 : __base <= 36); - const int __bits_per_digit = __bit_width(__base); + const int __bits_per_digit = __bit_width(unsigned(__base & 0x3f)); int __unused_bits_lower_bound = __gnu_cxx::__int_traits<_Tp>::__digits; for (; __first != __last; ++__first) {