Skip to content

Commit 48ae8f9

Browse files
committed
Do suggested changes by andy
1 parent 319e93c commit 48ae8f9

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,18 +529,32 @@ class CIRGenFunction : public CIRGenTypeCache {
529529
symbolTable.insert(vd, addr.getPointer());
530530
}
531531

532-
// A class to allow inserting things into the declaration map during some sort
533-
// of alternative generation (used currently for the OpenACC recipe
534-
// generation), then reverting changes after the fact.
532+
// A class to allow reverting changes to a var-decl's registration to the
533+
// localDeclMap. This is used in cases where things are being inserted into
534+
// the variable list but don't follow normal lookup/search rules, like in
535+
// OpenACC recipe generation.
535536
class DeclMapRevertingRAII {
536537
CIRGenFunction &cgf;
537-
CIRGenFunction::DeclMapTy originalMap;
538+
const VarDecl *vd;
539+
bool shouldDelete = false;
540+
Address oldAddr = Address::invalid();
538541

539542
public:
540-
DeclMapRevertingRAII(CIRGenFunction &cgf)
541-
: cgf(cgf), originalMap(cgf.localDeclMap) {}
543+
DeclMapRevertingRAII(CIRGenFunction &cgf, const VarDecl *vd) : cgf(cgf), vd(vd) {
544+
auto mapItr = cgf.localDeclMap.find(vd);
542545

543-
~DeclMapRevertingRAII() { cgf.localDeclMap = std::move(originalMap); }
546+
if (mapItr != cgf.localDeclMap.end())
547+
oldAddr = mapItr->second;
548+
else
549+
shouldDelete = true;
550+
}
551+
552+
~DeclMapRevertingRAII() {
553+
if (shouldDelete)
554+
cgf.localDeclMap.erase(vd);
555+
else
556+
cgf.localDeclMap.insert_or_assign(vd, oldAddr);
557+
}
544558
};
545559

546560
bool shouldNullCheckClassCastValue(const CastExpr *ce);

clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ class OpenACCClauseCIREmitter final
409409
Address{toArg, elementTy, cgf.getContext().getDeclAlign(varRecipe)});
410410
tempDeclEmission.EmittedAsOffload = true;
411411

412+
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf,temporary};
412413
cgf.setAddrOfLocalVar(
413414
temporary,
414415
Address{fromArg, elementTy, cgf.getContext().getDeclAlign(varRecipe)});
@@ -433,7 +434,7 @@ class OpenACCClauseCIREmitter final
433434

434435
CIRGenFunction::AutoVarEmission tempDeclEmission{
435436
CIRGenFunction::AutoVarEmission::invalid()};
436-
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf};
437+
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf, varRecipe};
437438

438439
// Do the 'init' section of the recipe IR, which does an alloca, then the
439440
// initialization (except for firstprivate).

0 commit comments

Comments
 (0)