From: Eli Friedman Date: Mon, 9 Nov 2009 05:07:37 +0000 (+0000) Subject: Rearrange function to avoid recursive use-after-free. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=654ad40f27d684e8f3eddbc990247a6dbea5dded;p=clang Rearrange function to avoid recursive use-after-free. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86516 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 6b33f45f38..ff193fb489 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -645,6 +645,24 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName, return llvm::ConstantExpr::getBitCast(Entry, PTy); } + // This function doesn't have a complete type (for example, the return + // type is an incomplete struct). Use a fake type instead, and make + // sure not to try to set attributes. + bool IsIncompleteFunction = false; + if (!isa(Ty)) { + Ty = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), + std::vector(), false); + IsIncompleteFunction = true; + } + llvm::Function *F = llvm::Function::Create(cast(Ty), + llvm::Function::ExternalLinkage, + "", &getModule()); + F->setName(MangledName); + if (D.getDecl()) + SetFunctionAttributes(cast(D.getDecl()), F, + IsIncompleteFunction); + Entry = F; + // This is the first use or definition of a mangled name. If there is a // deferred decl with this name, remember that we need to emit it at the end // of the file. @@ -678,23 +696,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName, DeferredCopyAssignmentToEmit(D); } - // This function doesn't have a complete type (for example, the return - // type is an incomplete struct). Use a fake type instead, and make - // sure not to try to set attributes. - bool IsIncompleteFunction = false; - if (!isa(Ty)) { - Ty = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), - std::vector(), false); - IsIncompleteFunction = true; - } - llvm::Function *F = llvm::Function::Create(cast(Ty), - llvm::Function::ExternalLinkage, - "", &getModule()); - F->setName(MangledName); - if (D.getDecl()) - SetFunctionAttributes(cast(D.getDecl()), F, - IsIncompleteFunction); - Entry = F; return F; }