Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp315385pxu; Tue, 1 Dec 2020 11:59:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyi0aQsovbYi59/m9vGANSlBNziKV1GGKIe3h3bmKnJb5ch79IQLbnlFY+umSi0zVRX1hKX X-Received: by 2002:a17:906:e212:: with SMTP id gf18mr4709063ejb.551.1606852769128; Tue, 01 Dec 2020 11:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606852769; cv=none; d=google.com; s=arc-20160816; b=yoVSU57qqsd5OsxJn0zxT+/2hYDGVXp/HgHkkahUepvY0pXBdIn15mn2OLBPAWZym6 OA1ZLlEKle94WVxn3U8iHkY5IDrZH89lR58TLOOBv4Krjqh8Rs2O1hAQzncZfTUOc1tu IIArLTkzwoQCkHSHFnqI3bWAgfQiKUxSG4dquRODkCRkbWXN05FPUfcpgobu+EqJ7LFT 7CY6t6x0d93yz3K9O4qak5tPltMzwEvX4WTyYMCybbrcN2pXMzHTc7+STtrlc1nWvLuk /WyN5Rpz7jlFKZ2IaTRPIbBNVJJSC9Xlsot9nGN7xzhPUqYIEQNKBEGCsJBeYlG/CxLL pfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wNrUoO5GhGjJ+F0ga/x1uzDpCFyyeAqcGZvey2hPlFA=; b=slPVZ/VPs2v8CWpCh+GYru+bSRmAB/wWRaEtmua6o2UEk2X7QPzCkMwVYCuECiWK9K lr92P6MNn7wLhAPrvI/Lq2l9EdpuSpuAdBWmtzuBTWwdUu7oCl6Xtj9fMJAvP7xEWzcm wSdG+KW1ZK0t+mlJKhjobegFlelocMdG10wH8sECN1ode2vNgpLr/j9glKwgTBef4NWS qJJiuKuUK0SL8X7YZsg8f2uul98C1Uh229HK9YmOPBy60Mdst85RW9tFbly+4c1Sszqw PPyRJWXZ369WsBW+sfJjewsrQuNdCi3ZbFKtHIKQsoogESrCoBDDRClrB18NlqcWjG3u JmnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=C70FTDvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l9si568196edf.357.2020.12.01.11.59.05; Tue, 01 Dec 2020 11:59:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=C70FTDvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730453AbgLAT5S (ORCPT + 99 others); Tue, 1 Dec 2020 14:57:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726148AbgLAT5O (ORCPT ); Tue, 1 Dec 2020 14:57:14 -0500 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 597B0C0613CF for ; Tue, 1 Dec 2020 11:56:34 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id v1so1920419pjr.2 for ; Tue, 01 Dec 2020 11:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wNrUoO5GhGjJ+F0ga/x1uzDpCFyyeAqcGZvey2hPlFA=; b=C70FTDvUfhgCOJfzTxUA5eEUmvVh0GQGj2pAVU9HmbC/YznEBWoEUH9FNJwDRm4ouu yTVSK0/sAqW6YZ/IDDB0Y+sDeW+YcWxqo8Of+BSpxImWP0hxbHBQMYae8E5RMew7reWX JmxzA82GJnHtHuYCmeZwTp3vc1Ypt5tK9QpIc3Qv1GCm6RxNFoc8C/5rmdVVmiASEBRl 0XiFtWFykza4PvjOIcNtJDwSz/yJhjjaRm659ZFKfsBKEZ0l5W+j/2IOMphwM/mbeeTi eoR0Ao9X5szwLJRIYwZcYAgJPtJOfTd8t0oeM7p1fvo6aXjil0MLGFAfpVkgR6Vpmq3R 84jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wNrUoO5GhGjJ+F0ga/x1uzDpCFyyeAqcGZvey2hPlFA=; b=qJYsp3fSu6YFoG9is+DGpm9dMuF8eX0V3H8AeQjxDx5/xWh+HowkSFfPyPI4fHFznt JfryKmqE+MH9Rw+Pox5Gsi5cNTPgT5w1bqo2zBIFmk5hW/4O57BwtLGrw2WdIt42wF3e R8CTiVpwiGC86bd36ONep8OQX2m+Gbm0E26MKKEJ7Qc1e9N37SlQjFvCiAILaw/yRzDr KkNfOxQxn7ds7ZEkpcdAJt/7AuXEsAYTIyLTvfPsdBTKkgJtRyi2XnrT6CvwIXTP6afa 20x0IFngXBz+psjDk49uLs7JT09dIcS5PRi48wZdhZpY8bVV3LHZKCTD+vUR901ga1Qd 91Ug== X-Gm-Message-State: AOAM5308A74LxG5SPE8qnKmQK01goCW6aLgXfOxezCzqxYaC+Wlyr1SC MTjU5PH6zmIvIkoLJPXP2oHZ6R1a26hj/lePzHKP8Q== X-Received: by 2002:a17:90a:dc16:: with SMTP id i22mr4567464pjv.32.1606852593726; Tue, 01 Dec 2020 11:56:33 -0800 (PST) MIME-Version: 1.0 References: <20201201152017.3576951-1-elver@google.com> <20201201161414.GA10881@infradead.org> <20201201170421.GA3609680@elver.google.com> In-Reply-To: <20201201170421.GA3609680@elver.google.com> From: Nick Desaulniers Date: Tue, 1 Dec 2020 11:56:22 -0800 Message-ID: Subject: Re: [PATCH] genksyms: Ignore module scoped _Static_assert() To: Marco Elver Cc: Christoph Hellwig , LKML , kasan-dev , Masahiro Yamada , Joe Perches , George Burgess , Rasmus Villemoes Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 1, 2020 at 9:04 AM Marco Elver wrote: > > On Tue, Dec 01, 2020 at 04:14PM +0000, Christoph Hellwig wrote: > > Why not use the kernels own BUILD_BUG_ON instead of this idiom? > > BUILD_BUG_ON() was conceived before there was builtin compiler-support > in the form of _Static_assert() (static_assert()), which has several > advantages (compile-time performance, optional message) but most > importantly, that it can be used at module/global scope (which > BUILD_BUG_ON() cannot). > > From include/linux/build_bug: > > /** > * static_assert - check integer constant expression at build time > * > [...] > * > * Contrary to BUILD_BUG_ON(), static_assert() can be used at global > * scope, but requires the expression to be an integer constant > * expression (i.e., it is not enough that __builtin_constant_p() is > * true for expr). > [...] > > .. and there are plenty of global/module scoped users of it already. And to proactively address the inevitable: why do we have both? We looked into wholesale replacing BUILD_BUG_ON's implementation with _Static_assert, but found that they differ slightly in the handling of integer constant expressions; BUILD_BUG_ON was reliant on some compiler optimizations in expressions making use of __builtin_constant_p that cannot be evaluated when the compiler performs the _Static_assert check. So the current implementation is more flexible for expressions that use __builtin_constant_p than _Static_assert is. If we needed a rule of thumb, I'd recommend "use _Static_assert unless you're passing an expression that relies on __builtin_constant_p evaluation, at which point BUILD_BUG_ON must be used." -- Thanks, ~Nick Desaulniers