From a212c56e9b7533bcc2d6be90efd52ad241bf894e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 4 May 2008 02:29:49 +0000 Subject: Simplify FunctionDecl::AddRedeclaration a bit by using std::swap. Fix 'swapping' of attributes to not insert null values into the DeclAttrs map. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50612 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 306abd120b..d8b1fc327a 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -303,28 +303,30 @@ void CodeGenModule::EmitObjCMethod(const ObjCMethodDecl *OMD) { void CodeGenModule::EmitFunction(const FunctionDecl *FD) { // If this is not a prototype, emit the body. - if (FD->getBody()) { - // If the function is a static, defer code generation until later so we can - // easily omit unused statics. - if (FD->getStorageClass() == FunctionDecl::Static) { - // We need to check the Module here to see if GetAddrOfFunctionDecl() has - // already added this function to the Module because the address of the - // function's prototype was taken. If this is the case, call - // GetAddrOfFunctionDecl to insert the static FunctionDecl into the used - // GlobalDeclsMap, so that EmitStatics will generate code for it later. - // - // Example: - // static int foo(); - // int bar() { return foo(); } - // static int foo() { return 5; } - if (getModule().getFunction(FD->getName())) - GetAddrOfFunctionDecl(FD, true); - - StaticDecls.push_back(FD); - return; - } + if (!FD->isThisDeclarationADefinition()) + return; + + // If the function is a static, defer code generation until later so we can + // easily omit unused statics. + if (FD->getStorageClass() != FunctionDecl::Static) { CodeGenFunction(*this).GenerateCode(FD); + return; } + + // We need to check the Module here to see if GetAddrOfFunctionDecl() has + // already added this function to the Module because the address of the + // function's prototype was taken. If this is the case, call + // GetAddrOfFunctionDecl to insert the static FunctionDecl into the used + // GlobalDeclsMap, so that EmitStatics will generate code for it later. + // + // Example: + // static int foo(); + // int bar() { return foo(); } + // static int foo() { return 5; } + if (getModule().getFunction(FD->getName())) + GetAddrOfFunctionDecl(FD, true); + + StaticDecls.push_back(FD); } void CodeGenModule::EmitStatics() { -- cgit v1.2.3-18-g5258