@@ -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);
0 commit comments