Received: by 10.192.165.156 with SMTP id m28csp2612475imm; Sun, 15 Apr 2018 05:11:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Wj8nBXJgTGfirRGQT2UUnJndu/L3wdxevxQJtTuZSk1OwYAGwZBWSpQH4YkyvnzN4WYMz X-Received: by 2002:a17:902:7e02:: with SMTP id b2-v6mr11541568plm.230.1523794287904; Sun, 15 Apr 2018 05:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523794287; cv=none; d=google.com; s=arc-20160816; b=lsL+up/f/Tty/KAyHSGy/A18/y070Wl6RP3nkXGznuiR3sXTkURioknO2D91VM1co6 iwuzcvDqaQRogC4QdFMo7Kg9eTdMPtRHkXWu8Mme69KwLSwSmNlN5OiiYX6aOBaVl/ts jViR8hq2oJ8gLzeV+ktSgJRbkMlhTNFAkjr2Qt9K8lOa/F4VxtDsxlpwc4Wds/ibEGuc JeaCTGEvLy5KCZ12GX0IyDrQA+Mh61yEmRFYwzXX2ARf3QVZ3TDaB18KVmyRptnP1V3a A2xMGpFB9XCpTiBpPk7ZGsKfqdLqsSU4pbul2NXh0CR7N/7FtRRYuXJQtrYo+2SDbXE1 CwGA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:cc:from:references:to:subject:domainkey-signature :dkim-signature:arc-authentication-results; bh=sJSiaQIvqYE7C8WRYty/Z9JmDOwCASNYlRERL32Ztrg=; b=zvK54roayrYGgbJowggB2A3/bz+4i59lo23pR+HIgnmhimhW9f78+hOOszNkNlEdrq i/iyc8yYcK2HN9oxWSAGgH9m3WQydnXRhqYkpQzyfOt2Wh71yIWbNte3oGpEKSkwu/bz 7wnUKNNQzqTfdy5XFjMF8gR+fBq8U1VCrFliDIqORaHT3y/CyK9o/m59+Zo2ggAZ21Ow LbyXUXzmI4DxTyHSSVPzmm4c2MIMnTDsfMy2NAXRIg8W1H6uFa+HASQvBSbbfILfOLvi pITK1IOMFh7hSF15s6TkcLvLBi8gruy6y54OcRXKEM7rmy87FWMyAK7s2Y9ZqKJ5Y8hi jdTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=uDvARNlU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=pobox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a35-v6si10022131pli.71.2018.04.15.05.11.14; Sun, 15 Apr 2018 05:11:27 -0700 (PDT) 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; dkim=pass header.i=@pobox.com header.s=sasl header.b=uDvARNlU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=pobox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752297AbeDOMKJ (ORCPT + 99 others); Sun, 15 Apr 2018 08:10:09 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:62285 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbeDOMKH (ORCPT ); Sun, 15 Apr 2018 08:10:07 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 0FFF0C9337; Sun, 15 Apr 2018 08:10:05 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=subject:to :references:from:cc:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=sasl; bh=udRDR+oH7ir6 +VvzX6mHZYONSNY=; b=uDvARNlUvUgVuqwDbQYOoWQWz3wu/4gGRDe6kTuwgAc+ E7E69iIvHo/hKo5myl2vP+LyrHOwcBa3jtKyJ7DgmsfSEOwG/zKLULl5ZKuDLmef 2u2KJsH7EJSxwC1Fr3SuRy6FfqwDGu8Jv7T8JgpJgkQU7xs2jJwxgrQ/YXuKc6Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=subject:to :references:from:cc:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; q=dns; s=sasl; b=Mb1v0p Jf0cXpK9Zuus6pyoJHcCk8bfwJWxEcU2uVkbIifT8b7ZnH6rZz2ypfkEq3kZDDZB WY+vJGXWL07drRo/04HRLBmm3jSRlZUwJSZqlCBWxRUB10uYgXeU3rzn+OteyawT C13OCSWLlFMZ8TgWO9aYIam7qCULrs29l0UNc= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 0407DC9336; Sun, 15 Apr 2018 08:10:05 -0400 (EDT) Received: from [192.168.1.4] (unknown [76.215.41.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id DCB9EC9331; Sun, 15 Apr 2018 08:10:03 -0400 (EDT) Subject: Re: BUILD_BUG_ON_MSG To: Julia Lawall References: From: Daniel Santos Cc: LKML Message-ID: <9f2e95dc-6f8e-0adc-50d9-578f1077722d@pobox.com> Date: Sun, 15 Apr 2018 07:10:55 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Pobox-Relay-ID: EDF064E2-40A5-11E8-992E-44CE1968708C-06139138!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Julia, I'm CCing LKML on this so that others can be involved. On 04/15/2018 12:43 AM, Julia Lawall wrote: > Hello, > > I saw that you introduced BUILD_BUG_ON_MSG in the Linux kernel a few ye= ars > ago. > > BUILD_BUG_ON_MSG is not safe when used in header files. Via > compiletime_assert, it makes a new function whose name is only determin= ed > by a line number. When BUILD_BUG_ON_MSG is used in header files, > multiple uses may end up at the same line, in different header files. = The > reported errors are then quite confusing; I guess the last function wit= h > the given name is used. Yes, This is an unfortunate side-effect of the implementation, since "error" and "warning" are function attributes.=C2=A0 This issue was discu= ssed during review and it was decided that one should simply not use more than one of such macro on the same line in an implementation file.=C2=A0 = I had thought we added a "don't use more than once per line" in the documentation for these macros, but I'm not seeing it right now -- if it's really missing then we probably want to add it. > > I tried incorporating __func__, but for some reason it didn't expand in= to > anything. Perhaps I used it incorrectly in some way. Neither __func__ nor __FUNCTION__ are cpp macros, they are just static const char arrays (see https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html).=C2=A0 For some reason I recall believing that __PRETTY_FUNCTION__ *is* a cpp macro, but I'm probably wrong, and even if it was it wouldn't be a valid function prefix. > If it is not > possible to get the name of the enclosing function, would it be reasona= ble > to make a new kind of BUILD_BUG_ON call that takes an extra argument th= at > can be used in the function name to make it unique? > > thanks, > julia > You're still going to need the function name as a cpp macro.=C2=A0 If you have that, you can just expand _compiletime_assert() directly.=C2=A0 Plea= se post your code when sending an inquiry like this -- it makes it easier for others to help you and we don't have to waste as much time trying to figure out exactly what you might be doing and how.=C2=A0 I don't remembe= r if doing this inside of an always_inline function (instead of a macro expansion) works or not. For a long time I've considered the merits of directly adding a gcc extension to perform these checks without all of these side effects and the lengthy macro expansion backtrace, which is also an ugly artifact of this mechanism.=C2=A0 In fact, I was really disappointed with C11's _Static_assert because I at first thought it was a generic solution, but then came to find out otherwise. IMO, the ideal mechanism would behave more like MAYBE_BUILD_BUG_ON, but without all of the cpp fluff currently required.=C2=A0 Does anybody know = if this has been proposed or a gcc feature request filed for this yet? Daniel