Skip to content

Commit 1dfbfbd

Browse files
[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.
1 parent 041ac7a commit 1dfbfbd

File tree

16 files changed

+50
-49
lines changed

16 files changed

+50
-49
lines changed

clang/include/clang/CIR/Dialect/IR/CIROpsEnums.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ static bool isLocalLinkage(GlobalLinkageKind linkage) {
5454
static bool isExternalWeakLinkage(GlobalLinkageKind linkage) {
5555
return linkage == GlobalLinkageKind::ExternalWeakLinkage;
5656
}
57-
LLVM_ATTRIBUTE_UNUSED static bool isCommonLinkage(GlobalLinkageKind linkage) {
57+
[[maybe_unused]] static bool isCommonLinkage(GlobalLinkageKind linkage) {
5858
return linkage == GlobalLinkageKind::CommonLinkage;
5959
}
60-
LLVM_ATTRIBUTE_UNUSED static bool
60+
[[maybe_unused]] static bool
6161
isValidDeclarationLinkage(GlobalLinkageKind linkage) {
6262
return isExternalWeakLinkage(linkage) || isExternalLinkage(linkage);
6363
}
6464

6565
/// Whether the definition of this global may be replaced by something
6666
/// non-equivalent at link time. For example, if a function has weak linkage
6767
/// then the code defining it may be replaced by different code.
68-
LLVM_ATTRIBUTE_UNUSED static bool
69-
isInterposableLinkage(GlobalLinkageKind linkage) {
68+
[[maybe_unused]] static bool isInterposableLinkage(GlobalLinkageKind linkage) {
7069
switch (linkage) {
7170
case GlobalLinkageKind::WeakAnyLinkage:
7271
case GlobalLinkageKind::LinkOnceAnyLinkage:
@@ -89,8 +88,7 @@ isInterposableLinkage(GlobalLinkageKind linkage) {
8988

9089
/// Whether the definition of this global may be discarded if it is not used
9190
/// in its compilation unit.
92-
LLVM_ATTRIBUTE_UNUSED static bool
93-
isDiscardableIfUnused(GlobalLinkageKind linkage) {
91+
[[maybe_unused]] static bool isDiscardableIfUnused(GlobalLinkageKind linkage) {
9492
return isLinkOnceLinkage(linkage) || isLocalLinkage(linkage) ||
9593
isAvailableExternallyLinkage(linkage);
9694
}
@@ -99,7 +97,7 @@ isDiscardableIfUnused(GlobalLinkageKind linkage) {
9997
/// Using this method outside of the code generators is almost always a
10098
/// mistake: when working at the IR level use isInterposable instead as it
10199
/// knows about ODR semantics.
102-
LLVM_ATTRIBUTE_UNUSED static bool isWeakForLinker(GlobalLinkageKind linkage) {
100+
[[maybe_unused]] static bool isWeakForLinker(GlobalLinkageKind linkage) {
103101
return linkage == GlobalLinkageKind::WeakAnyLinkage ||
104102
linkage == GlobalLinkageKind::WeakODRLinkage ||
105103
linkage == GlobalLinkageKind::LinkOnceAnyLinkage ||
@@ -108,7 +106,7 @@ LLVM_ATTRIBUTE_UNUSED static bool isWeakForLinker(GlobalLinkageKind linkage) {
108106
linkage == GlobalLinkageKind::ExternalWeakLinkage;
109107
}
110108

111-
LLVM_ATTRIBUTE_UNUSED static bool isValidLinkage(GlobalLinkageKind gl) {
109+
[[maybe_unused]] static bool isValidLinkage(GlobalLinkageKind gl) {
112110
return isExternalLinkage(gl) || isLocalLinkage(gl) || isWeakLinkage(gl) ||
113111
isLinkOnceLinkage(gl);
114112
}

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace clang {
2424
namespace interp {
2525

26-
LLVM_ATTRIBUTE_UNUSED static bool isNoopBuiltin(unsigned ID) {
26+
[[maybe_unused]] static bool isNoopBuiltin(unsigned ID) {
2727
switch (ID) {
2828
case Builtin::BIas_const:
2929
case Builtin::BIforward:

clang/lib/AST/Comment.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
5656
return good();
5757
}
5858

59-
LLVM_ATTRIBUTE_UNUSED
60-
static inline bad implements_child_begin_end(
61-
Comment::child_iterator (Comment::*)() const) {
59+
[[maybe_unused]]
60+
static inline bad
61+
implements_child_begin_end(Comment::child_iterator (Comment::*)() const) {
6262
return bad();
6363
}
6464

6565
#define ASSERT_IMPLEMENTS_child_begin(function) \
6666
(void) good(implements_child_begin_end(function))
6767

68-
LLVM_ATTRIBUTE_UNUSED
68+
[[maybe_unused]]
6969
static inline void CheckCommentASTNodes() {
7070
#define ABSTRACT_COMMENT(COMMENT)
7171
#define COMMENT(CLASS, PARENT) \

clang/lib/AST/Stmt.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace {
252252
template <class T> good implements_children(children_t T::*) {
253253
return good();
254254
}
255-
LLVM_ATTRIBUTE_UNUSED
255+
[[maybe_unused]]
256256
static bad implements_children(children_t Stmt::*) {
257257
return bad();
258258
}
@@ -261,15 +261,19 @@ namespace {
261261
template <class T> good implements_getBeginLoc(getBeginLoc_t T::*) {
262262
return good();
263263
}
264-
LLVM_ATTRIBUTE_UNUSED
265-
static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) { return bad(); }
264+
[[maybe_unused]]
265+
static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) {
266+
return bad();
267+
}
266268

267269
typedef SourceLocation getLocEnd_t() const;
268270
template <class T> good implements_getEndLoc(getLocEnd_t T::*) {
269271
return good();
270272
}
271-
LLVM_ATTRIBUTE_UNUSED
272-
static bad implements_getEndLoc(getLocEnd_t Stmt::*) { return bad(); }
273+
[[maybe_unused]]
274+
static bad implements_getEndLoc(getLocEnd_t Stmt::*) {
275+
return bad();
276+
}
273277

274278
#define ASSERT_IMPLEMENTS_children(type) \
275279
(void) is_good(implements_children(&type::children))
@@ -282,7 +286,7 @@ namespace {
282286

283287
/// Check whether the various Stmt classes implement their member
284288
/// functions.
285-
LLVM_ATTRIBUTE_UNUSED
289+
[[maybe_unused]]
286290
static inline void check_implementations() {
287291
#define ABSTRACT_STMT(type)
288292
#define STMT(type, base) \

clang/lib/AST/StmtPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ namespace {
151151
else StmtVisitor<StmtPrinter>::Visit(S);
152152
}
153153

154-
void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
154+
[[maybe_unused]] void VisitStmt(Stmt *Node) {
155155
Indent() << "<<unknown stmt type>>" << NL;
156156
}
157157

158-
void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
158+
[[maybe_unused]] void VisitExpr(Expr *Node) {
159159
OS << "<<unknown expr type>>";
160160
}
161161

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ bool ConstRecordBuilder::updateRecord(ConstantEmitter &emitter,
871871
class ConstExprEmitter
872872
: public StmtVisitor<ConstExprEmitter, mlir::Attribute, QualType> {
873873
CIRGenModule &cgm;
874-
LLVM_ATTRIBUTE_UNUSED ConstantEmitter &emitter;
874+
[[maybe_unused]] ConstantEmitter &emitter;
875875

876876
public:
877877
ConstExprEmitter(ConstantEmitter &emitter)

clang/lib/CIR/CodeGen/CIRGenValue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class AggValueSlot {
308308
/// destructor for the slot. Otherwise the code which constructs it should
309309
/// push the appropriate cleanup.
310310
LLVM_PREFERRED_TYPE(bool)
311-
LLVM_ATTRIBUTE_UNUSED unsigned destructedFlag : 1;
311+
[[maybe_unused]] unsigned destructedFlag : 1;
312312

313313
/// This is set to true if the memory in the slot is known to be zero before
314314
/// the assignment into it. This means that zero fields don't need to be set.
@@ -327,15 +327,15 @@ class AggValueSlot {
327327
/// object, it's important that this flag never be set when
328328
/// evaluating an expression which constructs such an object.
329329
LLVM_PREFERRED_TYPE(bool)
330-
LLVM_ATTRIBUTE_UNUSED unsigned aliasedFlag : 1;
330+
[[maybe_unused]] unsigned aliasedFlag : 1;
331331

332332
/// This is set to true if the tail padding of this slot might overlap
333333
/// another object that may have already been initialized (and whose
334334
/// value must be preserved by this initialization). If so, we may only
335335
/// store up to the dsize of the type. Otherwise we can widen stores to
336336
/// the size of the type.
337337
LLVM_PREFERRED_TYPE(bool)
338-
LLVM_ATTRIBUTE_UNUSED unsigned overlapFlag : 1;
338+
[[maybe_unused]] unsigned overlapFlag : 1;
339339

340340
public:
341341
enum IsDestructed_t { IsNotDestructed, IsDestructed };

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ llvm::MDNode *CodeGenTBAA::getValidBaseTypeInfo(QualType QTy) {
609609
// First calculate the metadata, before recomputing the insertion point, as
610610
// the helper can recursively call us.
611611
llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
612-
LLVM_ATTRIBUTE_UNUSED auto inserted =
613-
BaseTypeMetadataCache.insert({Ty, TypeNode});
612+
[[maybe_unused]] auto inserted = BaseTypeMetadataCache.insert({Ty, TypeNode});
614613
assert(inserted.second && "BaseType metadata was already inserted");
615614

616615
return TypeNode;

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
6060
OS << "\n";
6161
}
6262

63-
LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line) {
63+
[[maybe_unused]] static void printDebugInfo(const UnwrappedLine &Line) {
6464
printLine(llvm::dbgs(), Line);
6565
}
6666

clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const PointerToMemberData *BasicValueFactory::getPointerToMemberData(
173173
return D;
174174
}
175175

176-
LLVM_ATTRIBUTE_UNUSED static bool hasNoRepeatedElements(
176+
[[maybe_unused]] static bool hasNoRepeatedElements(
177177
llvm::ImmutableList<const CXXBaseSpecifier *> BaseSpecList) {
178178
llvm::SmallPtrSet<QualType, 16> BaseSpecSeen;
179179
for (const CXXBaseSpecifier *BaseSpec : BaseSpecList) {

0 commit comments

Comments
 (0)