diff options
author | Chris Lattner <sabre@nondot.org> | 2007-12-02 07:09:19 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-12-02 07:09:19 +0000 |
commit | 9cd4fe4af6d3e8b6dcfce9c2cdefcaafca7eed7c (patch) | |
tree | 951b238ba836eba03ff31ab6a77b8de7e0f9de57 /CodeGen/CodeGenFunction.cpp | |
parent | 5a2fa14860813a8b93f68a84063dd20c690f045a (diff) |
Handle global variable definitions which change the type of a definition, such as:
extern int x[];
void foo() { x[0] = 1; }
int x[10];
void bar() { x[0] = 1; }
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | CodeGen/CodeGenFunction.cpp | 37 |
1 files changed, 1 insertions, 36 deletions
diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp index aa9d2c6054..3ee7d1f0fc 100644 --- a/CodeGen/CodeGenFunction.cpp +++ b/CodeGen/CodeGenFunction.cpp @@ -59,42 +59,7 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { SourceLocation())); CurFuncDecl = FD; - llvm::Constant *CurFnC = CGM.GetAddrOfGlobalDecl(FD); - if (!(CurFn = dyn_cast<llvm::Function>(CurFnC))) { - // If CurFnC is not a constant, it must be a bitcast of another function. - llvm::ConstantExpr *CurFnCE = cast<llvm::ConstantExpr>(CurFnC); - assert(CurFnCE->getOpcode() == llvm::Instruction::BitCast && - "Unexpected name collision"); - llvm::Function *OtherFunc = cast<llvm::Function>(CurFnCE->getOperand(0)); - - // This happens if there is a prototype for a function (e.g. "int f()") and - // then a definition of a different type (e.g. "int f(int x)"). Start by - // making a new function of the correct type, RAUW, then steal the name. - const llvm::PointerType *PTy = cast<llvm::PointerType>(CurFnC->getType()); - const llvm::FunctionType *FTy = - cast<llvm::FunctionType>(PTy->getElementType()); - CurFn = new llvm::Function(FTy, llvm::Function::ExternalLinkage, "", - &CGM.getModule()); - CurFn->takeName(OtherFunc); - - // Replace uses of OtherFunc with the Function we will endow with a body. - llvm::Constant *NewPtrForOldDecl = - llvm::ConstantExpr::getBitCast(CurFn, OtherFunc->getType()); - OtherFunc->replaceAllUsesWith(NewPtrForOldDecl); - - // Make sure the GlobalDecl map for FD is up-to-date. - CGM.ChangeGlobalDeclMap(FD, CurFn); - - // FIXME: Update the globaldeclmap for the previous decl of this name. We - // really want a way to walk all of these, but we don't have it yet. This - // is incredibly slow! - CGM.ReplaceMapValuesWith(OtherFunc, NewPtrForOldDecl); - - // Ok, delete the old function now, which is dead. - assert(OtherFunc->isDeclaration() && "Shouldn't replace non-declaration"); - OtherFunc->eraseFromParent(); - } - + CurFn = cast<llvm::Function>(CGM.GetAddrOfFunctionDecl(FD, true)); assert(CurFn->isDeclaration() && "Function already has body?"); // TODO: Set up linkage and many other things. Note, this is a simple |