From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3719FC2BA19 for ; Wed, 15 Apr 2020 12:03:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 175C820575 for ; Wed, 15 Apr 2020 12:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586952198; bh=aS6rCUp0LQwVhHJsV5uUa9qCEMgITqc2OzijRDMUb+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=teI87x9r3yKnNb6BbzGurnNt+UGG6HRcgHwG47rw7fjEorDqbfFSI3rsZJhP9NmOf m1G0Li98M1nDBpzT0ENTaJu78KIXA3202AwHepRL0DKrVdx2aZG13AZDgUvTbRyv6h 8N4Uneqt4kH5OakWLye+FwBRn5xul0fWexXAXr7A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368241AbgDOMDO (ORCPT ); Wed, 15 Apr 2020 08:03:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:44178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409452AbgDOLs1 (ORCPT ); Wed, 15 Apr 2020 07:48:27 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D408F2137B; Wed, 15 Apr 2020 11:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586951307; bh=aS6rCUp0LQwVhHJsV5uUa9qCEMgITqc2OzijRDMUb+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tFhtEAL4WK1SQf1f5uAhdTokXOM/dRcTqL80zFQVEg7TqSDCYhPIlVpM3SoohKtym 3KL3VVQEANxJghnV4li/SPJn+ViNlbCu92WOoYJGuwjspO8YCGWSh+Ba+eKR4q6OO3 afmrYY7uqQhBhuQKUdp/geE1GBTW8uSYQ0WIfsXM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vegard Nossum , Andrew Morton , Masahiro Yamada , Daniel Santos , Rasmus Villemoes , Ian Abbott , Joe Perches , Linus Torvalds , Sasha Levin , linux-sparse@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 10/14] compiler.h: fix error in BUILD_BUG_ON() reporting Date: Wed, 15 Apr 2020 07:48:10 -0400 Message-Id: <20200415114814.15954-10-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415114814.15954-1-sashal@kernel.org> References: <20200415114814.15954-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vegard Nossum [ Upstream commit af9c5d2e3b355854ff0e4acfbfbfadcd5198a349 ] 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 `__compiletime_assert_9' 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 `__compiletime_assert_0' declared with attribute error: BUILD_BUG_ON failed: 1 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) Signed-off-by: Vegard Nossum Signed-off-by: Andrew Morton Reviewed-by: Masahiro Yamada Reviewed-by: Daniel Santos Cc: Rasmus Villemoes Cc: Ian Abbott Cc: Joe Perches Link: http://lkml.kernel.org/r/20200331112637.25047-1-vegard.nossum@oracle.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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 5508011cc0c79..5f8749440c6af 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -502,7 +502,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s * compiler has support to do so. */ #define compiletime_assert(condition, msg) \ - _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) + _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) #define compiletime_assert_atomic_type(t) \ compiletime_assert(__native_word(t), \ -- 2.20.1