Skip to content

Commit

Permalink
Fix an iterator-invalidation bug that was causing selfhost errors
Browse files Browse the repository at this point in the history
on non-darwin platforms.  Fixes PR6411. Test case doesn't reduce,
unfortunately.

llvm-svn: 97055
  • Loading branch information
rjmccall committed Feb 24, 2010
1 parent 05d9124 commit aea181d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions clang/lib/CodeGen/CGCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,6 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
const llvm::PointerType *AliasType
= getTypes().GetFunctionType(AliasDecl)->getPointerTo();

// Look for an existing entry.
const char *MangledName = getMangledName(AliasDecl);
llvm::GlobalValue *&Entry = GlobalDeclMap[MangledName];
if (Entry) {
assert(Entry->isDeclaration() && "definition already exists for alias");
assert(Entry->getType() == AliasType &&
"declaration exists with different type");
}

// Find the referrent. Some aliases might require a bitcast, in
// which case the caller is responsible for ensuring the soundness
// of these semantics.
Expand All @@ -161,8 +152,13 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
llvm::GlobalAlias *Alias =
new llvm::GlobalAlias(AliasType, Linkage, "", Aliasee, &getModule());

// Switch any previous uses to the alias and kill the previous decl.
// Switch any previous uses to the alias.
const char *MangledName = getMangledName(AliasDecl);
llvm::GlobalValue *&Entry = GlobalDeclMap[MangledName];
if (Entry) {
assert(Entry->isDeclaration() && "definition already exists for alias");
assert(Entry->getType() == AliasType &&
"declaration exists with different type");
Entry->replaceAllUsesWith(Alias);
Entry->eraseFromParent();
}
Expand Down

0 comments on commit aea181d

Please sign in to comment.