Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4367582ima; Mon, 4 Feb 2019 15:22:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ2tjFSZtZUUjOd39Nl8Rv5NaKbD2a6m8XN9q5vIQW5D2f8rwe00AkjhJTcNo6l9fLbZsZP X-Received: by 2002:a17:902:f20b:: with SMTP id gn11mr1880117plb.274.1549322533105; Mon, 04 Feb 2019 15:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549322533; cv=none; d=google.com; s=arc-20160816; b=sbr8DsgfyvUtkdXV1EhRzOgZfcbY2NFD6fOGUFmWZctjO5VN7LxDT6IRZPXM9XdZGf GpWm+DYgL+PVIiJ5tlqhsxClbOm3D/b4eJH/zfeOCRBHO4+5LuB8Hmf/Hk2FJRWhXYkn Kb3ILA3xX6u6/b9xInXcVl3qmp8Uc8617kYMNuodSKyHNqdQCOqbx7jS2vncH+7Cq+/c G9Q5k8gfkhUvjUmXwAQUuv+CtFSeLI9klNfej7AXHHKrNm28rM4oXayvjrZNyxCfJwdk axM1Fjf9L2GoiGVeznjOBesGJ1PkC/DKoteb6AmVYTtdzOPzgXJqUDl9aPkY5bgg+qGl N7ow== 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:to:from:date; bh=42bkSKj0wSbHIeDJW9rn67Bic6eV2KFbK8nYuxRHrzk=; b=gdNGfziWky+LmbzaLm/uJNkwnlXA1p7U3bzFpykdbjNc7EWZyGxXRx4nPTPee9W0SQ h+7nr6+h93OU46XJxASnRomEDa/VRb/SXvKr+8r9FDnEaG66rT9h4jCe5uMUwWXE5xcw 5X3bl4h9rtTRaRMxeiIfRzxivACbktTmGL/OjaOIYK/UjSQpsUt90xVM8ksJ4LemzYBM aUHQEZlj4hoi1x8ZuN7pR2m3nD5blLaKPnyglondUYe4FyzmfXH3GVIQf7eR5ycp8ZHP XImHHyUEvn7+yhR18Q46c+xBq8l/gYUKMCPDkn9UIBeekaflqbgZ7NAt7lWxYmP8YAh+ 4bKQ== 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 q10si1314530pll.221.2019.02.04.15.21.56; Mon, 04 Feb 2019 15:22:13 -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 S1728593AbfBDXML (ORCPT + 99 others); Mon, 4 Feb 2019 18:12:11 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60090 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726119AbfBDXML (ORCPT ); Mon, 4 Feb 2019 18:12:11 -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 B39878F89; Mon, 4 Feb 2019 23:12:10 +0000 (UTC) Date: Mon, 4 Feb 2019 15:12:09 -0800 From: Andrew Morton To: Rasmus Villemoes , 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: <20190204151209.d6fae2c6466cb5c9c5814fd9@linux-foundation.org> In-Reply-To: <20190204150916.f29d782b27f096e6c4c6d6cf@linux-foundation.org> References: <20190203192401.29170-1-linux@rasmusvillemoes.dk> <20190204150916.f29d782b27f096e6c4c6d6cf@linux-foundation.org> 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 Mon, 4 Feb 2019 15:09:16 -0800 Andrew Morton wrote: > 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. ie, just about every BUILD_BUG_ON in mm/ could use this. Let's switch a few?