diff --git a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp index 543ba8b7cfda..4d8174aaa3d1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp @@ -18,6 +18,7 @@ #include "clang/AST/GlobalDecl.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SaveAndRestore.h" #include using namespace clang; @@ -337,7 +338,7 @@ void CIRGenModule::buildCXXGlobalVarDeclInit(const VarDecl *varDecl, assert(varDecl && " Expected a global declaration!"); CIRGenFunction cgf{*this, builder, true}; - CurCGF = &cgf; + llvm::SaveAndRestore savedCGF(CurCGF, &cgf); CurCGF->CurFn = addr; CIRGenFunction::SourceLocRAIIObject fnLoc{cgf, @@ -421,6 +422,4 @@ void CIRGenModule::buildCXXGlobalVarDeclInit(const VarDecl *varDecl, builder.create(addr->getLoc()); } } - - CurCGF = nullptr; }