diff mbox series

[2/2] build_bug.h: remove all dummy BUILD_BUG_ON stubs for sparse

Message ID 1542349141-7229-2-git-send-email-yamada.masahiro@socionext.com
State Superseded
Headers show
Series [1/2] build_bug.h: remove negative-array fallback for BUILD_BUG_ON() | expand

Commit Message

Masahiro Yamada Nov. 16, 2018, 6:19 a.m. UTC
The introduction of these dummy BUILD_BUG_ON stubs dates back to
commit 903c0c7cdc21 ("sparse: define dummy BUILD_BUG_ON definition
for sparse"). At that time, BUILD_BUG_ON() was implemented with the
negative array trick, which Sparse complains about even if the
condition can be optimized and evaluated to 0 at compile-time.

With the previous commit, the leftover negative array trick is gone.
Sparse is happy with the current BUILD_BUG_ON(), which is implemented
by using the 'error' attribute.

There might be a little room for argument about BUILD_BUG_ON_ZERO().
Sparse reports 'invalid bitfield width, -1' for non-zero value,
and 'bad integer constant expression' for non-constant value.
This is the same criteria as GCC uses. So, if those Sparse errors
occurred, they would cause errors for GCC as well. (Hence, such
errors would have been detected by the normal compile test process.)

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 include/linux/build_bug.h | 11 -----------
 1 file changed, 11 deletions(-)

-- 
2.7.4

Comments

kernel test robot Nov. 17, 2018, 10:53 a.m. UTC | #1
Hi Masahiro,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.20-rc2 next-20181116]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Masahiro-Yamada/build_bug-h-remove-negative-array-fallback-for-BUILD_BUG_ON/20181116-190414
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:241:29: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:260:39: warning: incorrect type in assignment (different base types)
   drivers/crypto/chelsio/chcr_algo.c:260:39:    expected unsigned int [unsigned] [usertype] <noident>
   drivers/crypto/chelsio/chcr_algo.c:260:39:    got restricted __be32 [usertype] <noident>
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: restricted __be32 degrades to integer
   drivers/crypto/chelsio/chcr_algo.c:2301:21: warning: cast to restricted __be32
   drivers/crypto/chelsio/chcr_algo.c:2747:65: warning: incorrect type in assignment (different base types)
   drivers/crypto/chelsio/chcr_algo.c:2747:65:    expected unsigned short [unsigned] [short] <noident>
   drivers/crypto/chelsio/chcr_algo.c:2747:65:    got restricted __be16 [usertype] <noident>
   drivers/crypto/chelsio/chcr_algo.c:3014:46: warning: incorrect type in assignment (different base types)
   drivers/crypto/chelsio/chcr_algo.c:3014:46:    expected unsigned int [unsigned] <noident>
   drivers/crypto/chelsio/chcr_algo.c:3014:46:    got restricted __be32 [usertype] <noident>
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
   drivers/crypto/mediatek/mtk-sha.c:251:17: warning: incorrect type in assignment (different base types)
   drivers/crypto/mediatek/mtk-sha.c:251:17:    expected unsigned long long [unsigned] [long] [long long] <noident>
   drivers/crypto/mediatek/mtk-sha.c:251:17:    got restricted __be64 [usertype] <noident>
   drivers/crypto/mediatek/mtk-sha.c:252:17: warning: incorrect type in assignment (different base types)
   drivers/crypto/mediatek/mtk-sha.c:252:17:    expected unsigned long long [unsigned] [long] [long long] <noident>
   drivers/crypto/mediatek/mtk-sha.c:252:17:    got restricted __be64 [usertype] <noident>
   include/linux/slab.h:332:43: warning: dubious: x & !y
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

>> sound/hda/ext/hdac_ext_bus.c:203:36: warning: unknown expression (4 0)

--
   include/linux/slab.h:332:43: warning: dubious: x & !y
   drivers/infiniband/hw/hns/hns_roce_ah.c:72:24: warning: incorrect type in assignment (different base types)
   drivers/infiniband/hw/hns/hns_roce_ah.c:72:24:    expected restricted __le32 [usertype] port_pd
   drivers/infiniband/hw/hns/hns_roce_ah.c:72:24:    got restricted __be32 [usertype] <noident>
>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

>> drivers/infiniband/hw/hns/hns_roce_device.h:869:16: warning: unknown expression (4 0)

--
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
   include/linux/slab.h:332:43: warning: dubious: x & !y
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

--
>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

>> include/crypto/hash.h:767:16: warning: unknown expression (4 0)

..

vim +767 include/crypto/hash.h

974959863 Herbert Xu 2009-02-03  764  
7b5a080b3 Herbert Xu 2008-08-31  765  static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg)
7b5a080b3 Herbert Xu 2008-08-31  766  {
7b5a080b3 Herbert Xu 2008-08-31 @767  	return container_of(alg, struct shash_alg, base);
7b5a080b3 Herbert Xu 2008-08-31  768  }
7b5a080b3 Herbert Xu 2008-08-31  769  

:::::: The code at line 767 was first introduced by commit
:::::: 7b5a080b3c46f0cac71c0d0262634c6517d4ee4f crypto: hash - Add shash interface

:::::: TO: Herbert Xu <herbert@gondor.apana.org.au>
:::::: CC: Herbert Xu <herbert@gondor.apana.org.au>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Masahiro Yamada Nov. 19, 2018, 10:37 a.m. UTC | #2
On Sat, Nov 17, 2018 at 7:56 PM kbuild test robot <lkp@intel.com> wrote:
>

> Hi Masahiro,

>

> I love your patch! Perhaps something to improve:

>

> [auto build test WARNING on linus/master]

> [also build test WARNING on v4.20-rc2 next-20181116]

> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

>

> url:    https://github.com/0day-ci/linux/commits/Masahiro-Yamada/build_bug-h-remove-negative-array-fallback-for-BUILD_BUG_ON/20181116-190414

> config: x86_64-allmodconfig (attached as .config)

> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0

> reproduce:

>         # save the attached .config to linux build tree

>         make ARCH=x86_64



OK, I was digging into this Sparse warning.

I suspect this is a bug of Sparse.

I submitted this to disable __builtin_types_compatible_p() for Sparse.

https://lore.kernel.org/patchwork/patch/1013734/





-- 
Best Regards
Masahiro Yamada
diff mbox series

Patch

diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h
index d415c64..b0828f7 100644
--- a/include/linux/build_bug.h
+++ b/include/linux/build_bug.h
@@ -4,16 +4,6 @@ 
 
 #include <linux/compiler.h>
 
-#ifdef __CHECKER__
-#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
-#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
-#define BUILD_BUG_ON_ZERO(e) (0)
-#define BUILD_BUG_ON_INVALID(e) (0)
-#define BUILD_BUG_ON_MSG(cond, msg) (0)
-#define BUILD_BUG_ON(condition) (0)
-#define BUILD_BUG() (0)
-#else /* __CHECKER__ */
-
 /* Force a compilation error if a constant expression is not a power of 2 */
 #define __BUILD_BUG_ON_NOT_POWER_OF_2(n)	\
 	BUILD_BUG_ON(((n) & ((n) - 1)) != 0)
@@ -64,6 +54,5 @@ 
  */
 #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
 
-#endif	/* __CHECKER__ */
 
 #endif	/* _LINUX_BUILD_BUG_H */