Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3716940ybb; Tue, 31 Mar 2020 10:34:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vubxsBRexF9FD+Lw5sVuyG7GKKo5VpakFvtprT94+NSjAoWcTg/oTYagl4kXkGz3V0Sa+/c X-Received: by 2002:a4a:a60a:: with SMTP id e10mr14271901oom.34.1585676060514; Tue, 31 Mar 2020 10:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585676060; cv=none; d=google.com; s=arc-20160816; b=VUxLBzhYxNoEJGZ192q++Jqd04g9yfNtpj6KMLseWbfsZs/VgO4mpsrJ/SwN8n1iMz 0SnPF41FBXurWATHadpMUeQFkzQ0cg5JW8FvWK/pWAKq9MHWRa0CuJAEQK0cywcGTxgb vHnhpxvMfK2cHyi8CylXt8nTNfbqY1Y1D1BoSaXKWF/4MwHo4b3OuMHKGUTyKZqLPVF2 5SWfaP4NGunsxXdJOcuga/oAXEFbdIEnuh41m5CcLqD8kTO4Z7e7IMM14AaXo0ayIdLV TFuSppkX3sFoavYrtDUKOZUZlVkTZeYDP8o1A2UcDPcLGHr091/XzjxSkj/Ca3L9/a+Y 2PXA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:dkim-filter; bh=apzVeH3ZSZdTyLs9ucwBXEBHGGEys7AlSqP5ZhodY/s=; b=E//caFXQfU35lEXzasIhX5L1oSA7vl/fxD3guaHKR2PSVlWh/Q8W1v8R6I9Te6QRmG cQo2pCCGb9T2YkLzJhOm4rGiyeMT6joieBF3v+13Cn7Jj4cN6WUsSPcGz8IjfON9rm3I wjObe5A9Mvk4T+OwpvZ1Imsslj3oN+ZVYtbBgEmX/wsUCQM8Xwgj64C8C7hDasch+r/3 1x4IALBc/XPYm58zE07EVlFKe3pWR2FrzJjMe4Qd5f1SIQB9zjXFStY2iApGm5U94K+3 LKWkmGPz4kJj8eVaDd3fJvhoF3S2l1kBps81bREqsCuC9IK/G1eBqkWIYekqyuG35A5C AtLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="jVD0O/Vz"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si7980227oti.52.2020.03.31.10.34.06; Tue, 31 Mar 2020 10:34:20 -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=@nifty.com header.s=dec2015msa header.b="jVD0O/Vz"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726194AbgCaRcd (ORCPT + 99 others); Tue, 31 Mar 2020 13:32:33 -0400 Received: from conssluserg-04.nifty.com ([210.131.2.83]:57032 "EHLO conssluserg-04.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbgCaRcc (ORCPT ); Tue, 31 Mar 2020 13:32:32 -0400 Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (authenticated) by conssluserg-04.nifty.com with ESMTP id 02VHWEbr021936 for ; Wed, 1 Apr 2020 02:32:15 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-04.nifty.com 02VHWEbr021936 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1585675935; bh=apzVeH3ZSZdTyLs9ucwBXEBHGGEys7AlSqP5ZhodY/s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jVD0O/Vz8GNkLQaEWHiA4syrRtVzekwW9C0TQ3uo0gRYQi+4/ErCZWFBUwToaqxcB 34RDj8076HlqoQCu1gpEblQqyYH5zmvEt7XH0GwXtKWQAxqTPVeqNJwaD3CTXOWLIn XF6HTHuxlHjcg0JifijvyALAXi+T/IEu5GfGpkU6q/7F6JKxIjoBrmIE+D1W1dW0Ji 2r8UPWdSaKXhVMH0AmDYIR8+wAjttSir53hIwwgp6985qwc7UwMJuXeICJ8PyCRuzd TGPKLdetGnbu18SJnnIwASpmIQ+MNi846gUUSWLFASp2Q9xchGpClkPBPenbMQRF9N s9vMSGhFZOB0A== X-Nifty-SrcIP: [209.85.221.181] Received: by mail-vk1-f181.google.com with SMTP id v129so5586570vkf.10 for ; Tue, 31 Mar 2020 10:32:15 -0700 (PDT) X-Gm-Message-State: AGi0PuYogJYupHtQao6mDVUsmj9Xm2t+KBa76v/iX6LoSZLK03McXhJq eRrYeo7p6No8cVoHXI61lVr27FPd6GhJ8UEhfN8= X-Received: by 2002:a1f:32cf:: with SMTP id y198mr12581684vky.96.1585675934026; Tue, 31 Mar 2020 10:32:14 -0700 (PDT) MIME-Version: 1.0 References: <20200331112637.25047-1-vegard.nossum@oracle.com> In-Reply-To: <20200331112637.25047-1-vegard.nossum@oracle.com> From: Masahiro Yamada Date: Wed, 1 Apr 2020 02:31:37 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] compiler.h: fix error in BUILD_BUG_ON() reporting To: Vegard Nossum Cc: Andrew Morton , Linux Kernel Mailing List , Daniel Santos , Rasmus Villemoes , Ian Abbott Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 31, 2020 at 8:28 PM Vegard Nossum wr= ote: > > compiletime_assert() uses __LINE__ to create a unique function name. > This means that if you have more than one BUILD_BUG_ON() in the same > source line (which can happen if they appear e.g. in a macro), then > the error message from the compiler might output the wrong condition. > > For this source file: > > #include > > #define macro() \ > BUILD_BUG_ON(1); \ > BUILD_BUG_ON(0); > > void foo() > { > macro(); > } > > gcc would output: > > ./include/linux/compiler.h:350:38: error: call to =E2=80=98__compiletime_= assert_9=E2=80=99 declared with attribute error: BUILD_BUG_ON failed: 0 > _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) > > However, it was not the BUILD_BUG_ON(0) that failed, so it should say 1 > instead of 0. With this patch, we use __COUNTER__ instead of __LINE__, so > each BUILD_BUG_ON() gets a different function name and the correct > condition is printed: > > ./include/linux/compiler.h:350:38: error: call to =E2=80=98__compiletime_= assert_0=E2=80=99 declared with attribute error: BUILD_BUG_ON failed: 1 > _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) > > Cc: Daniel Santos > Cc: Rasmus Villemoes > Cc: Masahiro Yamada Reviewed-by: Masahiro Yamada > Cc: Ian Abbott > Signed-off-by: Vegard Nossum > --- > include/linux/compiler.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 5e88e7e33abec..034b0a644efcc 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -347,7 +347,7 @@ static inline void *offset_to_ptr(const int *off) > * compiler has support to do so. > */ > #define compiletime_assert(condition, msg) \ > - _compiletime_assert(condition, msg, __compiletime_assert_, __LINE= __) > + _compiletime_assert(condition, msg, __compiletime_assert_, __COUN= TER__) > > #define compiletime_assert_atomic_type(t) \ > compiletime_assert(__native_word(t), \ > -- > 2.16.1.72.g5be1f00a9.dirty > --=20 Best Regards Masahiro Yamada