Skip to contentSkip to conversation

compiler_attribute: remove CONFIG_ENABLE_MUST_CHECK

PATCH In review Masahiro Yamada 2 participants 5 messages Nov 21, 2020 – Nov 27, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compiler_attribute: remove CONFIG_ENABLE_MUST_CHECK

Revert commit cebc04ba9aeb ("add CONFIG_ENABLE_MUST_CHECK").

A lot of warn_unused_result warnings existed in 2006, but until now they have been fixed thanks to people doing allmodconfig tests.

Our goal is to always enable __must_check where appreciate, so this CONFIG option is no longer needed.

I see a lot of defconfig (arch/*/configs/*_defconfig) files having:

# CONFIG_ENABLE_MUST_CHECK is not set

I did not touch them for now since it would be a big churn. If arch maintainers want to clean them up, please go ahead.

---

 include/linux/compiler_types.h                      | 4 ----
 lib/Kconfig.debug                                   | 8 --------
 tools/testing/selftests/wireguard/qemu/debug.config | 1 -
 3 files changed, 13 deletions(-)
include/linux/compiler_types.h +0 -4
index ac3fa37a84f9..02f6d3fbad9d 100644
@@ -110,11 +110,7 @@ struct ftrace_likely_data {
 	unsigned long			constant;
 };
 
-#ifdef CONFIG_ENABLE_MUST_CHECK
 #define __must_check		__attribute__((__warn_unused_result__))
-#else
-#define __must_check
-#endif
 
 #if defined(CC_USING_HOTPATCH)
 #define notrace			__attribute__((hotpatch(0, 0)))
lib/Kconfig.debug +0 -8
index c789b39ed527..cb8ef4fd0d02 100644
@@ -286,14 +286,6 @@ config GDB_SCRIPTS
 
 endif # DEBUG_INFO
 
-config ENABLE_MUST_CHECK
-	bool "Enable __must_check logic"
-	default y
-	help
-	  Enable the __must_check logic in the kernel build.  Disable this to
-	  suppress the "warning: ignoring return value of 'foo', declared with
-	  attribute warn_unused_result" messages.
-
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
tools/testing/selftests/wireguard/qemu/debug.config +0 -1
index b50c2085c1ac..fe07d97df9fa 100644
@@ -1,5 +1,4 @@
 CONFIG_LOCALVERSION="-debug"
-CONFIG_ENABLE_MUST_CHECK=y
 CONFIG_FRAME_POINTER=y
 CONFIG_STACK_VALIDATION=y
 CONFIG_DEBUG_KERNEL=y
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Masahiro Yamada

Our goal is to always enable __must_check where appreciate, so this CONFIG option is no longer needed.

This would be great. It also implies we can then move it to compiler_attributes.h since it does not depend on config options anymore.

We should also rename it to __nodiscard, since that is the standardized name (coming soon to C2x and in C++ for years).

Cc'ing the Clang folks too to make them aware.

Cheers,
Miguel

#2 lore raw
Quoted 6 lines · Miguel Ojeda
Quoted 3 lines · Masahiro Yamada

Our goal is to always enable __must_check where appreciate, so this CONFIG option is no longer needed.

Quoted 9 lines

This would be great. It also implies we can then move it to compiler_attributes.h since it does not depend on config options anymore.

We should also rename it to __nodiscard, since that is the standardized name (coming soon to C2x and in C++ for years).

Cc'ing the Clang folks too to make them aware.

I can move it to compiler_attribute.h

This attribute is supported by gcc, clang, and icc.
https://godbolt.org/z/ehd6so

I can send v2.

I do not mind renaming, but it should be done in a separate patch.

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
Quoted 9 lines · Masahiro Yamada

I can move it to compiler_attribute.h

This attribute is supported by gcc, clang, and icc.
https://godbolt.org/z/ehd6so

I can send v2.

I do not mind renaming, but it should be done in a separate patch.

Of course -- sorry, I didn't mean we had to do them now, i.e. we can do the move and the rename later on, if you prefer.

Cheers,
Miguel

#4 lore raw
In reply to Masahiro Yamada
Quoted 9 lines · Masahiro Yamada

Revert commit cebc04ba9aeb ("add CONFIG_ENABLE_MUST_CHECK").

A lot of warn_unused_result warnings existed in 2006, but until now they have been fixed thanks to people doing allmodconfig tests.

Our goal is to always enable __must_check where appreciate, so this CONFIG option is no longer needed.

Quoted 8 lines

I see a lot of defconfig (arch/*/configs/*_defconfig) files having:

# CONFIG_ENABLE_MUST_CHECK is not set

I did not touch them for now since it would be a big churn. If arch maintainers want to clean them up, please go ahead.

Picked it up through compiler-attributes with the "appreciate" typo fixed on my end. I did a quick compile-test with a minimal config. Let's see if the -next bots complain...

Thanks!

Cheers,
Miguel