From patchwork Tue Oct 30 15:09:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 195513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7F5C52C00A4 for ; Wed, 31 Oct 2012 02:10:00 +1100 (EST) Received: from localhost ([::1]:44358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTDS2-0001Ax-Fd for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 11:09:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTDRq-00019j-Ma for qemu-devel@nongnu.org; Tue, 30 Oct 2012 11:09:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTDRk-00024N-Ud for qemu-devel@nongnu.org; Tue, 30 Oct 2012 11:09:46 -0400 Received: from 38.0.169.217.in-addr.arpa ([217.169.0.38]:42279 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTDRk-00022t-ND for qemu-devel@nongnu.org; Tue, 30 Oct 2012 11:09:40 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TTDRW-0005YY-Uq; Tue, 30 Oct 2012 15:09:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2012 15:09:26 +0000 Message-Id: <1351609766-21335-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 217.169.0.38 Cc: Blue Swirl , Paolo Bonzini , Anthony Liguori , patches@linaro.org Subject: [Qemu-devel] [PATCH] HACKING: List areas where we may rely on impdef C behaviour X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a section to HACKING describing the bits of implementation defined C compiler behaviour which C code in QEMU is allowed to rely on. Signed-off-by: Peter Maydell --- Since the issue just came up. Have I missed anything off the list? HACKING | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/HACKING b/HACKING index 89a6b3a..1e17ac7 100644 --- a/HACKING +++ b/HACKING @@ -123,3 +123,19 @@ gcc's printf attribute directive in the prototype. This makes it so gcc's -Wformat and -Wformat-security options can do their jobs and cross-check format strings with the number and types of arguments. + +6. Implementation defined and undefined behaviours + +The C language specification defines regions of undefined behaviour and +implementation defined behaviour (to give compiler authors enough +leeway to produce better code). In general, code in QEMU should +follow the language specification and avoid both undefined and +implementation defined constructs. ("It works fine on the gcc +I tested it with" is not a valid argument...) However there are +a few areas where we allow ourselves to assume certain behaviours +because in practice all the platforms we care about behave in the +same way and writing strictly conformant code would be painful. +These are: + * you may assume that integers are 2s complement representation + * you may assume that right shift of a signed integer duplicates + the sign bit (ie it is an arithmetic shift, not a logical shift)