Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1027667pxb; Fri, 15 Apr 2022 18:50:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjdPIIuSAm/Jvx+6rPfUv+S0+bPNG3GM16FooG3BXqCTy2A2aPnXIgPoq0hlC//Ij+Zp4j X-Received: by 2002:a63:3f8f:0:b0:386:3116:a1f3 with SMTP id m137-20020a633f8f000000b003863116a1f3mr1320489pga.136.1650073842233; Fri, 15 Apr 2022 18:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650073842; cv=none; d=google.com; s=arc-20160816; b=SsNBLyNvpi+n0UtU927tpgNITA5TMega9UR9v0IQGT+sGxGCY8swy0JbyzXrjh2EJv 9fM4JAM8ArakPwWXqe3fgQ7KZLPVti8Lkm9GzNF94Usx2TH0lPGvVIbUg76XOFhXC56c HM8yhRQ30Ljf39nzE0Kmk+/J9u893muAE2DogRRe+qMs7MW0yFx4S4C+OSkxDiMYIU7J u5j9PewN47WGGimyKDzD61WQ2U5n5LFgvzP+yGmEg+cvrfD6aev3Go8+up73WlvYkZx9 BNLQSaUQUyky85MM3VGSNv0vGhgZoAPpGKnxlpsjHeCr3SQQ61Wr9oL2TPAT/xzYIUiR aNAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+iRSXHQlt9lmhOSBYrvMuVQHw2ElrWncN2mrge5/yQ4=; b=WnHmZ05Jrtn+PzU7IHgJuQ9D0UauulETKxkuD30I70qtFvdlyL1WAUj0KL4/51VvOv B7Q+S6GuTtdQFWKE2vpn70vsLYm/tVt4rBhRbPXHqh1DPOqhlbpsagWqt2i/B3/ecbgV kOP96M1oDC2GL6AGZ1W06qoUanvbwjz8mYFXdpomp3md8gcmWkF6hW4M5NsbfHN8DehU UaKQEEXok6Dk6nw+OrZqwGwY41d4DB+Zbb5OX0gawZxozCWV5NOfbtGOG1QbOtUSYaVX T07lXVonKKohdVksiUkas6RysBCaGP49eAsX7WN1X+/zgFfNeeD85or8zlOEoFP0ynI8 0avA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=D4UH8lPR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q13-20020a63504d000000b003816043ee3asi2832883pgl.47.2022.04.15.18.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:50:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=D4UH8lPR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24EF3196119; Fri, 15 Apr 2022 18:12:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355850AbiDNP70 (ORCPT + 99 others); Thu, 14 Apr 2022 11:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354687AbiDNPlG (ORCPT ); Thu, 14 Apr 2022 11:41:06 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B1CDFD5D for ; Thu, 14 Apr 2022 08:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+iRSXHQlt9lmhOSBYrvMuVQHw2ElrWncN2mrge5/yQ4=; b=D4UH8lPRYK29ybcCYqOCJLNd3u Q4+bXU/1kTRxIE7w0/mHcMkrSCPJLapr2iCBsE80oGx3aeLmDbXhfKP6Fkzs31vlY0FP+8YSnLnGA psKONhCK8ST+iduJ2Cti5dc3/6xuzu4tUyrIHXDJUf3AQJwRNtqCqg/sZFQdBxJcqgIJGbD60Bxdi oaS0jyseexJ2bmKgeTcR1u426IWL9UnLdxAAKWVNxQBpyvSlDMHvhbL3rxBlCURpBfsccZHjsU40U p/tYya+kBtsh2ywbDnxGs9FU+WwVs7jWaPh4lOoJ1W1BUap47SGA8TWNcD30kSVuVAPp+UnWSnl0A I59pSpRQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nf1HL-0052yG-BV; Thu, 14 Apr 2022 15:21:03 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 578083002DE; Thu, 14 Apr 2022 17:21:01 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3B94F2057AAE7; Thu, 14 Apr 2022 17:21:01 +0200 (CEST) Date: Thu, 14 Apr 2022 17:21:01 +0200 From: Peter Zijlstra To: Christophe de Dinechin Cc: trivial@kernel.org, Ben Segall , "Michael S. Tsirkin" , Andrew Morton , Steven Rostedt , Ingo Molnar , Mel Gorman , Dietmar Eggemann , Vincent Guittot , Paolo Bonzini , Daniel Bristot de Oliveira , Jason Wang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Zhen Lei , Juri Lelli Subject: Re: [PATCH 1/3] sched/headers: Fix compilation error with GCC 12 Message-ID: References: <20220414150855.2407137-1-dinechin@redhat.com> <20220414150855.2407137-2-dinechin@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220414150855.2407137-2-dinechin@redhat.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 14, 2022 at 05:08:53PM +0200, Christophe de Dinechin wrote: > With gcc version 12.0.1 20220401 (Red Hat 12.0.1-0) (GCC), the following > errors are reported in sched.h when building after `make defconfig`: > Rewrite the definitions of sched_class_highest and for_class_range to > avoid this error as follows: > > 1/ The sched_class_highest is rewritten to be relative to > __begin_sched_classes, so that GCC sees it as being part of the > __begin_sched_classes array and not a distinct __end_sched_classes > array. > > 2/ The for_class_range macro is modified to replace the comparison with > an out-of-bound pointer __begin_sched_classes - 1 with an equivalent, > but in-bounds comparison. > > In that specific case, I believe that the GCC analysis is correct and > potentially valuable for other arrays, so it makes sense to keep it > enabled. > > Signed-off-by: Christophe de Dinechin > Signed-off-by: Christophe de Dinechin > --- > kernel/sched/sched.h | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 8dccb34eb190..6350fbc7418d 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -2193,11 +2193,18 @@ const struct sched_class name##_sched_class \ > extern struct sched_class __begin_sched_classes[]; > extern struct sched_class __end_sched_classes[]; > > -#define sched_class_highest (__end_sched_classes - 1) > +/* > + * sched_class_highests is really __end_sched_classes - 1, but written in a way > + * that makes it clear that it is within __begin_sched_classes[] and not outside > + * of __end_sched_classes[]. > + */ > +#define sched_class_highest (__begin_sched_classes + \ > + (__end_sched_classes - __begin_sched_classes - 1)) > #define sched_class_lowest (__begin_sched_classes - 1) > > +/* The + 1 below places the pointers within the range of their array */ > #define for_class_range(class, _from, _to) \ > - for (class = (_from); class != (_to); class--) > + for (class = (_from); class + 1 != (_to) + 1; class--) Urgh, so now we get less readable code, just because GCC is being stupid? What's wrong with negative array indexes? memory is memory, stuff works.