From patchwork Thu Jul 31 23:47:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 4659601 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 98F2E9F2B8 for ; Thu, 31 Jul 2014 23:47:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C749420170 for ; Thu, 31 Jul 2014 23:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D720920120 for ; Thu, 31 Jul 2014 23:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752332AbaGaXrl (ORCPT ); Thu, 31 Jul 2014 19:47:41 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:55347 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751322AbaGaXrj (ORCPT ); Thu, 31 Jul 2014 19:47:39 -0400 Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 45BBD17208C; Fri, 1 Aug 2014 01:47:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id pFAzuTUIJBEb; Fri, 1 Aug 2014 01:47:32 +0200 (CEST) X-Originating-IP: 173.246.103.110 Received: from jtriplet-mobl1 (joshtriplett.org [173.246.103.110]) (Authenticated sender: josh@joshtriplett.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id E7881172074; Fri, 1 Aug 2014 01:47:25 +0200 (CEST) Date: Thu, 31 Jul 2014 16:47:23 -0700 From: Josh Triplett To: akpm@linux-foundation.org, "J. Bruce Fields" , Alexander Viro , Christopher Li , Ingo Molnar , Jeff Layton , Michal Marek , Neil Brown , Steven Rostedt , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-sparse@vger.kernel.org Subject: [PATCH 1/5] Add __designated_init, wrapping __attribute__((designated_init)) Message-ID: <3130b0553b15518e3bef6d14c80280beed0f5ff9.1406850006.git.josh@joshtriplett.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP GCC 4.10 and newer, and Sparse, supports __attribute__((designated_init)), which marks a structure as requiring a designated initializer rather than a positional one. This helps reduce churn and errors when used with _ops structures and similar structures designed for future extension. Add a wrapper __designated_init, which turns into __attribute__((designated_init)) for Sparse or sufficiently new GCC. Enable the corresponding warning as an error. The following semantic patch can help mark structures containing function pointers as requiring designated initializers: @@ identifier I, f; type T; @@ struct I { ... T (*f)(...); ... } + __designated_init ; Signed-off-by: Josh Triplett --- Makefile | 3 +++ include/linux/compiler-gcc4.h | 4 ++++ include/linux/compiler.h | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/Makefile b/Makefile index f6a7794..83773c2 100644 --- a/Makefile +++ b/Makefile @@ -744,6 +744,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=strict-prototypes) # Prohibit date/time macros, which would make the build non-deterministic KBUILD_CFLAGS += $(call cc-option,-Werror=date-time) +# Disallow positional initialization of designated structs +KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) + # use the deterministic mode of AR if available KBUILD_ARFLAGS := $(call ar-option,D) diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 2507fd2..5cd3c26 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h @@ -85,4 +85,8 @@ #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600) #define __HAVE_BUILTIN_BSWAP16__ #endif + +#if GCC_VERSION >= 41000 || defined(__CHECKER__) +#define __designated_init __attribute__((designated_init)) +#endif #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index d5ad7b1..c2334b2 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -266,6 +266,11 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #define __always_inline inline #endif +/* Marks a struct as requiring designated initializers, never positional. */ +#ifndef __designated_init +#define __designated_init +#endif + #endif /* __KERNEL__ */ /*