Skip to content

Commit 5ad8b1a

Browse files
committed
Address review feedback
1 parent 69c7104 commit 5ad8b1a

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

clang/lib/CIR/CodeGen/CIRGenConstantEmitter.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ class ConstantEmitter {
8282
mlir::Attribute tryEmitAbstractForInitializer(const VarDecl &d);
8383

8484
private:
85-
struct AbstractState {
85+
class AbstractStateRAII {
86+
ConstantEmitter &emitter;
8687
bool oldValue;
88+
89+
public:
90+
AbstractStateRAII(ConstantEmitter &emitter, bool value)
91+
: emitter(emitter), oldValue(emitter.abstract) {
92+
emitter.abstract = value;
93+
}
94+
~AbstractStateRAII() { emitter.abstract = oldValue; }
8795
};
88-
AbstractState pushAbstract() {
89-
AbstractState saved = {abstract};
90-
abstract = true;
91-
return saved;
92-
}
93-
mlir::Attribute validateAndPopAbstract(mlir::Attribute C, AbstractState save);
9496
};
9597

9698
} // namespace clang::CIRGen

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ bool CIRGenFunction::isTrivialInitializer(const Expr *init) {
7575

7676
void CIRGenFunction::emitAutoVarInit(
7777
const CIRGenFunction::AutoVarEmission &emission) {
78+
assert(emission.Variable && "emission was not valid!");
79+
80+
// If this was emitted as a global constant, we're done.
81+
if (emission.wasEmittedAsGlobal())
82+
return;
83+
7884
const VarDecl &d = *emission.Variable;
7985

8086
QualType type = d.getType();
@@ -209,22 +215,17 @@ void CIRGenFunction::emitVarDecl(const VarDecl &d) {
209215

210216
void CIRGenFunction::emitScalarInit(const Expr *init, mlir::Location loc,
211217
LValue lvalue, bool capturedByInit) {
212-
Qualifiers::ObjCLifetime lifetime = Qualifiers::ObjCLifetime::OCL_None;
213218
assert(!cir::MissingFeatures::objCLifetime());
214219

215-
if (!lifetime) {
216-
SourceLocRAIIObject locRAII{*this, loc};
217-
mlir::Value value = emitScalarExpr(init);
218-
if (capturedByInit) {
219-
cgm.errorNYI(init->getSourceRange(), "emitScalarInit: captured by init");
220-
return;
221-
}
222-
assert(!cir::MissingFeatures::emitNullabilityCheck());
223-
emitStoreThroughLValue(RValue::get(value), lvalue, true);
220+
SourceLocRAIIObject locRAII{*this, loc};
221+
mlir::Value value = emitScalarExpr(init);
222+
if (capturedByInit) {
223+
cgm.errorNYI(init->getSourceRange(), "emitScalarInit: captured by init");
224224
return;
225225
}
226-
227-
cgm.errorNYI(loc, "emitScalarInit: ObjCLifetime");
226+
assert(!cir::MissingFeatures::emitNullabilityCheck());
227+
emitStoreThroughLValue(RValue::get(value), lvalue, true);
228+
return;
228229
}
229230

230231
void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d,

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,10 @@ static QualType getNonMemoryType(CIRGenModule &cgm, QualType type) {
169169
// ConstantEmitter
170170
//===----------------------------------------------------------------------===//
171171

172-
mlir::Attribute ConstantEmitter::validateAndPopAbstract(mlir::Attribute c,
173-
AbstractState saved) {
174-
abstract = saved.oldValue;
175-
176-
// No validation necessary for now.
177-
// No cleanup to do for now.
178-
return c;
179-
}
180-
181172
mlir::Attribute
182173
ConstantEmitter::tryEmitAbstractForInitializer(const VarDecl &d) {
183-
AbstractState state = pushAbstract();
184-
mlir::Attribute c = tryEmitPrivateForVarInit(d);
185-
return validateAndPopAbstract(c, state);
174+
AbstractStateRAII state(*this, true);
175+
return tryEmitPrivateForVarInit(d);
186176
}
187177

188178
mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) {
@@ -241,11 +231,10 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForMemory(const APValue &value,
241231
mlir::Attribute ConstantEmitter::emitAbstract(SourceLocation loc,
242232
const APValue &value,
243233
QualType destType) {
244-
AbstractState state = pushAbstract();
234+
AbstractStateRAII state(*this, true);
245235
mlir::Attribute c = tryEmitPrivate(value, destType);
246-
c = validateAndPopAbstract(c, state);
247236
if (!c)
248-
cgm.errorNYI(loc, "emitAbstract failed");
237+
cgm.errorNYI(loc, "emitAbstract failed, emit null constaant");
249238
return c;
250239
}
251240

@@ -266,8 +255,6 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
266255
switch (value.getKind()) {
267256
case APValue::None:
268257
case APValue::Indeterminate:
269-
// TODO(cir): LLVM models out-of-lifetime and indeterminate values as
270-
// 'undef'. Find out what's better for CIR.
271258
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate none or indeterminate");
272259
return {};
273260
case APValue::Int: {

0 commit comments

Comments
 (0)