[cfe-commits] r64666 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGen/functions.c

Douglas Gregor dgregor at apple.com
Mon Feb 16 12:58:09 PST 2009


Author: dgregor
Date: Mon Feb 16 14:58:07 2009
New Revision: 64666

URL: http://llvm.org/viewvc/llvm-project?rev=64666&view=rev
Log:
When merging from a function with a prototype to a function without a
prototype, synthesize ParmVarDecls for prototype-less FunctionDecl.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGen/functions.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=64666&r1=64665&r2=64666&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 16 14:58:07 2009
@@ -607,6 +607,23 @@
                                          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 @@
     
     // 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 @@
       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());

Modified: cfe/trunk/test/CodeGen/functions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/functions.c?rev=64666&r1=64665&r2=64666&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/functions.c (original)
+++ cfe/trunk/test/CodeGen/functions.c Mon Feb 16 14:58:07 2009
@@ -15,3 +15,5 @@
   f();
 }
 
+int a(int);
+int a() {return 1;}





More information about the cfe-commits mailing list