diff mbox series

btrfs-progs: mark BUG() as unreachable

Message ID 5c7b703beca572514a28677df0caaafab28bfff8.1617265419.git.naohiro.aota@wdc.com (mailing list archive)
State New
Headers show
Series btrfs-progs: mark BUG() as unreachable | expand

Commit Message

Naohiro Aota April 1, 2021, 8:41 a.m. UTC
Marking BUG() unreachable helps us silence unnecessary warnings e.g.
"warning: control reaches end of non-void function [-Wreturn-type]" like
the code below.

   int foo()
   {
   ...
   	if (XXX)
   		return 0;
	else if (YYY)
		return 1;
   	else
   		BUG();
   }

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 kerncompat.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

David Sterba April 16, 2021, 5:35 p.m. UTC | #1
On Thu, Apr 01, 2021 at 05:41:00PM +0900, Naohiro Aota wrote:
> Marking BUG() unreachable helps us silence unnecessary warnings e.g.
> "warning: control reaches end of non-void function [-Wreturn-type]" like
> the code below.
> 
>    int foo()
>    {
>    ...
>    	if (XXX)
>    		return 0;
> 	else if (YYY)
> 		return 1;
>    	else
>    		BUG();
>    }
> 
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Added to devel, thanks.
diff mbox series

Patch

diff --git a/kerncompat.h b/kerncompat.h
index 01fd93a7b540..7060326fe4f4 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -333,7 +333,11 @@  static inline void assert_trace(const char *assertion, const char *filename,
 #endif
 
 #define BUG_ON(c) bugon_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define BUG() BUG_ON(1)
+#define BUG()				\
+do {					\
+	BUG_ON(1);			\
+	__builtin_unreachable();	\
+} while (0)
 #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
 
 #define container_of(ptr, type, member) ({                      \