Skip to content

Commit 2676b6a

Browse files
committed
* introduce maybeEmitDeferredVarDeclInit
* reformat rest
1 parent 6f62ea0 commit 2676b6a

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d,
520520
llvm_unreachable("bad evaluation kind");
521521
}
522522

523-
void CIRGenFunction::emitDecl(const Decl &d) {
523+
void CIRGenFunction::emitDecl(const Decl &d, bool evaluateConditionDecl) {
524524
switch (d.getKind()) {
525525
case Decl::BuiltinTemplate:
526526
case Decl::TranslationUnit:
@@ -614,10 +614,8 @@ void CIRGenFunction::emitDecl(const Decl &d) {
614614
assert(vd.isLocalVarDecl() &&
615615
"Should not see file-scope variables inside a function!");
616616
emitVarDecl(vd);
617-
if (auto *dd = dyn_cast<DecompositionDecl>(&vd))
618-
for (BindingDecl *b : dd->bindings())
619-
if (VarDecl *hd = b->getHoldingVar())
620-
emitVarDecl(*hd);
617+
if (evaluateConditionDecl)
618+
maybeEmitDeferredVarDeclInit(&vd);
621619
return;
622620
}
623621
case Decl::OpenACCDeclare:
@@ -801,3 +799,11 @@ void CIRGenFunction::emitAutoVarTypeCleanup(
801799
assert(!cir::MissingFeatures::ehCleanupFlags());
802800
ehStack.pushCleanup<DestroyObject>(cleanupKind, addr, type, destroyer);
803801
}
802+
803+
void CIRGenFunction::maybeEmitDeferredVarDeclInit(const VarDecl *vd) {
804+
if (auto *dd = dyn_cast_if_present<DecompositionDecl>(vd)) {
805+
for (auto *b : dd->flat_bindings())
806+
if (auto *hd = b->getHoldingVar())
807+
emitVarDecl(*hd);
808+
}
809+
}

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,11 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
585585
}
586586

587587
if (const auto *bd = dyn_cast<BindingDecl>(nd)) {
588-
assert(!e->refersToEnclosingVariableOrCapture() &&
589-
!cir::MissingFeatures::lambdaCaptures());
588+
if (e->refersToEnclosingVariableOrCapture()) {
589+
assert(!cir::MissingFeatures::lambdaCaptures());
590+
cgm.errorNYI(e->getSourceRange(), "emitDeclRefLValue: lambda captures");
591+
return LValue();
592+
}
590593
return emitLValue(bd->getBinding());
591594
}
592595

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ class CIRGenFunction : public CIRGenTypeCache {
870870
void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
871871
clang::QualType::DestructionKind dtorKind);
872872

873+
void maybeEmitDeferredVarDeclInit(const VarDecl *vd);
874+
873875
void emitBaseInitializer(mlir::Location loc, const CXXRecordDecl *classDecl,
874876
CXXCtorInitializer *baseInit);
875877

@@ -1059,7 +1061,7 @@ class CIRGenFunction : public CIRGenTypeCache {
10591061

10601062
void emitCompoundStmtWithoutScope(const clang::CompoundStmt &s);
10611063

1062-
void emitDecl(const clang::Decl &d);
1064+
void emitDecl(const clang::Decl &d, bool evaluateConditionDecl = false);
10631065
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
10641066
LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
10651067

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) {
363363
mlir::LogicalResult CIRGenFunction::emitDeclStmt(const DeclStmt &s) {
364364
assert(builder.getInsertionBlock() && "expected valid insertion point");
365365

366-
for (const Decl *I : s.decls())
367-
emitDecl(*I);
366+
for (const Decl *i : s.decls())
367+
emitDecl(*i, /*evaluateConditionDecl=*/true);
368368

369369
return mlir::success();
370370
}
@@ -875,7 +875,7 @@ mlir::LogicalResult CIRGenFunction::emitSwitchStmt(const clang::SwitchStmt &s) {
875875
return mlir::failure();
876876

877877
if (s.getConditionVariable())
878-
emitDecl(*s.getConditionVariable());
878+
emitDecl(*s.getConditionVariable(), /*evaluateConditionDecl=*/true);
879879

880880
mlir::Value condV = emitScalarExpr(s.getCond());
881881

clang/test/CIR/CodeGen/variable-decomposition.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
77

88
struct some_struct {
9-
int a;
10-
float b;
9+
int a;
10+
float b;
1111
};
1212

1313
float function() {
14-
auto[a, b] = some_struct{1, 2.f};
14+
auto[a, b] = some_struct{1, 2.f};
1515

16-
return a + b;
16+
return a + b;
1717
}
1818

1919
// CIR-LABEL: cir.func dso_local @_Z8functionv() -> !cir.float

0 commit comments

Comments
 (0)