summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-16 20:58:07 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-16 20:58:07 +0000
commitbfdd607372e900c3a05bcb3ce7a172179def8048 (patch)
tree633ab8dff88d7d1c0e3077d5ae53e2c0bedf60d1
parent227811afcaeae725cff407a964495d5d4089f160 (diff)
downloadbcm5719-llvm-bfdd607372e900c3a05bcb3ce7a172179def8048.tar.gz
bcm5719-llvm-bfdd607372e900c3a05bcb3ce7a172179def8048.zip
When merging from a function with a prototype to a function without a
prototype, synthesize ParmVarDecls for prototype-less FunctionDecl. llvm-svn: 64666
-rw-r--r--clang/lib/Sema/SemaDecl.cpp31
-rw-r--r--clang/test/CodeGen/functions.c2
2 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3f31a33c803..b194c9e2ec2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -607,6 +607,23 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
OldProto->getTypeQuals());
New->setType(NewQType);
New->setInheritedPrototype();
+
+ // Synthesize a parameter for each argument type.
+ llvm::SmallVector<ParmVarDecl*, 16> Params;
+ for (FunctionTypeProto::arg_type_iterator
+ ParamType = OldProto->arg_type_begin(),
+ ParamEnd = OldProto->arg_type_end();
+ ParamType != ParamEnd; ++ParamType) {
+ ParmVarDecl *Param = ParmVarDecl::Create(Context, New,
+ SourceLocation(), 0,
+ *ParamType, VarDecl::None,
+ 0);
+ Param->setImplicit();
+ Params.push_back(Param);
+ }
+
+ New->setParams(Context, &Params[0], Params.size());
+
}
MergeAttributes(New, Old);
@@ -762,7 +779,9 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
// C99 6.9.1p5: If the declarator includes a parameter type list, the
// declaration of each parameter shall include an identifier.
- if (Param->getIdentifier() == 0 && !getLangOptions().CPlusPlus)
+ if (Param->getIdentifier() == 0 &&
+ !Param->isImplicit() &&
+ !getLangOptions().CPlusPlus)
Diag(Param->getLocation(), diag::err_parameter_name_omitted);
}
@@ -1693,10 +1712,12 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
llvm::SmallVector<ParmVarDecl*, 16> Params;
for (FunctionTypeProto::arg_type_iterator ArgType = FT->arg_type_begin();
ArgType != FT->arg_type_end(); ++ArgType) {
- Params.push_back(ParmVarDecl::Create(Context, DC,
- SourceLocation(), 0,
- *ArgType, VarDecl::None,
- 0));
+ ParmVarDecl *Param = ParmVarDecl::Create(Context, DC,
+ SourceLocation(), 0,
+ *ArgType, VarDecl::None,
+ 0);
+ Param->setImplicit();
+ Params.push_back(Param);
}
NewFD->setParams(Context, &Params[0], Params.size());
diff --git a/clang/test/CodeGen/functions.c b/clang/test/CodeGen/functions.c
index 60e2b6c80cf..83da64704bb 100644
--- a/clang/test/CodeGen/functions.c
+++ b/clang/test/CodeGen/functions.c
@@ -15,3 +15,5 @@ void test3(T f) {
f();
}
+int a(int);
+int a() {return 1;}
OpenPOWER on IntegriCloud