[cfe-commits] r68155 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/mangle.c
Chris Lattner
sabre at nondot.org
Tue Mar 31 15:37:52 PDT 2009
Author: lattner
Date: Tue Mar 31 17:37:52 2009
New Revision: 68155
URL: http://llvm.org/viewvc/llvm-project?rev=68155&view=rev
Log:
Change UsedArray to be a vector of WeakVH to fix a dangling pointer problem that occurs when
attribute(used) and asm renaming are used together.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGen/mangle.c
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68155&r1=68154&r2=68155&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Mar 31 17:37:52 2009
@@ -320,8 +320,7 @@
void CodeGenModule::AddUsedGlobal(llvm::GlobalValue *GV) {
assert(!GV->isDeclaration() &&
"Only globals with definition can force usage.");
- llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
- LLVMUsed.push_back(llvm::ConstantExpr::getBitCast(GV, i8PTy));
+ LLVMUsed.push_back(GV);
}
void CodeGenModule::EmitLLVMUsed() {
@@ -329,12 +328,21 @@
if (LLVMUsed.empty())
return;
- llvm::ArrayType *ATy = llvm::ArrayType::get(LLVMUsed[0]->getType(),
- LLVMUsed.size());
+ llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+ llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, LLVMUsed.size());
+
+ // Convert LLVMUsed to what ConstantArray needs.
+ std::vector<llvm::Constant*> UsedArray;
+ UsedArray.resize(LLVMUsed.size());
+ for (unsigned i = 0, e = LLVMUsed.size(); i != e; ++i) {
+ UsedArray[i] =
+ llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*LLVMUsed[i]), i8PTy);
+ }
+
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(ATy, false,
llvm::GlobalValue::AppendingLinkage,
- llvm::ConstantArray::get(ATy, LLVMUsed),
+ llvm::ConstantArray::get(ATy, UsedArray),
"llvm.used", &getModule());
GV->setSection("llvm.metadata");
@@ -725,7 +733,6 @@
Entry->replaceAllUsesWith(NewPtrForOldDecl);
// Erase the old global, since it is no longer used.
- // FIXME: What if it was attribute used? Dangling pointer from LLVMUsed.
cast<llvm::GlobalValue>(Entry)->eraseFromParent();
}
@@ -839,8 +846,6 @@
Entry->replaceAllUsesWith(NewPtrForOldDecl);
// Ok, delete the old function now, which is dead.
- // FIXME: If it was attribute(used) the pointer will dangle from the
- // LLVMUsed array!
cast<llvm::GlobalValue>(Entry)->eraseFromParent();
Entry = NewFn;
@@ -905,7 +910,6 @@
Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
Entry->getType()));
- // FIXME: What if it was attribute used? Dangling pointer from LLVMUsed.
Entry->eraseFromParent();
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=68155&r1=68154&r2=68155&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Mar 31 17:37:52 2009
@@ -21,6 +21,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/ValueHandle.h"
#include <list>
namespace llvm {
@@ -119,7 +120,7 @@
/// present in the object file; bitcast to i8*. This is used for
/// forcing visibility of symbols which may otherwise be optimized
/// out.
- std::vector<llvm::Constant*> LLVMUsed;
+ std::vector<llvm::WeakVH> LLVMUsed;
/// GlobalCtors - Store the list of global constructors and their respective
/// priorities to be emitted when the translation unit is complete.
Modified: cfe/trunk/test/CodeGen/mangle.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mangle.c?rev=68155&r1=68154&r2=68155&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/mangle.c (original)
+++ cfe/trunk/test/CodeGen/mangle.c Tue Mar 31 17:37:52 2009
@@ -47,3 +47,8 @@
void foo6() __asm__("var2");
void foo6() {
}
+
+
+
+int foo7 __asm__("foo7") __attribute__((used));
+float foo8 __asm__("foo7") = 42;
More information about the cfe-commits
mailing list