public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: Fix use of GCC_VERSION in messages.h
@ 2025-04-28 22:01 Nathan Chancellor
  2025-04-29  6:38 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2025-04-28 22:01 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: linux-btrfs, llvm, patches, Nathan Chancellor

Clang warns (or errors with CONFIG_WERROR=y):

  fs/btrfs/messages.h:188:5: error: 'GCC_VERSION' is not defined, evaluates to 0 [-Werror,-Wundef]
    188 | #if GCC_VERSION >= 80000
        |     ^

GCC_VERSION is defined in compiler-gcc.h, which is not included when
building with clang. Use the always defined Kconfig symbol,
CONFIG_GCC_VERSION, to do the comparison.

Additionally, as a comment above this #ifdef notes, clang supports
__VA_OPT__, which is really what is needed for this block to function.
Include a check for CONFIG_CC_IS_CLANG as well, since clang 13 is the
minimum supported version for building the kernel.

Fixes: 14d740332aa0 ("btrfs: enhance ASSERT() to take optional format string")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 fs/btrfs/messages.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/messages.h b/fs/btrfs/messages.h
index dcba4f43ee00..5539fb3c2e24 100644
--- a/fs/btrfs/messages.h
+++ b/fs/btrfs/messages.h
@@ -185,7 +185,7 @@ static inline void verify_assert_printk_format(const char *fmt, ...) {
  */
 #define __REST_ARGS(_, ... ) __VA_OPT__(,) __VA_ARGS__
 
-#if GCC_VERSION >= 80000
+#if defined(CONFIG_CC_IS_CLANG) || CONFIG_GCC_VERSION >= 80000
 /*
  * Assertion with optional printk() format.
  *

---
base-commit: b25667588fc3bf7b500c592959c3e6012e35a0de
change-id: 20250428-btrfs-fix-messages-h-clang-21c58d3f31ed

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: Fix use of GCC_VERSION in messages.h
  2025-04-28 22:01 [PATCH] btrfs: Fix use of GCC_VERSION in messages.h Nathan Chancellor
@ 2025-04-29  6:38 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2025-04-29  6:38 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs, llvm,
	patches

On Mon, Apr 28, 2025 at 03:01:35PM -0700, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
> 
>   fs/btrfs/messages.h:188:5: error: 'GCC_VERSION' is not defined, evaluates to 0 [-Werror,-Wundef]
>     188 | #if GCC_VERSION >= 80000
>         |     ^
> 
> GCC_VERSION is defined in compiler-gcc.h, which is not included when
> building with clang. Use the always defined Kconfig symbol,
> CONFIG_GCC_VERSION, to do the comparison.
> 
> Additionally, as a comment above this #ifdef notes, clang supports
> __VA_OPT__, which is really what is needed for this block to function.
> Include a check for CONFIG_CC_IS_CLANG as well, since clang 13 is the
> minimum supported version for building the kernel.
> 
> Fixes: 14d740332aa0 ("btrfs: enhance ASSERT() to take optional format string")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks, back then I verified that the minimum clang version required for
kernel compiles the code and using just GCC_VERSION looked correct from
other code but apparently not. Folded to the patch, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-29  6:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 22:01 [PATCH] btrfs: Fix use of GCC_VERSION in messages.h Nathan Chancellor
2025-04-29  6:38 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox