https://github.com/steakhal updated https://github.com/llvm/llvm-project/pull/211795
From 297041c8e1b0ee34772dc246bab97c2710b7c2d2 Mon Sep 17 00:00:00 2001 From: Balazs Benics <[email protected]> Date: Fri, 24 Jul 2026 14:47:14 +0100 Subject: [PATCH 1/4] [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the warn_unused attribute IntrusiveRefCntPtr has non-trivial ctor/dtor, thus unused variables wouldn't trigger a warning by default. However, they should. https://clang.llvm.org/docs/AttributeReference.html#warn-unused Let's mark the class with this attribute get warned about them. This would have helped catching #211518 and #211517. Supersedes #211647. --- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h index 90349e02014dd..55f80778823ad 100644 --- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -170,7 +170,7 @@ template <typename T> struct IntrusiveRefCntPtrInfo { /// This class increments its pointee's reference count when it is created, and /// decrements its refcount when it's destroyed (or is changed to point to a /// different object). -template <typename T> class IntrusiveRefCntPtr { +template <typename T> class [[gnu::warn_unused]] IntrusiveRefCntPtr { T *Obj = nullptr; public: From 79deb75811d1c7a3af9caa5dad85972c11e1ea15 Mon Sep 17 00:00:00 2001 From: Balazs Benics <[email protected]> Date: Fri, 24 Jul 2026 15:42:08 +0100 Subject: [PATCH 2/4] Define LLVM_ATTRIBUTE_WARN_UNUSED --- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h | 3 ++- llvm/include/llvm/Support/Compiler.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h index 55f80778823ad..fe98750632d05 100644 --- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -60,6 +60,7 @@ #ifndef LLVM_ADT_INTRUSIVEREFCNTPTR_H #define LLVM_ADT_INTRUSIVEREFCNTPTR_H +#include "llvm/Support/Compiler.h" #include <atomic> #include <cassert> #include <cstddef> @@ -170,7 +171,7 @@ template <typename T> struct IntrusiveRefCntPtrInfo { /// This class increments its pointee's reference count when it is created, and /// decrements its refcount when it's destroyed (or is changed to point to a /// different object). -template <typename T> class [[gnu::warn_unused]] IntrusiveRefCntPtr { +template <typename T> class LLVM_ATTRIBUTE_WARN_UNUSED IntrusiveRefCntPtr { T *Obj = nullptr; public: diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index 34b328ba1ac8a..753b1e12f721d 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -238,6 +238,12 @@ #define LLVM_ATTRIBUTE_USED #endif +#if __has_attribute(warn_unused) +#define LLVM_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]] +#else +#define LLVM_ATTRIBUTE_WARN_UNUSED +#endif + // Only enabled for clang: // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587 // GCC may produce "warning: 'retain' attribute ignored" (despite From 5add1d09fa34edadd1f84f02ddbeb270d3934d46 Mon Sep 17 00:00:00 2001 From: Balazs Benics <[email protected]> Date: Fri, 24 Jul 2026 16:16:36 +0100 Subject: [PATCH 3/4] Use the __attribute__ style --- llvm/include/llvm/Support/Compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index 753b1e12f721d..f9dc2e8d45c4d 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -239,7 +239,7 @@ #endif #if __has_attribute(warn_unused) -#define LLVM_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]] +#define LLVM_ATTRIBUTE_WARN_UNUSED __attribute__((warn_unused)) #else #define LLVM_ATTRIBUTE_WARN_UNUSED #endif From 36eeb78bf71ed4ed2d1314298c079dc91c1f00aa Mon Sep 17 00:00:00 2001 From: Balazs Benics <[email protected]> Date: Sun, 26 Jul 2026 11:05:38 +0100 Subject: [PATCH 4/4] Drop unused FS variables The `RecordedIncludesTest` unittests had some unused FS variables: - `Match` was introduced with the unused variable in 8249dc21046af57ad3b2c72414aa8a7f16b67687 - `MatchVerbatim` and `MatchVerbatimMixedAbsoluteRelative` was introduced in 16b5e1897b7efaa4250b04dface0c807a02ae31a --- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp b/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp index 6f7491928fb05..dffc778240a80 100644 --- a/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/TypesTest.cpp @@ -11,8 +11,6 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Tooling/Inclusions/StandardLibrary.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/Support/VirtualFileSystem.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -28,7 +26,6 @@ MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; } TEST(RecordedIncludesTest, Match) { // We're using synthetic data, but need a FileManager to obtain FileEntry*s. // Ensure it doesn't do any actual IO. - auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager FM(FileSystemOptions{}); FileEntryRef A = FM.getVirtualFileRef("/path/a", /*Size=*/0, time_t{}); FileEntryRef B = FM.getVirtualFileRef("/path/b", /*Size=*/0, time_t{}); @@ -48,7 +45,6 @@ TEST(RecordedIncludesTest, Match) { } TEST(RecordedIncludesTest, MatchVerbatim) { - auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); FileManager FM(FileSystemOptions{}); Includes Inc; @@ -79,8 +75,6 @@ TEST(RecordedIncludesTest, MatchVerbatim) { } TEST(RecordedIncludesTest, MatchVerbatimMixedAbsoluteRelative) { - auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); - FS->setCurrentWorkingDirectory("/working"); FileManager FM(FileSystemOptions{}); Includes Inc; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
