From b723f7520bcce5f13ccaae557c16a1e7133b6908 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 4 Jan 2009 02:08:04 +0000 Subject: Fix the bug that would cause Python to crash at startup. When emitting the static variables we need to make sure that the order is preserved. Fix this by making StaticDecls a std::list which has O(1) random removal. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61621 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index fc1b108b0d..021e9af676 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -361,26 +361,27 @@ void CodeGenModule::EmitStatics() { bool Changed; do { Changed = false; - for (unsigned i = 0, e = StaticDecls.size(); i != e; ++i) { - const ValueDecl *D = StaticDecls[i]; - + + for (std::list::iterator i = StaticDecls.begin(), + e = StaticDecls.end(); i != e; ) { + const ValueDecl *D = *i; + // Check if we have used a decl with the same name // FIXME: The AST should have some sort of aggregate decls or // global symbol map. // FIXME: This is missing some important cases. For example, we // need to check for uses in an alias and in a constructor. - if (!GlobalDeclMap.count(D->getIdentifier())) + if (!GlobalDeclMap.count(D->getIdentifier())) { + i++; continue; - + } + // Emit the definition. EmitGlobalDefinition(D); // Erase the used decl from the list. - StaticDecls[i] = StaticDecls.back(); - StaticDecls.pop_back(); - --i; - --e; - + i = StaticDecls.erase(i); + // Remember that we made a change. Changed = true; } -- cgit v1.2.3-18-g5258