From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E12663858D37 for ; Thu, 18 Apr 2024 10:01:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E12663858D37 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 E12663858D37 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=1713434523; cv=none; b=OwMtGxEqTuxROin0qj3J7cvmyR8EOlM1nbnxawjWIRHwWq/7RZURlezPYgC6ekbARhL2/5hsE1VmEb1FxLGrPvS5P5HkQzKYXh7uJu/XY6J6FS31Di3xI9ifanxCfguOjPLlU0MttwKzJyv67vSHK+uugFlgTfix1JLvwIyPljE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713434523; c=relaxed/simple; bh=Egk6OBDpm7Pu3DAq60JR3IiJx40WZcw2k12B67pwksg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Dsi0bwd/CMLbUi7OGJnZWiCYQxkV3TfZzxPO+1ifIxRLNu1MHK/nOK2V1SEMRBpXMiX+VvOWgRSGqie5qib+jsucyozGzxHUmY2omZvi6St1LoP90g/GODN44QrXK0d596gucF9DXzYtI9tX/Gm8rxcGcxABGOOsftubuqfBI28= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713434512; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=gn6yvn424nPf+b3nuvHuy0p6TqT0qw9Doj5gMz0zs1Y=; b=V6O2Z0+bf7iFVV3y9GvbohV4tl1A+oGNB4K3pZpqWnJRu9O/TvCNnlZJwWv/RnMUFMf8rR m8Utu8QrgByHqTaUnIOgKWGBtqhrYCRjU+lSx6MzBS7yfOWAjTARwR1Yn7gKdLd13v1GgU J8HmhYnlzs9PgfuvP48YCnNwSp27Vrc= 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-470-mgRZqXmjON6OEHvqQoJAAA-1; Thu, 18 Apr 2024 06:01:48 -0400 X-MC-Unique: mgRZqXmjON6OEHvqQoJAAA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 DB4A31C05AE2; Thu, 18 Apr 2024 10:01:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CC33400E89; Thu, 18 Apr 2024 10:01:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 43IA1jVT1273473 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 18 Apr 2024 12:01:45 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43IA1jec1273472; Thu, 18 Apr 2024 12:01:45 +0200 Date: Thu, 18 Apr 2024 12:01:45 +0200 From: Jakub Jelinek To: Christophe Lyon Cc: Richard Biener , "Joseph S. Myers" , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libgcc: Fix up __divmodbitint4 [PR114755] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Thu, Apr 18, 2024 at 11:25:43AM +0200, Christophe Lyon wrote: > On Thu, 18 Apr 2024 at 09:37, Jakub Jelinek wrote: > > The following testcase aborts on aarch64-linux but does not on x86_64-linux. > > In both cases there is UB in the __divmodbitint4 implemenetation. > > When the divisor is negative with most significant limb (even when partial) > > all ones, has at least 2 limbs and the second most significant limb has the > > most significant bit clear, when this number is negated, it will have 0 > > in the most significant limb. > > Already in the PR114397 r14-9592 fix I was dealing with such divisors, but > > thought the problem is only if because of that un < vn doesn't imply the > > quotient is 0 and remainder u. > > But as this testcase shows, the problem is with such divisors always. > > What happens is that we use __builtin_clz* on the most significant limb, > > and assume it will not be 0 because that is UB for the builtins. > > Normally the most significant limb of the divisor shouldn't be 0, as > > guaranteed by the bitint_reduce_prec e.g. for the positive numbers, unless > > the divisor is just 0 (but for vn == 1 we have special cases). > > Just curious: could this have been caught by ubsan? (I don't know if > it knows about clz) ubsan does instrument clz, I don't remember right now if even libgcc is built with -fsanitize=undefined during bootstrap-ubsan, if it is, it probably should (but we didn't have this test in the testsuite). Jakub