From nobody Sat Nov 23 13:34:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1723208695; cv=none; d=zohomail.com; s=zohoarc; b=SA0+4pIDIPDyKwV9W4xgmDIRxgECy3VgRrw0aXRPz9TG3ZpdKxfcpsU6DdPO67Pj/Ec0Poc+G+YLhcMPZ667k7C5p6DytyRCvvxg5InKHvOOj2wCxgFAia0Cfli60jKd/W7KkeJFoUpjqhvMJAcTcUG+85ghBpnfHgPbvdzwElw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723208695; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IqFJjaRsLh2UOFChJjBNPbupmjhv4JBVg7GbkBcuHVg=; b=EG/++1UMSv0A0KwXE84WWJZOOTglvvY6bIyk/uCP8SiSvBZEbiFliQvCKI1YKF52x09ev/sX/9XKlD6dT3/v0qL8OCIos2GJr6wit15Y0eakcMjpZCtZfeHfZWhSobPxYHVjb3TWrWsQW+urL4ZgLrQfpiluv7qqIr7kZf4sJjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1723208695544965.8784301004675; Fri, 9 Aug 2024 06:04:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.774744.1185169 (Exim 4.92) (envelope-from ) id 1scPIB-0000gR-QG; Fri, 09 Aug 2024 13:04:27 +0000 Received: by outflank-mailman (output) from mailman id 774744.1185169; Fri, 09 Aug 2024 13:04:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1scPIB-0000gK-Nc; Fri, 09 Aug 2024 13:04:27 +0000 Received: by outflank-mailman (input) for mailman id 774744; Fri, 09 Aug 2024 13:04:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1scPI9-0000fj-Hs for xen-devel@lists.xenproject.org; Fri, 09 Aug 2024 13:04:25 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e644dc82-564f-11ef-8776-851b0ebba9a2; Fri, 09 Aug 2024 15:04:23 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a7a94478a4eso506971566b.1 for ; Fri, 09 Aug 2024 06:04:23 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9d437a5sm835020266b.101.2024.08.09.06.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 06:04:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e644dc82-564f-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723208663; x=1723813463; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IqFJjaRsLh2UOFChJjBNPbupmjhv4JBVg7GbkBcuHVg=; b=RPAiPK5yRVeS8Yvn++GWkh7szcfN16PDKTPj7/srXK82tEqbH+ViVDhEI/w5OxfBtX WSTRbPjkebkNXuaqX5JmVwySWKWKeUtUKJgcfFhgd2eEb2eTOIX/oqv0zpYsYGm1RDG2 qymG9QSFnDmPqUxXw+AtdnL96SFtSfGzC+i0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723208663; x=1723813463; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IqFJjaRsLh2UOFChJjBNPbupmjhv4JBVg7GbkBcuHVg=; b=NUsXZyTL8VU5iyIjP33QCKwL2KyXz8S0kuzFj8tCsZ7FTJ2Zg2FnXGQUiFctVbGMb8 oG0bjSd8+OEFmxgNK74fWqgFdYjwfdukG+Lug3sAbmJRsUjq8IgoXL1XJ2XCtUClipb8 9fDnn58XxOytiuRBb9vEvbTH+VZyw4fbBLqP4z74WVyd5DTjHGAaOvAXzI1XyZ7aOYrx dtx3UfY1Ztn8joGT3Xn1brlh1ZljVE2gmlyQ3M9cTp0qoeNSuL/wlkYA0pJkyy1eH+df r+uTFvjV3hT8ImmYEIoPJENRur+EKOA274NLMRM7VNL8euso3RcEeKjZr6UPt5m1fzhA O04g== X-Gm-Message-State: AOJu0YyXCLMpX+/zPjnFxQxF2AlOI3dhXokHnzRw756FSd9ddrAiT17X Qh7btZi01HNQe96kpg4eT5oPr8KaBXT2znHPJKnnrVE8sf6UDMxypWcXeifTUFcd/85k4185Iql B X-Google-Smtp-Source: AGHT+IF3a2+rZm0LdS0N84wcXkZrMpkLEAxaKgpUmxpZyi4RX8szJX/zSNJo8B4xU11eluiNC+6uLA== X-Received: by 2002:a17:906:f59f:b0:a77:db39:cc04 with SMTP id a640c23a62f3a-a8091ef4436mr453145066b.11.1723208662561; Fri, 09 Aug 2024 06:04:22 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [RFC PATCH] xen: Remove -Wdeclaration-after-statement Date: Fri, 9 Aug 2024 14:04:18 +0100 Message-ID: <20240809130418.10431-1-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723208697386116600 Content-Type: text/plain; charset="utf-8" This warning only makes sense when developing using a compiler with C99 support on a codebase meant to be built with C89 compilers too, and that's no longer the case (nor should it be, as it's been 25 years since C99 came out already). Signed-off-by: Alejandro Vallejo --- Yes, I'm opening this can of worms. I'd like to hear others people's thoughts on this and whether this is something MISRA has views on. If there's an ulterior non-obvious reason besides stylistic preference I think it should be documented somewhere, but I haven't seen such an explanation. IMO, the presence of this warning causes several undesirable effects: 1. Small functions are hampered by the preclusion of check+declare patterns that improve readability via concision. e.g: Consider a silly example like: /* with warning */ /* without warning */ void foo(uint8_t *p) void foo(uint8_t *p) { { uint8_t tmp1; if ( !p ) uint16_t tmp2; return; uint32_t tmp3; uint8_t tmp1 =3D OFFSET1 += *p; if ( !p ) uint16_t tmp2 =3D OFFSET2 += *p; return; uint32_t tmp3 =3D OFFSET3 += *p; tmp1 =3D OFFSET1 + *p; /* Lots of uses of `tmpX`= */ tmp2 =3D OFFSET2 + *p; } tmp2 =3D OFFSET2 + *p; /* Lots of uses of tmpX */ } 2. Promotes scope-creep. On small functions it doesn't matter much, but on bigger ones to prevent declaring halfway through the body needlessly increases variable scope to the full scope in which they are defined rather than the subscope of point-of-declaration to end-of-current-scope. In cases in which they can be trivially defined at that point, it also means they can be trivially misused before they are meant to. i.e: On the example in (1) assume the conditional in "with warning" is actually a large switch statement. 3. It facilitates a disconnect between time-of-declaration and time-of-use that lead very easily to "use-before-init" bugs. While a modern compiler can alleviate the most egregious cases of this, there's cases it simply cannot cover. A conditional initialization on anything with external linkage combined with a conditional use on something else with external linkage will squash the warning of using an uninitialised variable. Things are worse where the variable in question is preinitialised to something credible (e.g: a pointer to NULL), as then that can be misused between its declaration and its original point of intended use. So... thoughts? yay or nay? --- xen/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/Makefile b/xen/Makefile index 2e1a925c8417..288b7ac8bb2d 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -394,7 +394,7 @@ CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) +=3D -ffunction-sect= ions -fdata-sections =20 CFLAGS +=3D -nostdinc -fno-builtin -fno-common CFLAGS +=3D -Werror -Wredundant-decls -Wwrite-strings -Wno-pointer-arith -CFLAGS +=3D -Wdeclaration-after-statement -Wuninitialized +CFLAGS +=3D -Wuninitialized $(call cc-option-add,CFLAGS,CC,-Wvla) $(call cc-option-add,CFLAGS,CC,-Wflex-array-member-not-at-end) $(call cc-option-add,CFLAGS,CC,-Winit-self) --=20 2.45.2