From owner-freebsd-numerics@freebsd.org Tue Jan 1 06:21:04 2019 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 42C10148E378 for ; Tue, 1 Jan 2019 06:21:04 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic314-22.consmr.mail.ne1.yahoo.com (sonic314-22.consmr.mail.ne1.yahoo.com [66.163.189.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A6CC481B59 for ; Tue, 1 Jan 2019 06:21:03 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546323657; bh=VwEziizEt8F1cRofhoK4deHVEGZ3/ud2kCUPSIXdnBI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=Q0d1066gLX67ddbDooyesWVbmY9jiJX6Y+qfz+1gmjQppCgUr6XKflzeHT5B3fcvDKdLGmPta9e0a5UMVBu/RwOAIr3X/SSDQAPyYljQ03VDkLSVlhZsKX9mPO2I9Dy8dNPSwDCra9ZmVLMQSUrwPRSr3UCjrjQceSFYaB0eF5QrBPiapDjIwqK71ePsXMAh8M/EBwr6HHyEnLCnuUzV8KvbYPRkDy1ZDAozvCY1cAHFNbSMzmqDxv5ioaRaMsj+d/ri90NITfVt2Pj4dNE6Dyc5AOKJ+8fY39nEJOOjf8j5PHKPa5xERr+3OxqMUPSw3OldnG+vM/K9XElQ+Vut7Q== X-YMail-OSG: s7zxSp8VM1lhqUZcLCJOVujoYqq2HTTqw1lziYrtaYatoiF7PcXyuTi065qWagx iEwWsZTRZir_wTo1HRUz0fyYXlOlArCP80nA6qWLcAfXtq.tLtCg3_8i8z2lDaTvmFfncpzlS.Lx HtKyju_6B4yTmncIWxXfSAFxjQphZlgLHkVQSjhyxBPWvmB4WRho76jA.h5ZnTtaXqjEzOll_ES6 vkg8CnoxnPKlj4ZstV7YHdASzZOncCQCO7v8RAXOh04td8Rzzxe28g.f_jbMMzuLs94rT_eIDUY7 qEPFgx0WJOQCamCFe7pIP.Pp0jiBYPOYvue3C_5r9eJUcM1NX218T9OIewTZfBDD2lDeMf1QZhAU wj.EmuQfX.SobeBwdQ4tVgSayzLh3Y_dm.Vwf8PYwWTz2HDJjtE9dptR4XYau3fF2RrmunUcdYud B3cihIr7cxUohxNvUaRmSr8DPU3x67VOe8gSSmJlhxO2Pp.MrXEhaFlaYqJXU7585gigNy2zEuFG p6lmvB0MOgrnhFnK.4SO.KUBFZRBoFWAtd7K9hSgtk2vfZadhgK_ixtmc9oRywLRaUavawU.Rlji DyTCwL0TWXuTChEOgtEVIgo9XmFK64wFKm7Nz9Q8Olsz4ejqB1.YQQrqJb6lQSWUS1SjFJTdssGQ 0ZaSkFXvuvZ7VqgiscNgK1oSBQ3auzzVRcPRygPUOINyQzFcTJcCehPKGHwcTq1XKfb6grQTF914 3KBWsu0lwxkTAZK4nyGofsOG8JhmwvHbTOf7IlbRe3vjIOi5yKzzOKniDhyCHr5b1trWvBrqVJYV pT3n9Z0ihZdORL4YnlYdVmUvTUtvGFm7HKyVQSyiyeCsEJCEn3KQhnFJvoprTZBGmsiysXPYC3v2 30kELXTMPKEs0ZXl0q3vRhQHRFxfR4OXEbTImGUmm7YdGXhc0XOzrDNZdZTi3ud6URoRzS9MTD0y xHdGQNpddSzKvdY9pUUEwUOeDk730qGKBWUNnTiK9xoLpFACrrOPnrLpkobJ1umfQkTxsGHDL7Df _TTBeTPeWH7p2onwcNcXKAgT_mOSuu5xxQ5WdE51k Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Tue, 1 Jan 2019 06:20:57 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp412.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 05daaf1df328de8df0de7fb0328cff94; Tue, 01 Jan 2019 06:20:54 +0000 (UTC) Subject: Re: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) To: sgk@troutmask.apl.washington.edu Cc: freebsd-numerics@freebsd.org References: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> <20181231151904.GB823@troutmask.apl.washington.edu> <20181231152230.GC823@troutmask.apl.washington.edu> <06c8b6a2-ed26-f255-3947-c79b593a9dea@FreeBSD.org> <20190101045425.GA5767@troutmask.apl.washington.edu> <20190101055225.GA5982@troutmask.apl.washington.edu> From: Pedro Giffuni Message-ID: Date: Tue, 1 Jan 2019 01:20:53 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190101055225.GA5982@troutmask.apl.washington.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Rspamd-Queue-Id: A6CC481B59 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.93 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.93)[-0.933,0]; ASN(0.00)[asn:36646, ipnet:66.163.184.0/21, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jan 2019 06:21:04 -0000 On 1/1/19 12:52 AM, Steve Kargl wrote: > On Tue, Jan 01, 2019 at 12:14:38AM -0500, Pedro Giffuni wrote: >>> I'll defer to Bruce on this. My only comments are >>> 1) declarations belong at the top of the file where all declarations occur >> Modern standards let you declare variables within blocks. For style we >> do prefer to start the function with them but in this case we can't. > I'am aware of what modern standards allow. I'm also > aware of the code style of fdlibm, which I think > should be maintain. Well, the alternative is the musl-libc patch, which declares the variables upon use (twice). I think my patch is a little bit more acceptable. >>> 2) j is already declared as int32_t >> And it has to be a signed integer: we later check for negative values. > Yeah, I know. That's why I pointed out the collision. > >>> 3) uint32_t should be written as u_int32_t. >> No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the file >> consistently uses uint32_t. > Ah, no. e_pow.c uses u_int32_t on line 107. Duh! I completely misread, sorry about that I probably was still looking at musl-libc instead. Yes, we should use u_int32_t. > This would be easy > to see if all declarations are grouped together. In additional, > don't you need to include stdint.h to get uint32_t? Well, my patch did compile,  but I will match the existing style if the change is accepted/desired. > % grep uint32_t /usr/src/lib/msun/src/e_pow.c > % grep u_int32_t /usr/src/lib/msun/src/e_pow.c > u_int32_t lx,ly; > n = ((u_int32_t)hx>>31)-1; > > Code churn to placate lint for an event that cannot occur > seems dubious to me. > UBsan should be able to detect it. I think Undefined Behavior is considered a portability bug. There is no urgency but it is still a bug. Pedro.