Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4367386ima; Mon, 4 Feb 2019 15:21:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IasCb4Lm9tanTxKKJNRPGrmGxoxohFb6arpuBYnZre9dtCJmXnaSOgQ2qkCO9QK2ees/Vjl X-Received: by 2002:a62:9f11:: with SMTP id g17mr1868575pfe.222.1549322513455; Mon, 04 Feb 2019 15:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549322513; cv=none; d=google.com; s=arc-20160816; b=L30FDT4VpzSNPOEdtdUBcU1ofoREalrVqBQBMD3U2jcFjN81TSCe5qx9BDjLFlPkVc CUJswbNw52qvXkyaR7f+j9kx4Cn5fP479uaRhBLkK+LlL0BmKgM67b5322Hl2ZDZB/Rq B1Yvvi/UQ4I+I++CVM78APiW39r2swFF6hu4UitmKsgX94ZtXX3if9jnrkaJwQ5dBO6b 2RLZ+BngM5GEJ85q7OUn3fjABBoQQV99d3Xg5r9axAAcKSIiQ4TgwbWg+129MHLI8A5w A7RkyzLnj3+rjtjy8/+Yxy2FQNf9fK0YQVUbTB5W5xQ1e4tPV9unDntEO4P0j12i2C3b mLzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=1fOpb5R2oFCRT+eHHK2vAmkjDNzRR0YEbUTlZcEr6Ng=; b=BRJwpCHDhe6LMayFP++KAiG76E02hE8Twv1E0R2xl3bW28RPw0+6dUNVHxr7FNvIPi q1U0uL6jZt2o3CHSulLPuC7SLiyJH+DhpKgcXPuFuTkoRVo2WFx1ruI4xUuo4uxNcCk6 p2J4RvwGW2np6ZVGzyCnn4qQfXuJe06y1AMqE2WaPyyyH5GkZOPs9liFyX0r38xHz+Wv U1YymjxRTQ1nblIKXABH0jDWonk3myTf1oi+NZF+LzLBY7pHkOP0V4T0afTi70HY32m5 hghf/k4x8H3TsaaxdctTCsYxhOeHHMVaOaCktPg1XIH5bSN5hwKeHStVmS0SiTX4ZrOl i2IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si1038073pgh.305.2019.02.04.15.21.37; Mon, 04 Feb 2019 15:21:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728487AbfBDXJS (ORCPT + 99 others); Mon, 4 Feb 2019 18:09:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59776 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726901AbfBDXJS (ORCPT ); Mon, 4 Feb 2019 18:09:18 -0500 Received: from X1 (c-24-6-103-156.hsd1.ca.comcast.net [24.6.103.156]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5392A986E; Mon, 4 Feb 2019 23:09:17 +0000 (UTC) Date: Mon, 4 Feb 2019 15:09:16 -0800 From: Andrew Morton To: Rasmus Villemoes Cc: Kees Cook , Nick Desaulniers , Masahiro Yamada , Luc Van Oostenryck , linux-kernel@vger.kernel.org Subject: Re: [PATCH] build_bug.h: add wrapper for _Static_assert Message-Id: <20190204150916.f29d782b27f096e6c4c6d6cf@linux-foundation.org> In-Reply-To: <20190203192401.29170-1-linux@rasmusvillemoes.dk> References: <20190203192401.29170-1-linux@rasmusvillemoes.dk> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 3 Feb 2019 20:24:00 +0100 Rasmus Villemoes wrote: > BUILD_BUG_ON() is a little annoying, since it cannot be used outside > function scope. So one cannot put assertions about the sizeof() a > struct next to the struct definition, but has to hide that in some > more or less arbitrary function. > > Since gcc 4.6 (which is now also the required minimum), there is > support for the C11 _Static_assert in all C modes, including gnu89. So > add a simple wrapper for that. > > _Static_assert() requires a message argument, which is usually quite > redundant (and I believe that bug got fixed at least in newer C++ > standards), but we can easily work around that with a little macro > magic, making it optional. > > For example, adding > > static_assert(sizeof(struct printf_spec) == 8); > > in vsprintf.c and modifying that struct to violate it, one gets > > ./include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(struct printf_spec) == 8" > #define __static_assert(expr, msg, ...) _Static_assert(expr, "" msg "") > > godbolt.org suggests that _Static_assert() has been support by clang > since at least 3.0.0. > It would be (very) nice to actually use this macro in a few places so it gets its build testing while in -next.