Skip to content

Commit ba2edbd

Browse files
authored
[CIR] Fix warnings related to unused variables in release builds (#151412)
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 e1d45b1 commit ba2edbd

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
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
@@ -1481,9 +1481,10 @@ Address CIRGenFunction::emitArrayToPointerDecay(const Expr *e) {
14811481
if (e->getType()->isVariableArrayType())
14821482
return addr;
14831483

1484-
auto pointeeTy = mlir::cast<cir::ArrayType>(lvalueAddrTy.getPointee());
1484+
[[maybe_unused]] auto pointeeTy =
1485+
mlir::cast<cir::ArrayType>(lvalueAddrTy.getPointee());
14851486

1486-
mlir::Type arrayTy = convertType(e->getType());
1487+
[[maybe_unused]] mlir::Type arrayTy = convertType(e->getType());
14871488
assert(mlir::isa<cir::ArrayType>(arrayTy) && "expected array");
14881489
assert(pointeeTy == arrayTy);
14891490

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

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

159+
#ifndef NDEBUG
160+
// Only used in asserts
159161
static const ComplexType *getComplexType(QualType type) {
160162
type = type.getCanonicalType();
161163
if (const ComplexType *comp = dyn_cast<ComplexType>(type))
162164
return comp;
163165
return cast<ComplexType>(cast<AtomicType>(type)->getValueType());
164166
}
167+
#endif // NDEBUG
165168

166169
LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e,
167170
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +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);
220-
assert(namedVar && "Needs a named decl");
219+
assert(isa<NamedDecl>(var) && "Needs a named decl");
221220
assert(!cir::MissingFeatures::cgfSymbolTable());
222221

223222
auto allocaOp = cast<cir::AllocaOp>(addrVal.getDefiningOp());

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
7979
#define EXPR(Type, Base) case Stmt::Type##Class:
8080
#include "clang/AST/StmtNodes.inc"
8181
{
82-
// Remember the block we came in on.
83-
mlir::Block *incoming = builder.getInsertionBlock();
84-
assert(incoming && "expression emission must have an insertion point");
82+
assert(builder.getInsertionBlock() &&
83+
"expression emission must have an insertion point");
8584

8685
emitIgnoredExpr(cast<Expr>(s));
8786

88-
mlir::Block *outgoing = builder.getInsertionBlock();
89-
assert(outgoing && "expression emission cleared block!");
87+
// Classic codegen has a check here to see if the emitter created a new
88+
// block that isn't used (comparing the incoming and outgoing insertion
89+
// points) and deletes the outgoing block if it's not used. In CIR, we
90+
// will handle that during the cir.canonicalize pass.
9091
return mlir::success();
9192
}
9293
case Stmt::IfStmtClass:

0 commit comments

Comments
 (0)