diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-05-26 01:22:57 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-05-26 01:22:57 +0000 |
commit | 895771aa4b784e1ba3bce2b97ae38a86b8f90c8e (patch) | |
tree | 6864775829063864473ab0caf1f43ccd7efed1f2 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | b7e69b06b52d84c22cbe414bbb3593445303507e (diff) | |
download | bcm5719-llvm-895771aa4b784e1ba3bce2b97ae38a86b8f90c8e.tar.gz bcm5719-llvm-895771aa4b784e1ba3bce2b97ae38a86b8f90c8e.zip |
Handle the edge case of a weak function with incomplete type correctly.
Found by code inspection; I haven't seen this in real-world code.
llvm-svn: 72408
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index a9d67b35641..04693fd502e 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -373,8 +373,10 @@ void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, } void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD, - llvm::Function *F) { - SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F); + llvm::Function *F, + bool IsIncompleteFunction) { + if (!IsIncompleteFunction) + SetLLVMFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F); // Only a few attributes are set on declarations; these may later be // overridden by a definition. @@ -625,18 +627,19 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName, // 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 ShouldSetAttributes = true; + bool IsIncompleteFunction = false; if (!isa<llvm::FunctionType>(Ty)) { Ty = llvm::FunctionType::get(llvm::Type::VoidTy, std::vector<const llvm::Type*>(), false); - ShouldSetAttributes = false; + IsIncompleteFunction = true; } llvm::Function *F = llvm::Function::Create(cast<llvm::FunctionType>(Ty), llvm::Function::ExternalLinkage, "", &getModule()); F->setName(MangledName); - if (D.getDecl() && ShouldSetAttributes) - SetFunctionAttributes(cast<FunctionDecl>(D.getDecl()), F); + if (D.getDecl()) + SetFunctionAttributes(cast<FunctionDecl>(D.getDecl()), F, + IsIncompleteFunction); Entry = F; return F; } |