[clang] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163914)

This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]],
introduced as part of C++17.
This commit is contained in:
Kazu Hirata 2025-10-17 07:27:11 -07:00 committed by GitHub
parent 041ac7a193
commit 1dfbfbd637
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 50 additions and 49 deletions

View File

@ -54,10 +54,10 @@ static bool isLocalLinkage(GlobalLinkageKind linkage) {
static bool isExternalWeakLinkage(GlobalLinkageKind linkage) {
return linkage == GlobalLinkageKind::ExternalWeakLinkage;
}
LLVM_ATTRIBUTE_UNUSED static bool isCommonLinkage(GlobalLinkageKind linkage) {
[[maybe_unused]] static bool isCommonLinkage(GlobalLinkageKind linkage) {
return linkage == GlobalLinkageKind::CommonLinkage;
}
LLVM_ATTRIBUTE_UNUSED static bool
[[maybe_unused]] static bool
isValidDeclarationLinkage(GlobalLinkageKind linkage) {
return isExternalWeakLinkage(linkage) || isExternalLinkage(linkage);
}
@ -65,8 +65,7 @@ isValidDeclarationLinkage(GlobalLinkageKind linkage) {
/// Whether the definition of this global may be replaced by something
/// non-equivalent at link time. For example, if a function has weak linkage
/// then the code defining it may be replaced by different code.
LLVM_ATTRIBUTE_UNUSED static bool
isInterposableLinkage(GlobalLinkageKind linkage) {
[[maybe_unused]] static bool isInterposableLinkage(GlobalLinkageKind linkage) {
switch (linkage) {
case GlobalLinkageKind::WeakAnyLinkage:
case GlobalLinkageKind::LinkOnceAnyLinkage:
@ -89,8 +88,7 @@ isInterposableLinkage(GlobalLinkageKind linkage) {
/// Whether the definition of this global may be discarded if it is not used
/// in its compilation unit.
LLVM_ATTRIBUTE_UNUSED static bool
isDiscardableIfUnused(GlobalLinkageKind linkage) {
[[maybe_unused]] static bool isDiscardableIfUnused(GlobalLinkageKind linkage) {
return isLinkOnceLinkage(linkage) || isLocalLinkage(linkage) ||
isAvailableExternallyLinkage(linkage);
}
@ -99,7 +97,7 @@ isDiscardableIfUnused(GlobalLinkageKind linkage) {
/// Using this method outside of the code generators is almost always a
/// mistake: when working at the IR level use isInterposable instead as it
/// knows about ODR semantics.
LLVM_ATTRIBUTE_UNUSED static bool isWeakForLinker(GlobalLinkageKind linkage) {
[[maybe_unused]] static bool isWeakForLinker(GlobalLinkageKind linkage) {
return linkage == GlobalLinkageKind::WeakAnyLinkage ||
linkage == GlobalLinkageKind::WeakODRLinkage ||
linkage == GlobalLinkageKind::LinkOnceAnyLinkage ||
@ -108,7 +106,7 @@ LLVM_ATTRIBUTE_UNUSED static bool isWeakForLinker(GlobalLinkageKind linkage) {
linkage == GlobalLinkageKind::ExternalWeakLinkage;
}
LLVM_ATTRIBUTE_UNUSED static bool isValidLinkage(GlobalLinkageKind gl) {
[[maybe_unused]] static bool isValidLinkage(GlobalLinkageKind gl) {
return isExternalLinkage(gl) || isLocalLinkage(gl) || isWeakLinkage(gl) ||
isLinkOnceLinkage(gl);
}

View File

@ -23,7 +23,7 @@
namespace clang {
namespace interp {
LLVM_ATTRIBUTE_UNUSED static bool isNoopBuiltin(unsigned ID) {
[[maybe_unused]] static bool isNoopBuiltin(unsigned ID) {
switch (ID) {
case Builtin::BIas_const:
case Builtin::BIforward:

View File

@ -56,16 +56,16 @@ good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
return good();
}
LLVM_ATTRIBUTE_UNUSED
static inline bad implements_child_begin_end(
Comment::child_iterator (Comment::*)() const) {
[[maybe_unused]]
static inline bad
implements_child_begin_end(Comment::child_iterator (Comment::*)() const) {
return bad();
}
#define ASSERT_IMPLEMENTS_child_begin(function) \
(void) good(implements_child_begin_end(function))
LLVM_ATTRIBUTE_UNUSED
[[maybe_unused]]
static inline void CheckCommentASTNodes() {
#define ABSTRACT_COMMENT(COMMENT)
#define COMMENT(CLASS, PARENT) \

View File

@ -252,7 +252,7 @@ namespace {
template <class T> good implements_children(children_t T::*) {
return good();
}
LLVM_ATTRIBUTE_UNUSED
[[maybe_unused]]
static bad implements_children(children_t Stmt::*) {
return bad();
}
@ -261,15 +261,19 @@ namespace {
template <class T> good implements_getBeginLoc(getBeginLoc_t T::*) {
return good();
}
LLVM_ATTRIBUTE_UNUSED
static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) { return bad(); }
[[maybe_unused]]
static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) {
return bad();
}
typedef SourceLocation getLocEnd_t() const;
template <class T> good implements_getEndLoc(getLocEnd_t T::*) {
return good();
}
LLVM_ATTRIBUTE_UNUSED
static bad implements_getEndLoc(getLocEnd_t Stmt::*) { return bad(); }
[[maybe_unused]]
static bad implements_getEndLoc(getLocEnd_t Stmt::*) {
return bad();
}
#define ASSERT_IMPLEMENTS_children(type) \
(void) is_good(implements_children(&type::children))
@ -282,7 +286,7 @@ namespace {
/// Check whether the various Stmt classes implement their member
/// functions.
LLVM_ATTRIBUTE_UNUSED
[[maybe_unused]]
static inline void check_implementations() {
#define ABSTRACT_STMT(type)
#define STMT(type, base) \

View File

@ -151,11 +151,11 @@ namespace {
else StmtVisitor<StmtPrinter>::Visit(S);
}
void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
[[maybe_unused]] void VisitStmt(Stmt *Node) {
Indent() << "<<unknown stmt type>>" << NL;
}
void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
[[maybe_unused]] void VisitExpr(Expr *Node) {
OS << "<<unknown expr type>>";
}

View File

@ -871,7 +871,7 @@ bool ConstRecordBuilder::updateRecord(ConstantEmitter &emitter,
class ConstExprEmitter
: public StmtVisitor<ConstExprEmitter, mlir::Attribute, QualType> {
CIRGenModule &cgm;
LLVM_ATTRIBUTE_UNUSED ConstantEmitter &emitter;
[[maybe_unused]] ConstantEmitter &emitter;
public:
ConstExprEmitter(ConstantEmitter &emitter)

View File

@ -308,7 +308,7 @@ class AggValueSlot {
/// destructor for the slot. Otherwise the code which constructs it should
/// push the appropriate cleanup.
LLVM_PREFERRED_TYPE(bool)
LLVM_ATTRIBUTE_UNUSED unsigned destructedFlag : 1;
[[maybe_unused]] unsigned destructedFlag : 1;
/// This is set to true if the memory in the slot is known to be zero before
/// the assignment into it. This means that zero fields don't need to be set.
@ -327,7 +327,7 @@ class AggValueSlot {
/// object, it's important that this flag never be set when
/// evaluating an expression which constructs such an object.
LLVM_PREFERRED_TYPE(bool)
LLVM_ATTRIBUTE_UNUSED unsigned aliasedFlag : 1;
[[maybe_unused]] unsigned aliasedFlag : 1;
/// This is set to true if the tail padding of this slot might overlap
/// another object that may have already been initialized (and whose
@ -335,7 +335,7 @@ class AggValueSlot {
/// store up to the dsize of the type. Otherwise we can widen stores to
/// the size of the type.
LLVM_PREFERRED_TYPE(bool)
LLVM_ATTRIBUTE_UNUSED unsigned overlapFlag : 1;
[[maybe_unused]] unsigned overlapFlag : 1;
public:
enum IsDestructed_t { IsNotDestructed, IsDestructed };

View File

@ -609,8 +609,7 @@ llvm::MDNode *CodeGenTBAA::getValidBaseTypeInfo(QualType QTy) {
// First calculate the metadata, before recomputing the insertion point, as
// the helper can recursively call us.
llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
LLVM_ATTRIBUTE_UNUSED auto inserted =
BaseTypeMetadataCache.insert({Ty, TypeNode});
[[maybe_unused]] auto inserted = BaseTypeMetadataCache.insert({Ty, TypeNode});
assert(inserted.second && "BaseType metadata was already inserted");
return TypeNode;

View File

@ -60,7 +60,7 @@ void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
OS << "\n";
}
LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line) {
[[maybe_unused]] static void printDebugInfo(const UnwrappedLine &Line) {
printLine(llvm::dbgs(), Line);
}

View File

@ -173,7 +173,7 @@ const PointerToMemberData *BasicValueFactory::getPointerToMemberData(
return D;
}
LLVM_ATTRIBUTE_UNUSED static bool hasNoRepeatedElements(
[[maybe_unused]] static bool hasNoRepeatedElements(
llvm::ImmutableList<const CXXBaseSpecifier *> BaseSpecList) {
llvm::SmallPtrSet<QualType, 16> BaseSpecSeen;
for (const CXXBaseSpecifier *BaseSpec : BaseSpecList) {

View File

@ -983,7 +983,7 @@ public:
}
/// Check equivalence data for consistency.
[[nodiscard]] LLVM_ATTRIBUTE_UNUSED static bool
[[nodiscard]] [[maybe_unused]] static bool
isClassDataConsistent(ProgramStateRef State);
[[nodiscard]] QualType getType() const {
@ -1041,8 +1041,7 @@ private:
// Constraint functions
//===----------------------------------------------------------------------===//
[[nodiscard]] LLVM_ATTRIBUTE_UNUSED bool
areFeasible(ConstraintRangeTy Constraints) {
[[nodiscard]] [[maybe_unused]] bool areFeasible(ConstraintRangeTy Constraints) {
return llvm::none_of(
Constraints,
[](const std::pair<EquivalenceClass, RangeSet> &ClassConstraint) {
@ -1134,7 +1133,7 @@ template <class EndTy>
return End;
}
[[nodiscard]] LLVM_ATTRIBUTE_UNUSED inline std::optional<RangeSet>
[[nodiscard]] [[maybe_unused]] inline std::optional<RangeSet>
intersect(RangeSet::Factory &F, const RangeSet *End) {
// This is an extraneous conversion from a raw pointer into
// std::optional<RangeSet>

View File

@ -403,7 +403,7 @@ namespace tooling {
// This anchor is used to force the linker to link in the generated object file
// and thus register the JSONCompilationDatabasePlugin.
extern volatile int JSONAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED JSONAnchorDest = JSONAnchorSource;
[[maybe_unused]] static int JSONAnchorDest = JSONAnchorSource;
} // namespace tooling
} // namespace clang

View File

@ -96,9 +96,9 @@ createExecutorFromCommandLineArgs(int &argc, const char **argv,
// and thus register the StandaloneToolExecutorPlugin etc.
extern volatile int StandaloneToolExecutorAnchorSource;
extern volatile int AllTUsToolExecutorAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED StandaloneToolExecutorAnchorDest =
[[maybe_unused]] static int StandaloneToolExecutorAnchorDest =
StandaloneToolExecutorAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED AllTUsToolExecutorAnchorDest =
[[maybe_unused]] static int AllTUsToolExecutorAnchorDest =
AllTUsToolExecutorAnchorSource;
} // end namespace tooling

View File

@ -77,8 +77,10 @@ static Expr *IgnoreImplicit(Expr *E) {
IgnoreCXXFunctionalCastExprWrappingConstructor);
}
LLVM_ATTRIBUTE_UNUSED
static bool isImplicitExpr(Expr *E) { return IgnoreImplicit(E) != E; }
[[maybe_unused]]
static bool isImplicitExpr(Expr *E) {
return IgnoreImplicit(E) != E;
}
namespace {
/// Get start location of the Declarator from the TypeLoc.

View File

@ -27,21 +27,21 @@ template <class RangeOrSet> static std::string toString(const RangeOrSet &Obj) {
Obj.dump(SS);
return ObjRepresentation;
}
LLVM_ATTRIBUTE_UNUSED static std::string toString(const llvm::APSInt &Point) {
[[maybe_unused]] static std::string toString(const llvm::APSInt &Point) {
return toString(Point, 10);
}
// We need it here for better fail diagnostics from gtest.
LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
const RangeSet &Set) {
[[maybe_unused]] static std::ostream &operator<<(std::ostream &OS,
const RangeSet &Set) {
return OS << toString(Set);
}
// We need it here for better fail diagnostics from gtest.
LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
const Range &R) {
[[maybe_unused]] static std::ostream &operator<<(std::ostream &OS,
const Range &R) {
return OS << toString(R);
}
LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
APSIntType Ty) {
[[maybe_unused]] static std::ostream &operator<<(std::ostream &OS,
APSIntType Ty) {
return OS << (Ty.isUnsigned() ? "u" : "s") << Ty.getBitWidth();
}

View File

@ -34,13 +34,12 @@ namespace clang {
// getType() tests include whole bunch of type comparisons,
// so when something is wrong, it's good to have gtest telling us
// what are those types.
LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
const QualType &T) {
[[maybe_unused]] std::ostream &operator<<(std::ostream &OS, const QualType &T) {
return OS << T.getAsString();
}
LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
const CanQualType &T) {
[[maybe_unused]] std::ostream &operator<<(std::ostream &OS,
const CanQualType &T) {
return OS << QualType{T};
}