Skip to content

Commit ceabe27

Browse files
committed
[CIR] Fix warnings related to unused variables in release builds
This fixes a number of warnings in release builds due to variables that were only being used in asserts. Some of these variables will later be used in non-debug code, but for now they are unused in release builds.
1 parent 254b90f commit ceabe27

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct CallArg {
137137

138138
/// A data-flow flag to make sure getRValue and/or copyInto are not
139139
/// called twice for duplicated IR emission.
140-
mutable bool isUsed;
140+
[[maybe_unused]] mutable bool isUsed;
141141

142142
public:
143143
clang::QualType ty;

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,9 +1472,10 @@ Address CIRGenFunction::emitArrayToPointerDecay(const Expr *e) {
14721472
if (e->getType()->isVariableArrayType())
14731473
return addr;
14741474

1475-
auto pointeeTy = mlir::cast<cir::ArrayType>(lvalueAddrTy.getPointee());
1475+
[[maybe_unused]] auto pointeeTy =
1476+
mlir::cast<cir::ArrayType>(lvalueAddrTy.getPointee());
14761477

1477-
mlir::Type arrayTy = convertType(e->getType());
1478+
[[maybe_unused]] mlir::Type arrayTy = convertType(e->getType());
14781479
assert(mlir::isa<cir::ArrayType>(arrayTy) && "expected array");
14791480
assert(pointeeTy == arrayTy);
14801481

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
154154
};
155155
} // namespace
156156

157+
#ifndef NDEBUG
158+
// Only used in asserts
157159
static const ComplexType *getComplexType(QualType type) {
158160
type = type.getCanonicalType();
159161
if (const ComplexType *comp = dyn_cast<ComplexType>(type))
160162
return comp;
161163
return cast<ComplexType>(cast<AtomicType>(type)->getValueType());
162164
}
165+
#endif // NDEBUG
163166

164167
LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e,
165168
mlir::Value &value) {

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
439439
value = builder.getTrue(cgf.getLoc(e->getExprLoc()));
440440
} else if (type->isIntegerType()) {
441441
QualType promotedType;
442-
bool canPerformLossyDemotionCheck = false;
442+
[[maybe_unused]] bool canPerformLossyDemotionCheck = false;
443443
if (cgf.getContext().isPromotableIntegerType(type)) {
444444
promotedType = cgf.getContext().getPromotedIntegerType(type);
445445
assert(promotedType != type && "Shouldn't promote to the same type.");

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void CIRGenFunction::emitAndUpdateRetAlloca(QualType type, mlir::Location loc,
216216
void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
217217
mlir::Location loc, CharUnits alignment,
218218
bool isParam) {
219-
const auto *namedVar = dyn_cast_or_null<NamedDecl>(var);
219+
[[maybe_unused]] const auto *namedVar = dyn_cast_or_null<NamedDecl>(var);
220220
assert(namedVar && "Needs a named decl");
221221
assert(!cir::MissingFeatures::cgfSymbolTable());
222222

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,6 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty,
656656

657657
void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
658658
bool isTentative) {
659-
const QualType astTy = vd->getType();
660-
661659
if (getLangOpts().OpenCL || getLangOpts().OpenMPIsTargetDevice) {
662660
errorNYI(vd->getSourceRange(), "emit OpenCL/OpenMP global variable");
663661
return;
@@ -701,7 +699,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
701699
// never attempt to emit a tentative definition if a real one
702700
// exists. A use may still exists, however, so we still may need
703701
// to do a RAUW.
704-
assert(!astTy->isIncompleteType() && "Unexpected incomplete type");
702+
assert(!vd->getType()->isIncompleteType() && "Unexpected incomplete type");
705703
init = builder.getZeroInitAttr(convertType(vd->getType()));
706704
} else {
707705
emitter.emplace(*this);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
8080
#include "clang/AST/StmtNodes.inc"
8181
{
8282
// Remember the block we came in on.
83-
mlir::Block *incoming = builder.getInsertionBlock();
83+
[[maybe_unused]] mlir::Block *incoming = builder.getInsertionBlock();
8484
assert(incoming && "expression emission must have an insertion point");
8585

8686
emitIgnoredExpr(cast<Expr>(s));
8787

88-
mlir::Block *outgoing = builder.getInsertionBlock();
88+
[[maybe_unused]] mlir::Block *outgoing = builder.getInsertionBlock();
8989
assert(outgoing && "expression emission cleared block!");
9090
return mlir::success();
9191
}

0 commit comments

Comments
 (0)