* [PATCH] btrfs-progs: mark BUG() as unreachable
@ 2021-04-01 8:41 Naohiro Aota
2021-04-16 17:35 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Naohiro Aota @ 2021-04-01 8:41 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs, Naohiro Aota
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(-)
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) ({ \
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs-progs: mark BUG() as unreachable
2021-04-01 8:41 [PATCH] btrfs-progs: mark BUG() as unreachable Naohiro Aota
@ 2021-04-16 17:35 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-04-16 17:35 UTC (permalink / raw)
To: Naohiro Aota; +Cc: David Sterba, linux-btrfs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-16 17:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 8:41 [PATCH] btrfs-progs: mark BUG() as unreachable Naohiro Aota
2021-04-16 17:35 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.