From owner-freebsd-current@FreeBSD.ORG Sun Dec 1 00:33:19 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 84347E1A; Sun, 1 Dec 2013 00:33:19 +0000 (UTC) Received: from mail-qa0-x22c.google.com (mail-qa0-x22c.google.com [IPv6:2607:f8b0:400d:c00::22c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 30DFD1444; Sun, 1 Dec 2013 00:33:19 +0000 (UTC) Received: by mail-qa0-f44.google.com with SMTP id i13so3083128qae.10 for ; Sat, 30 Nov 2013 16:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=1yxCWMpZQgsom/cnYvh8R7hDXC1nd3mLBohnHiuqsns=; b=ykEkYhqPJWYe4VioZJcwqKBZQckZnwBQJuSWawGoCEbDuX1rsxi/ZlGR4Zcqv+dveB qPi5iIJBfBCs1t8nE8n0BYZfGQPlp8aK3aafzQktgITvUj0miF4pyCVjPDDBeWlHsnxR 3tyYKh0EN8XTVOEHBAkfGVeNzjYyalV+FF9xrHVDUOYgZ7EUsvsME30Fnrsdk2YQH7/b 77EyvwruMnMGWCR8yfznFtPGtPHk5ZGQH0SYLLtfTDNbQeN5gd7l0zOFmy8iZg126wNu lUlg0EeU7jsFkbJ5wWi+S+rPdvepT5/bfB/CU22zxsuhWevZHFpEN0K8TUrVdNohwZCB PvhA== MIME-Version: 1.0 X-Received: by 10.229.49.8 with SMTP id t8mr99912267qcf.21.1385857997212; Sat, 30 Nov 2013 16:33:17 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.224.53.200 with HTTP; Sat, 30 Nov 2013 16:33:17 -0800 (PST) In-Reply-To: References: <20131130135616.GA59496@kib.kiev.ua> Date: Sat, 30 Nov 2013 16:33:17 -0800 X-Google-Sender-Auth: lzqRF1qjiayRik2OiuCEt2CBzpA Message-ID: Subject: Re: RFC: (Unconditionally) enable -fno-strict-overflow for kernel builds From: Adrian Chadd To: Dimitry Andric Content-Type: text/plain; charset=ISO-8859-1 Cc: Konstantin Belousov , "current@freebsd.org" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Dec 2013 00:33:19 -0000 On 30 November 2013 15:25, Dimitry Andric wrote: > On 30 Nov 2013, at 14:56, Konstantin Belousov wrote: >> I propose to unconditionally add the switch -fno-strict-overflow to the >> kernel compilation. See the patch at the end of message for exact change >> proposed. >> >> What does it do. It disallows useless and counter-intuitive behaviour of >> the compiler(s) for the signed overflow. Basically, the issue is that >> the C standard left signed overflow as undefined to allow for different >> hardware implementation of signess to be used for signed arithmetic. >> De-facto, all architectures where FreeBSD works or have a chance to be >> ported, use two-complement signed integer representation, and developers >> intuition is right about it. > > I think this is quite a misrepresentation. Any C compiler is free to do > whatever it wants whenever it encounters undefined behavior. Some > behavior is undefined in the C standards, so compilers can do a better > job at optimization. > > If the optimized code fails to do what the programmer thinks it does, it > is almost always the programmer's fault, excluding actual compiler bugs > (which are unavoidable, as all software has bugs). > > Basically, if you rely on undefined behavior, you are inventing your own > de facto language, which is *not* C. That is fine with me, but let's > not pretend the FreeBSD kernel is written in C then. :-) Are you able to have clang/llvm/gcc tell us where/when code is relying on undefined behaviour? So we can, like, fix them? If there was a way to lint this stuff then yes, please lint it. Otherwise we don't have the tools to know whether we're doing sane things or not. (Same with things like strict aliasing..) -adrian