[PATCH 1/1] bug: mark generic BUG() as unreachable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Tom Rix <trix@xxxxxxxxxx>

This spurious error is reported for powerpc64, CONFIG_BUG=n

fs/afs/dir.c: In function 'afs_dir_set_page_dirty':
fs/afs/dir.c:51:1: error: no return statement in
  function returning non-void [-Werror=return-type]
   51 | }
      | ^

When CONFIG_BUG=y is BUG is expanded from
  #define BUG() do {
 	BUG_ENTRY("twi 31, 0, 0", 0);
 	unreachable();
   } while (0)

to

static int afs_dir_set_page_dirty(struct page *page)
{
 do { __asm__ __volatile__( "1:	" "twi 31, 0, 0"  ...
   do { ; asm volatile(""); __builtin_unreachable(); } while (0);
 } while (0);
}

When CONFIG_BUG=n, the generic BUG() is used which
expands out to

static int afs_dir_set_page_dirty(struct page *page)
{
 do {} while (1);
}

Without the __builtin_unreachable(), gcc reports the
warning

ref: gcc docs https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
" ... without the __builtin_unreachable, GCC issues a
  warning that control reaches the end of a non-void function."

So add an unreachable() to the generic BUG(), the resulting
expansiion will be

static int afs_dir_set_page_dirty(struct page *page)
{
 do {
   do {} while (1);
   do { ; asm volatile(""); __builtin_unreachable(); } while (0);
 } while (0);
}

Signed-off-by: Tom Rix <trix@xxxxxxxxxx>
---
 include/asm-generic/bug.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index f152b9bb916fc..b250e06d7de26 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -177,7 +177,10 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 
 #else /* !CONFIG_BUG */
 #ifndef HAVE_ARCH_BUG
-#define BUG() do {} while (1)
+#define BUG() do {						\
+		do {} while (1);				\
+		unreachable();					\
+	} while (0)
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
-- 
2.26.3




[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux