From patchwork Fri Sep 28 23:20:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Santos X-Patchwork-Id: 1527621 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 962693FDAE for ; Fri, 28 Sep 2012 23:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758894Ab2I1X2Q (ORCPT ); Fri, 28 Sep 2012 19:28:16 -0400 Received: from nm29.bullet.mail.ne1.yahoo.com ([98.138.90.92]:45404 "HELO nm29.bullet.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1758877Ab2I1X2O (ORCPT ); Fri, 28 Sep 2012 19:28:14 -0400 X-Greylist: delayed 381 seconds by postgrey-1.27 at vger.kernel.org; Fri, 28 Sep 2012 19:28:14 EDT Received: from [98.138.90.52] by nm29.bullet.mail.ne1.yahoo.com with NNFMP; 28 Sep 2012 23:21:51 -0000 Received: from [66.94.237.96] by tm5.bullet.mail.ne1.yahoo.com with NNFMP; 28 Sep 2012 23:21:51 -0000 Received: from [127.0.0.1] by omp1001.access.mail.mud.yahoo.com with NNFMP; 28 Sep 2012 23:21:51 -0000 X-Yahoo-Newman-Id: 459197.54466.bm@omp1001.access.mail.mud.yahoo.com Received: (qmail 81570 invoked from network); 28 Sep 2012 23:21:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=att.net; s=s1024; t=1348874511; bh=4e+EQ12fNJuPF24DeCzlQkVWaSg0fPCDvGIyReNXmvU=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=g/gP+Ky95NH6sxDQZ3eA1CH6YEgaI+C2w4Z3GMkbb3zt2b3CB6bDFNB1GU14s18R5YQ8U3WInE+nR0fw72CKGyDmytfwxsKW448NGHjxfe8UFMnoAunYjPSKMW5JkrJMmoXUP7eqYsOnmgfSfSSTDTQ6sggnCiQvEZx/SYoUSos= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 3cPF7fwVM1lt5C9.3gnqpV2kolrXDZeDAzpm6jno3VZMmJe d1P0V16WNBbO8bYkftcu5h8VdaquNeoJMd0H327.PN4JG0oveiNqwMsAJ0zw RKH.nR_FBA9IQl6MdIrK8Sj52OYT9PqfkrYK7fhFaxnk1jAuejSYm2T0TKv5 iJvGcs5pNSekTZhRrIw4An8.ztfl0E6oRfIKyyft7GHv_vb641_Mkzrj3evq zyncwbzuGYGIfcc8gZxw5AXztkRcCz.h6QC18cd07xcx_mtSwEeklmWy.W7Q L74svyZXCvINdKM77QjX.Duwm19Bt3FmzG_vIAFKKRNLUtFj3AymgpRXl_mA _Rvep9aERNiWeW6DyKDs2.xdJJyAAK3xiWDXpAkzNwKDC8dIgENmAoFFJEWj XbG1NCadmxfv0GcSuoOpAwE1JBnUpRfJdUWJxr.GJdaod31q2ZgcE X-Yahoo-SMTP: xXkkXk6swBBAi.5wfkIWFW3ugxbrqyhyk_b4Z25Sfu.XGQ-- Received: from localhost.localdomain (danielfsantos@99.70.244.137 with login) by smtp106.sbc.mail.mud.yahoo.com with SMTP; 28 Sep 2012 23:21:51 +0000 UTC From: Daniel Santos To: LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , Daniel Santos , David Daney , David Howells , Joe Perches , Konstantin Khlebnikov , linux-sparse@vger.kernel.org, Michel Lespinasse , Paul Gortmaker , Pavel Pisa , Peter Zijlstra , Steven Rostedt Subject: [PATCH 10/10] bug.h: Add gcc 4.2+ versions of BUILD_BUG_ON_* macros Date: Fri, 28 Sep 2012 18:20:11 -0500 Message-Id: <1348874411-28288-11-git-send-email-daniel.santos@pobox.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1348874411-28288-1-git-send-email-daniel.santos@pobox.com> References: <1348874411-28288-1-git-send-email-daniel.santos@pobox.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org BUILD_BUG_ON42(arg) BUILD_BUG_ON_CONST42(arg) Prior to gcc 4.2, the optimizer was unable to determine that many constant values stored in structs were indeed compile-time constants and optimize them out. Sometimes, it will find an intergral value to be a compile-time constant, but fail to perform a bit-wise AND at compile-time. These two macros provide a mechanism to perform these build-time checks, but not break on older compilers where we already know they can't be checked at compile time. For specific details, consult the doc comments for BUILD_BUG_ON_CONST. These macros are used in the generic rbtree code. Signed-off-by: Daniel Santos --- include/linux/bug.h | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index e30f600..d14c23c 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -2,6 +2,7 @@ #define _LINUX_BUG_H #include +#include enum bug_trap_type { BUG_TRAP_TYPE_NONE = 0, @@ -129,6 +130,41 @@ struct pt_regs; #define BUILD_BUG_ON_NON_CONST(exp) #endif + +#if GCC_VERSION >= 40200 +/** + * BUILD_BUG_ON_NON_CONST42 - break compile if expression cannot be determined + * to be a compile-time constant (disabled prior to + * gcc 4.2) + * @exp: value to test for compile-time constness + * + * Use this macro instead of BUILD_BUG_ON_NON_CONST when testing struct + * members or dereferenced arrays and pointers. Note that the version checks + * for this macro are not perfect. BUILD_BUG_ON_NON_CONST42 expands to nothing + * prior to gcc-4.2, after which it is the same as BUILD_BUG_ON_NON_CONST. + * However, there are still many checks that will break with this macro (see + * the Gory Details section of BUILD_BUG_ON_NON_CONST for more info). + * + * See also BUILD_BUG_ON_NON_CONST() + */ +# define BUILD_BUG_ON_NON_CONST42(exp) BUILD_BUG_ON_NON_CONST(exp) + +/** + * BUILD_BUG_ON42 - break compile if expression cannot be determined + * (disabled prior to gcc 4.2) + * + * This gcc-version check is necessary due to breakages in testing struct + * members prior to gcc 4.2. + * + * See also BUILD_BUG_ON() + */ +# define BUILD_BUG_ON42(arg) BUILD_BUG_ON(arg) +#else +# define BUILD_BUG_ON_NON_CONST42(exp) +# define BUILD_BUG_ON42(arg) +#endif /* GCC_VERSION >= 40200 */ + + #endif /* __CHECKER__ */ #ifdef CONFIG_GENERIC_BUG