Repository navigation
[Support] Use [[gnu::warn_unused]] for LLVM_ATTRIBUTE_WARN_UNUSED (NFC) - #239486
kazutakahirata merged 1 commit into
Conversation
This patch updates LLVM_ATTRIBUTE_WARN_UNUSED in Compiler.h to use the
C++11 attribute syntax [[gnu::warn_unused]] via LLVM_HAS_CPP_ATTRIBUTE
instead of __attribute__((warn_unused)).
GCC 12 and earlier reject:
class __attribute__((warn_unused)) [[nodiscard]] Foo { ... };
class [[nodiscard]] __attribute__((warn_unused)) Bar { ... };
This patch drops the __attribute__((warn_unused)) fallback because an
older compiler like Clang 5.0 would select it and fail when a class
also has [[nodiscard]]. It's always safe to expand this optional
warning macro to empty.
Assisted-by: Antigravity
|
@llvm/pr-subscribers-llvm-support Author: Kazu Hirata (kazutakahirata) ChangesThis patch updates LLVM_ATTRIBUTE_WARN_UNUSED in Compiler.h to use the GCC 12 and earlier reject: This patch drops the attribute((warn_unused)) fallback because an Assisted-by: Antigravity Full diff: https://github.com/llvm/llvm-project/pull/239486.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index af06dbb441751..b3afc96842ed0 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -234,8 +234,8 @@
#define LLVM_ATTRIBUTE_USED
#endif
-#if __has_attribute(warn_unused)
-#define LLVM_ATTRIBUTE_WARN_UNUSED __attribute__((warn_unused))
+#if LLVM_HAS_CPP_ATTRIBUTE(gnu::warn_unused)
+#define LLVM_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]]
#else
#define LLVM_ATTRIBUTE_WARN_UNUSED
#endif
|
boomanaiden154
left a comment
There was a problem hiding this comment.
Seems reasonable enough to me.
Is there a buildbot failure link or something that this is fixing? If so, please put it in the PR description.
Thanks for the review! I've added the link just below the "GCC 12" story. |
This patch updates LLVM_ATTRIBUTE_WARN_UNUSED in Compiler.h to use the
C++11 attribute syntax [[gnu::warn_unused]] via LLVM_HAS_CPP_ATTRIBUTE
instead of attribute((warn_unused)).
GCC 12 and earlier reject:
This is exactly what happened in #237802. Specifically, it added
LLVM_ATTRIBUTE_WARN_UNUSED to APInt, which already had [[nodiscard]],
and broke GCC 12 buildbots, leading to a revert in #239152:
https://lab.llvm.org/buildbot/#/builders/181/builds/53859
This patch drops the attribute((warn_unused)) fallback because an
older compiler like Clang 5.0 would select it and fail when a class
also has [[nodiscard]]. It's always safe to expand this optional
warning macro to empty.
Assisted-by: Antigravity