Skip to content

Commit 98dc1d5

Browse files
Merge pull request #62422 from aschwaighofer/use_after_free_shadow_slot
IRGen: Fix a use-after-free error in ShadowStackSlots creation
2 parents dd015f4 + 0ca27df commit 98dc1d5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class IRGenSILFunction :
403403
/// Keeps track of the mapping of source variables to -O0 shadow copy allocas.
404404
llvm::SmallDenseMap<StackSlotKey, Address, 8> ShadowStackSlots;
405405
llvm::SmallDenseMap<llvm::Value *, Address, 8> TaskAllocStackSlots;
406-
llvm::SmallDenseMap<Decl *, SmallString<4>, 8> AnonymousVariables;
406+
llvm::SmallDenseMap<Decl *, Identifier, 8> AnonymousVariables;
407407
/// To avoid inserting elements into ValueDomPoints twice.
408408
llvm::SmallDenseSet<llvm::Value *, 8> ValueVariables;
409409
/// Holds the DominancePoint of values that are storage for a source variable.
@@ -653,15 +653,17 @@ class IRGenSILFunction :
653653
}
654654

655655
StringRef getOrCreateAnonymousVarName(VarDecl *Decl) {
656-
llvm::SmallString<4> &Name = AnonymousVariables[Decl];
656+
Identifier &Name = AnonymousVariables[Decl];
657657
if (Name.empty()) {
658658
{
659-
llvm::raw_svector_ostream S(Name);
659+
llvm::SmallString<64> NameBuffer;
660+
llvm::raw_svector_ostream S(NameBuffer);
660661
S << "$_" << NumAnonVars++;
662+
Name = IGM.Context.getIdentifier(NameBuffer);
661663
}
662664
AnonymousVariables.insert({Decl, Name});
663665
}
664-
return Name;
666+
return Name.str();
665667
}
666668

667669
template <class DebugVarCarryingInst>

0 commit comments

Comments
 (0)