aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-16 18:20:44 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-16 18:20:44 +0000
commit6871981fbccba9e8a63997d58245ec0add114f49 (patch)
tree7626e9c24e0b70c4e4285c1678b1b2d21dfb99ec /lib/Sema/SemaDecl.cpp
parent83d67909f9058816d1ab49910708c0ba3c4c8096 (diff)
When a function with a prototype is redeclared without a prototype,
merge the prototype into the redeclaration (and make a note in the declaration). Fixes PR3588. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 3960a7d57c..444f85e773 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -593,7 +593,24 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
// duplicate function decls like "void f(int); void f(enum X);" properly.
if (!getLangOptions().CPlusPlus &&
Context.typesAreCompatible(OldQType, NewQType)) {
+ const FunctionType *NewFuncType = NewQType->getAsFunctionType();
+ const FunctionTypeProto *OldProto = 0;
+ if (isa<FunctionTypeNoProto>(NewFuncType) &&
+ (OldProto = OldQType->getAsFunctionTypeProto())) {
+ // The old declaration provided a function prototype, but the
+ // new declaration does not. Merge in the prototype.
+ llvm::SmallVector<QualType, 16> ParamTypes(OldProto->arg_type_begin(),
+ OldProto->arg_type_end());
+ NewQType = Context.getFunctionType(NewFuncType->getResultType(),
+ &ParamTypes[0], ParamTypes.size(),
+ OldProto->isVariadic(),
+ OldProto->getTypeQuals());
+ New->setType(NewQType);
+ New->setInheritedPrototype();
+ }
+
MergeAttributes(New, Old);
+
return false;
}