From patchwork Wed Oct 31 09:30:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 12628 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 86F9E23F56 for ; Wed, 31 Oct 2012 09:30:58 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 154E7A18FBA for ; Wed, 31 Oct 2012 09:30:57 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so836562iag.11 for ; Wed, 31 Oct 2012 02:30:57 -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=3gUUpNg3lrWzC6OJih0g99h6Bb5jOnS1uWKQBl09gKY=; b=KU4IM3jt1M/xAixd7tvP6mqMhzSWwdOgPmJ57mmgIGIw80PF595Gvf511n4AXyIXzh gUchQnmZG/Sui559i0lr9O/mf+I3vsHrlUOvawlLs41gBEtFQhcD6IZSrMCqHr3PKtrk 4p/++X2nyEQJQwgf+/7H3j5WMKDbb+JUCnQCTwloEfVG1lo27L7Asq2YEo5kHcosaRAY jKDlog/XVxPN9pWB8UX3VuH6TO4veVblAgRivwzpes+9hpCll+IElOehlghIUfAwjmq5 rfB5qNIWKTv2+6wIFR77J5SO3KNRCM4bEQ1hPgUpZwMJscwyuMGMD+aFeVpTytjQeFkc 58Rg== Received: by 10.50.213.34 with SMTP id np2mr482132igc.57.1351675857459; Wed, 31 Oct 2012 02:30:57 -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 n20csp590370igt; Wed, 31 Oct 2012 02:30:56 -0700 (PDT) Received: by 10.181.13.194 with SMTP id fa2mr1317492wid.10.1351675855713; Wed, 31 Oct 2012 02:30:55 -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 c28si1782350wep.30.2012.10.31.02.30.55 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 02:30:55 -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 1TTUdL-0005vD-L2; Wed, 31 Oct 2012 09:30:47 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , Blue Swirl , Paolo Bonzini , malc Subject: [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour Date: Wed, 31 Oct 2012 09:30:47 +0000 Message-Id: <1351675847-22740-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQlC4QZSwY33HqLttPGfswnetx1cocNN/2dUNdeifOZkXiauAas+Nz0RBiE9YPYKDuTnfAzr Add a section to HACKING saying which version of the C spec we use and describing the bits of implementation defined C compiler behaviour which C code in QEMU is allowed to rely on. Signed-off-by: Peter Maydell --- HACKING | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/HACKING b/HACKING index 89a6b3a..6654d33 100644 --- a/HACKING +++ b/HACKING @@ -123,3 +123,23 @@ 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. C standard, implementation defined and undefined behaviors + +C code in QEMU should be written to the C99 language specification. A copy +of the final version of the C99 standard with corrigenda TC1, TC2, and TC3 +included, formatted as a draft, can be downloaded from: + http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf + +The C language specification defines regions of undefined behavior and +implementation defined behavior (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 behaviors 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)