Skip to content

Commit 851bca6

Browse files
committed
[CIR][CodeGen] Store the old CIRGenFunction when popping to a new one
We diverge from CodeGen here by delaying the function emission that happens for a global variable. However, due to situations where a global can be emitted while building out a function the old CGF might not be invalid. So we need to store it here just in case. Reviewers: bcardosolopes, smeenai Reviewed By: smeenai Pull Request: #1023
1 parent db61ac6 commit 851bca6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "clang/AST/GlobalDecl.h"
2020
#include "llvm/Support/ErrorHandling.h"
21+
#include "llvm/Support/SaveAndRestore.h"
2122
#include <cassert>
2223

2324
using namespace clang;
@@ -337,7 +338,7 @@ void CIRGenModule::buildCXXGlobalVarDeclInit(const VarDecl *varDecl,
337338

338339
assert(varDecl && " Expected a global declaration!");
339340
CIRGenFunction cgf{*this, builder, true};
340-
CurCGF = &cgf;
341+
llvm::SaveAndRestore<CIRGenFunction*> savedCGF(CurCGF, &cgf);
341342
CurCGF->CurFn = addr;
342343

343344
CIRGenFunction::SourceLocRAIIObject fnLoc{cgf,
@@ -421,6 +422,4 @@ void CIRGenModule::buildCXXGlobalVarDeclInit(const VarDecl *varDecl,
421422
builder.create<mlir::cir::YieldOp>(addr->getLoc());
422423
}
423424
}
424-
425-
CurCGF = nullptr;
426425
}

0 commit comments

Comments
 (0)