]> granicus.if.org Git - clang/commitdiff
Fix an iterator-invalidation bug that was causing selfhost errors
authorJohn McCall <rjmccall@apple.com>
Wed, 24 Feb 2010 20:32:01 +0000 (20:32 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 24 Feb 2010 20:32:01 +0000 (20:32 +0000)
on non-darwin platforms.  Fixes PR6411. Test case doesn't reduce,
unfortunately.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97055 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp

index 01648ae074796df8c192b7dea94cc440de772186..cb8489d20240e4170044fa22b242cb76960753ca 100644 (file)
@@ -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.
@@ -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();
   }