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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72408 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Friedman 2009-05-26 01:22:57 +00:00
Родитель e9263729b7
Коммит c6c14d1cd6
3 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -373,7 +373,9 @@ void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
}
void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
llvm::Function *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
@ -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;
}

Просмотреть файл

@ -402,7 +402,8 @@ private:
/// SetFunctionAttributes - Set function attributes for a function
/// declaration.
void SetFunctionAttributes(const FunctionDecl *FD,
llvm::Function *F);
llvm::Function *F,
bool IsIncompleteFunction);
/// EmitGlobal - Emit code for a singal global function or var decl. Forward
/// declarations are emitted lazily.

Просмотреть файл

@ -0,0 +1,5 @@
// RUN: clang-cc -emit-llvm < %s | grep 'extern_weak' | count 1
struct S;
void __attribute__((weak)) foo1(struct S);
void (*foo2)(struct S) = foo1;