]> granicus.if.org Git - clang/commitdiff
When merging from a function with a prototype to a function without a
authorDouglas Gregor <dgregor@apple.com>
Mon, 16 Feb 2009 20:58:07 +0000 (20:58 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 16 Feb 2009 20:58:07 +0000 (20:58 +0000)
prototype, synthesize ParmVarDecls for prototype-less FunctionDecl.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64666 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CodeGen/functions.c

index 3f31a33c8030d0a35c8e7b85cbc888f39fe21991..b194c9e2ec2850b674959de482e3ac8a03ef3418 100644 (file)
@@ -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());
index 60e2b6c80cff498da169b9a14955aead2ba9ff70..83da64704bb622f8daf7ec35a5d4e72978dcd1e9 100644 (file)
@@ -15,3 +15,5 @@ void test3(T f) {
   f();
 }
 
+int a(int);
+int a() {return 1;}