From patchwork Sun Oct 28 20:57:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Santos X-Patchwork-Id: 1659051 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 90A9DDFF3D for ; Sun, 28 Oct 2012 20:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755772Ab2J1U5Z (ORCPT ); Sun, 28 Oct 2012 16:57:25 -0400 Received: from nm22-vm0.access.bullet.mail.sp2.yahoo.com ([98.139.44.178]:28899 "EHLO nm22-vm0.access.bullet.mail.sp2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755817Ab2J1U5S (ORCPT ); Sun, 28 Oct 2012 16:57:18 -0400 Received: from [98.139.44.106] by nm22.access.bullet.mail.sp2.yahoo.com with NNFMP; 28 Oct 2012 20:57:17 -0000 Received: from [98.138.84.183] by tm11.access.bullet.mail.sp2.yahoo.com with NNFMP; 28 Oct 2012 20:57:17 -0000 Received: from [127.0.0.1] by smtp105.sbc.mail.ne1.yahoo.com with NNFMP; 28 Oct 2012 20:57:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=att.net; s=s1024; t=1351457837; bh=ZPOE1CDHUmIEXzSGdsLslWWwb+5KB/hJiZxe9sFNgMM=; h=X-Yahoo-Newman-Id:Received:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=uWkPEuXCyA8N2m/g5NN5chtcgUwTFE16xyFy6vCsw2CdeVDiNvrKUdhpG44o9VmAoUEz4jZaRtTbwpRrFF7Q+WvmdVaWitY1NqgGbySvmCksAq/R1mwGNOSP960Y3Dy32c8M3r35GBmPJcZnw3B91aywcSx50eA6JfpMGHfq1O0= X-Yahoo-Newman-Id: 433701.16106.bm@smtp105.sbc.mail.ne1.yahoo.com Received: from localhost.localdomain (danielfsantos@99.70.244.137 with login) by smtp105.sbc.mail.ne1.yahoo.com with SMTP; 28 Oct 2012 20:57:17 +0000 UTC X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: iy4h88AVM1lutF90xHH1n1zqTEhgT_.bAz6vApvqNacXSDa nTGM7FdBv5Yv.nzBGDIqeIoSu2t9vTYjzRKf_DW6xK74bJldyLe8rbRJwQ0X tWUBrUHjfjop.5z3U3Tm0CVsV5ic8S4gFWPst8pio8t__LZXsBlnwLrfEmCm j9u1Ta0ZA7pAt2jNZKAMaEQUSlrBRNweHGx5PuRggMw1TjohP.ISfTUl6Mxe HoIhVLk54fMqCQDGLug4.WZssRn5c8VqjM4AyxBwbUhRPUXaLyvMCNQOqALO FERH2PMtwKomx4lCfPNl9zdsXV3NxnQa83Qi1LyEywWoS_vZqpCgFkfJbMCd XSTsFdmqwUHPtkT.HYn7utPwG9TENICUqf933M5zthWJgqmqbVvQsolD6iM3 hirpIr03mPChYZlmnvP5KPAbsyWKiTHYzvB_vg2yU7kmXItUcv_.XG7n_DIC LUk4H5kSdFp3N8UrIDpbGd.KlLv1H X-Yahoo-SMTP: xXkkXk6swBBAi.5wfkIWFW3ugxbrqyhyk_b4Z25Sfu.XGQ-- From: danielfsantos@att.net To: LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , Daniel Santos , David Daney , David Howells , Joe Perches , Josh Triplett , Konstantin Khlebnikov , linux-sparse@vger.kernel.org, Michel Lespinasse , Paul Gortmaker , Pavel Pisa , Peter Zijlstra , Steven Rostedt , Borislav Petkov , David Rientjes Subject: [PATCH v4 8/9] bug.h: Add BUILD_BUG_ON_MSG & _BUILD_BUG_INTERNAL Date: Sun, 28 Oct 2012 15:57:14 -0500 Message-Id: <1351457835-7553-8-git-send-email-daniel.santos@pobox.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1351457648-7453-1-git-send-email-daniel.santos@pobox.com> References: <1351457648-7453-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 Add BUILD_BUG_ON_MSG which behaves like BUILD_BUG_ON (with optimizations enabled), except that it allows you to specify the error message you want emitted as the third parameter. Under the hood, this relies on _BUILD_BUG_INTERNAL, which does the actual work and is pretty-much identical to BUILD_BUG_ON. Signed-off-by: Daniel Santos --- include/linux/bug.h | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index 6c38988..3bc1ddf 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -16,6 +16,7 @@ struct pt_regs; #define BUILD_BUG_ON_NOT_POWER_OF_2(n) #define BUILD_BUG_ON_ZERO(e) (0) #define BUILD_BUG_ON_NULL(e) ((void*)0) +#define BUILD_BUG_ON_MSG(cond, msg) (0) #define BUILD_BUG_ON(condition) (0) #define BUILD_BUG() (0) #else /* __CHECKER__ */ @@ -38,6 +39,27 @@ struct pt_regs; */ #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) +#define __BUILD_BUG_INTERNAL(condition, msg, line) \ + do { \ + extern void __build_bug_on_failed_ ## line \ + (void) __compiletime_error(msg); \ + __compiletime_error_fallback(condition); \ + if (condition) \ + __build_bug_on_failed_ ## line(); \ + } while (0) + +#define _BUILD_BUG_INTERNAL(condition, msg, line) \ + __BUILD_BUG_INTERNAL(condition, msg, line) + +/** + * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied + * error message. + * @condition: the condition which the compiler should know is false. + * + * See BUILD_BUG_ON for description. + */ +#define BUILD_BUG_ON_MSG(cond, msg) _BUILD_BUG_INTERNAL(cond, msg, __LINE__) + /** * BUILD_BUG_ON - break compile if a condition is true. * @condition: the condition which the compiler should know is false.