From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 97BC6385B835 for ; Fri, 10 Apr 2020 14:59:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 97BC6385B835 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1B2B51E5F9; Fri, 10 Apr 2020 10:59:01 -0400 (EDT) Subject: Re: [PATCH] Undefined behavior reported in copy_bitwise To: krokus , gdb-patches@sourceware.org References: From: Simon Marchi Message-ID: <2ea2b4f7-b9f2-99c4-b301-e35d9f265690@simark.ca> Date: Fri, 10 Apr 2020 10:59:00 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Apr 2020 14:59:02 -0000 On 2020-04-09 7:50 p.m., krokus via Gdb-patches wrote: > gdb version 9.1, built with clang 8.0.0 on Ubuntu 18.04 (x86_64); > --enable-ubsan (for clang's undefined behavior sanitizer) > > Executing command; `maint selftest copy_bitwise` bombs in runtime error: > ../../gdb/utils.c:3432:28: runtime error: left shift of negative value -1 > > Closer look reveals the offending shift: `(~0 << nbits)`, apparently 0 > is treated as signed int, resulting in negative complement. Explicitly > stating it unsigned 0U fixes it and the `copy_bitwise` test passes > ok. > > patch -p1: > ```````` > --- gdb/utils.c 2020-04-09 18:41:03.339065535 -0500 > +++ gdb/utils.c 2020-04-09 18:41:24.427064851 -0500 > @@ -3429,7 +3429,7 @@ > buf |= *source << avail; > > buf &= (1 << nbits) - 1; > - *dest = (*dest & (~0 << nbits)) | buf; > + *dest = (*dest & (~0U << nbits)) | buf; > } > } > ```````` > Thanks. I'll try to reproduce it, but at first sight it seems fine. Could you please provide a ChangeLog entry for this, with the name and email address you'd like to have in there? See the gdb/ChangeLog file for examples. Simon