Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3395899ybb; Tue, 31 Mar 2020 04:30:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu1BkPvdPyv73TUvUZ/WugtZDdpNEjbRfFoooWVcPg80HnyFwlrfafQ3RQnvkMogQ+A9Mvr X-Received: by 2002:aca:ec49:: with SMTP id k70mr1748809oih.80.1585654254634; Tue, 31 Mar 2020 04:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585654254; cv=none; d=google.com; s=arc-20160816; b=mdzG3txvHk1U3n09fJ6tk7iELwSWNEh73OaKkSkaJmlqmUZ7SgvmzkrwZL4CTGbV4G gQMezvsqJ8dTx53q1bpVLG6Zb9uZ7Jn+lgTpuPYliWSjwfuOTCKaHVFKkjt0Spj9VDRZ DHxXYQR2/jFbqxsRUZl/Oxt5lhBvdvAA3rxXqNmqFpkmGOujFY+fjLqpSGEgfuY45kqN i96CiEO9K53h6m1IsrpFw+HnuV9PiLyLW7Ed3lteH9IjTxlcoAsdtMymEURHCe/HQCHG jCWGUjO9K+lzir6FaCgcxmHzY+kdmQX7aWlFGLr/CgKaRUMVlHQ7Baj5TMM0YwjJKQpT IJHQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=CmjhbKGL3UgHlnlsAZ5WOFChMBQYcpnp75M2BI5GcX0=; b=llpjop7ZKmxtvCD9QpI6C5Uw93B61RYdPLHp+bZfWxeLbMgAH3bdulOTtJsiDGgUyk ffegixfinAjV/riCGXwBxzNTeJyT4HIVvA+cn6P+p2ftMUE0YgLALjROijwpci6jTSi7 h2Esb2nNV416nvhOIPrtBajp2wrgkmDUJmaBZUqOavOGVaeKyNhck8ysK+nT1OO2Ty9y jzJgFDUUmYt9D2YaiLveBtXPEDSNEg/jIHl6nmrlSAoiSYNFPPBBQF56FAY+4ud82BTZ sAM9IZU1QREARi1cpuC3Xr0pog3EVtczW1DRilRjXQUPN6AOxgX3GYxcTqZ8JiR4TlJz nZbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=xJ3P1GrT; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si608295oti.69.2020.03.31.04.30.40; Tue, 31 Mar 2020 04:30:54 -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=@oracle.com header.s=corp-2020-01-29 header.b=xJ3P1GrT; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730469AbgCaL2u (ORCPT + 99 others); Tue, 31 Mar 2020 07:28:50 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:58098 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730418AbgCaL2u (ORCPT ); Tue, 31 Mar 2020 07:28:50 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02VBRSSD082719; Tue, 31 Mar 2020 11:28:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=CmjhbKGL3UgHlnlsAZ5WOFChMBQYcpnp75M2BI5GcX0=; b=xJ3P1GrTv8jFUMMToH5kBgrA5nkBvl7gC3ssjYnvTy4//itw0jIiJZr5CtFReloA88Hz Mxz0OVX1FsJI7XDeKumemYENOay5UU4iNP28KD0O8/cWBORfUBR6ZHNTdjS+DAjFnQSK FoXj4lkqFNh7pLn0s4tbBnQao9+cNF0QG4fWkAIU9TdtQmHfF51QgBTLnK5urXbmMqf/ hfxc96UZTnBsUbqZKvD38iCdwWZBMGd/Z4dKpUVIE5QI9jmH/kkRKbIoZFi48QRuQeBD LtcfGVgwSawBmqIyVeJGnM6DLrp5jvD3gorwQE1PZfEJ7nVg05BW8EoaxZpJAG7mTU/j Xg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 303ceuxytk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Mar 2020 11:28:40 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02VBMJVw034538; Tue, 31 Mar 2020 11:28:40 GMT Received: from t460.home (dhcp-10-175-15-184.vpn.oracle.com [10.175.15.184]) by aserp3030.oracle.com with ESMTP id 302g4re0sx-1; Tue, 31 Mar 2020 11:28:39 +0000 From: Vegard Nossum To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Daniel Santos , Rasmus Villemoes , Masahiro Yamada , Ian Abbott Subject: [PATCH] compiler.h: fix error in BUILD_BUG_ON() reporting Date: Tue, 31 Mar 2020 13:26:37 +0200 Message-Id: <20200331112637.25047-1-vegard.nossum@oracle.com> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9.dirty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9576 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003310104 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9576 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 adultscore=0 clxscore=1011 phishscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003310104 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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__) Cc: Daniel Santos Cc: Rasmus Villemoes Cc: 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_, __COUNTER__) #define compiletime_assert_atomic_type(t) \ compiletime_assert(__native_word(t), \ -- 2.16.1.72.g5be1f00a9.dirty