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: 12576 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1090323F56 for ; Tue, 30 Oct 2012 15:09:37 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id A4095A184FA for ; Tue, 30 Oct 2012 15:09:36 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so510001iej.11 for ; Tue, 30 Oct 2012 08:09:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=VnEHsA5UJ4MJNSO0UGk1xg56VA3SZqdShexT9NW6rPI=; b=IjVbDKRVq1eCmHycHXp33+aR1CO3LUsY7W5DmrtKXHf9nREElieYfuUlmoqilU3aue ObYosbc1op/jEkIcS4Q4Ikb8c5qyVlzrYvFl0rL6ucODE+y/6xKnkhGhdCRmEsj1tLG5 192SlyZNXvGYAH5xCiaUgBgoSZQ5H8xo155N83Txel7zth23+dhNFosWe2QWb3IsBpi3 N4kJEc7+EDvRE8gzTt7DzIL685/MSJOrE2oWelqfpb2QlIzQmb0gsJqUyRWMGjgKqeCW 00QWAEMiXbXmnMnfi+EXvcOddtJM2ZBVzN5/v5hMu9g0s04LPpm44ahxoH4YdCeDj0OI F1ew== Received: by 10.50.10.199 with SMTP id k7mr1719662igb.70.1351609776056; Tue, 30 Oct 2012 08:09:36 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp429276igt; Tue, 30 Oct 2012 08:09:35 -0700 (PDT) Received: by 10.180.8.234 with SMTP id u10mr2494609wia.17.1351609774614; Tue, 30 Oct 2012 08:09:34 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id q38si512848wen.148.2012.10.30.08.09.33 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 08:09:34 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk 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 Cc: patches@linaro.org, Anthony Liguori , Blue Swirl , Paolo Bonzini Subject: [PATCH] HACKING: List areas where we may rely on impdef C behaviour 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-Gm-Message-State: ALoCoQnmtAe64/HYLW1sFUGC/0JTrzvegRBNU49ou6PvwDGQMfE+eQncZgxCSbsnlyRWT52occ1F 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)