Received: from eggs.gnu.org ([140.186.70.92]:53605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJnau-0002Pl-9M for qemu-devel@nongnu.org; Fri, 28 Oct 2011 10:39:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJnas-0006uS-U9 for qemu-devel@nongnu.org; Fri, 28 Oct 2011 10:39:40 -0400 From: Markus Armbruster References: <1319487523-19978-1-git-send-email-sw@weilnetz.de> <20111026125431.GC27267@stefanha-thinkpad.localdomain> Date: Fri, 28 Oct 2011 16:39:32 +0200 In-Reply-To: (Stefan Hajnoczi's message of "Fri, 28 Oct 2011 13:41:47 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-trivial@nongnu.org, Stefan Weil , qemu-devel@nongnu.org Stefan Hajnoczi writes: > On Fri, Oct 28, 2011 at 12:07 PM, Markus Armbruster w= rote: >> Stefan Hajnoczi writes: >> >>> On Fri, Oct 28, 2011 at 9:59 AM, Markus Armbruster = wrote: >>>> Stefan Hajnoczi writes: >>>> >>>>> On Fri, Oct 28, 2011 at 8:40 AM, Markus Armbruster wrote: >>>>>> Stefan Hajnoczi writes: [...] >>>>>>> I would replace assert(3) with abort(3). =C2=A0If this ever happens= the >>>>>>> program is broken - returning 0 instead of an undefined value doesn= 't >>>>>>> help. >>>>>> >>>>>> Why is it useful to make failed assertions stop the program regardle= ss >>>>>> of NDEBUG only when the assertion happens to be "can't reach"? >>>>> >>>>> My point is that it should not be an assertion. =C2=A0The program has= a >>>>> control flow path which should never be taken. =C2=A0In any "safe" >>>>> programming environment the program will terminate with a diagnostic. >>>> >>>> In the not-so-safe C programming environment, we can disable that safe= ty >>>> check by defining NDEBUG. >>>> >>>> Disabling safety checks is almost always a bad idea. >>> >>> There's a difference in a safety check that slows down the system and >>> a failure condition where the program must terminate. >>> >>> assert(3) is for safety checks that can be disabled because they may >>> slow down the system. >>> >>> I've been saying that assert(3) isn't appropriate here because the >>> program can't continue and there's no check we can skip here. >> >> a. Program can't continue: same for pretty much any assertion anywhere. >> >> b. There's no code we can skip here: calling abort() is code. >> >> What I've been saying is >> >> 1. Attempting to distinguish between safety checks that are safe to skip >> and failure conditions that aren't is a fool's errand. =C2=A0If a check = is >> safe to skip it's not a safety check by definition. =C2=A0It's debugging >> code, perhaps. >> >> 2. Optionally disabling "expensive" safety checks should be done based >> on measurements, if at all. =C2=A0Arbitrarily declaring all "can't reach" >> checks "inexpensive" and all other assertions "expensive" isn't >> measuring, it's guesswork. > > I'm tempted to continue the thread but at the end of the day we just > need to make the function compile with -NDEBUG. Using abort(3) or Do we? Anyone crazy^Wadventurous enough to compile with -DNDEBUG should be capable of configure --disable-werror. > qemu_abort() would be the smallest and IMO sanest change, but if it's > something else that's fine.