[llvm-branch-commits] [cfe-branch] r118535 - in /cfe/branches/Apple/whitney: include/clang/Sema/Sema.h lib/Sema/SemaChecking.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp test/SemaObjCXX/blocks.mm

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:30:18 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:30:18 2010
New Revision: 118535

URL: http://llvm.org/viewvc/llvm-project?rev=118535&view=rev
Log:
Merge r117942:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Mon Nov 1 18:37:59 2010 +0000

    Require that the types of the parameters of a block literal are complete.

Modified:
    cfe/branches/Apple/whitney/include/clang/Sema/Sema.h
    cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
    cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp
    cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp
    cfe/branches/Apple/whitney/test/SemaObjCXX/blocks.mm

Modified: cfe/branches/Apple/whitney/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Sema/Sema.h?rev=118535&r1=118534&r2=118535&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Sema/Sema.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Sema/Sema.h Tue Nov  9 11:30:18 2010
@@ -1170,7 +1170,8 @@
                            CallExpr *CE, FunctionDecl *FD);
 
   /// Helpers for dealing with blocks and functions.
-  bool CheckParmsForFunctionDef(FunctionDecl *FD);
+  bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
+                                bool CheckParameterNames);
   void CheckCXXDefaultArguments(FunctionDecl *FD);
   void CheckExtraCXXDefaultArguments(Declarator &D);
   Scope *getNonFieldDeclScope(Scope *S);

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp?rev=118535&r1=118534&r2=118535&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp Tue Nov  9 11:30:18 2010
@@ -2831,11 +2831,12 @@
 /// takes care of any checks that cannot be performed on the
 /// declaration itself, e.g., that the types of each of the function
 /// parameters are complete.
-bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
+bool Sema::CheckParmsForFunctionDef(ParmVarDecl **P, ParmVarDecl **PEnd,
+                                    bool CheckParameterNames) {
   bool HasInvalidParm = false;
-  for (unsigned p = 0, NumParams = FD->getNumParams(); p < NumParams; ++p) {
-    ParmVarDecl *Param = FD->getParamDecl(p);
-
+  for (; P != PEnd; ++P) {
+    ParmVarDecl *Param = *P;
+    
     // C99 6.7.5.3p4: the parameters in a parameter type list in a
     // function declarator that is part of a function definition of
     // that function shall not have incomplete type.
@@ -2850,7 +2851,8 @@
 
     // 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 &&
+    if (CheckParameterNames &&
+        Param->getIdentifier() == 0 &&
         !Param->isImplicit() &&
         !getLangOptions().CPlusPlus)
       Diag(Param->getLocation(), diag::err_parameter_name_omitted);

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp?rev=118535&r1=118534&r2=118535&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp Tue Nov  9 11:30:18 2010
@@ -3624,7 +3624,6 @@
       if (getLangOptions().CPlusPlus &&
           Param->getType().getUnqualifiedType() != Context.VoidTy)
         Diag(Param->getLocation(), diag::err_param_typedef_of_void);
-      // FIXME: Leaks decl?
     } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) {
       for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
         ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param);
@@ -4927,10 +4926,6 @@
          "Not a function declarator!");
   DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun;
 
-  if (FTI.hasPrototype) {
-    // FIXME: Diagnose arguments without names in C.
-  }
-
   Scope *ParentScope = FnBodyScope->getParent();
 
   Decl *DP = HandleDeclarator(ParentScope, D,
@@ -5043,7 +5038,8 @@
     PushDeclContext(FnBodyScope, FD);
 
   // Check the validity of our function parameters
-  CheckParmsForFunctionDef(FD);
+  CheckParmsForFunctionDef(FD->param_begin(), FD->param_end(),
+                           /*CheckParameterNames=*/true);
 
   bool ShouldCheckShadow =
     Diags.getDiagnosticLevel(diag::warn_decl_shadow) != Diagnostic::Ignored;
@@ -7356,7 +7352,6 @@
   }
 
   // Figure out the type that should be used for this enum.
-  // FIXME: Support -fshort-enums.
   QualType BestType;
   unsigned BestWidth;
 

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp?rev=118535&r1=118534&r2=118535&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp Tue Nov  9 11:30:18 2010
@@ -7424,9 +7424,13 @@
   }
 
   // Set the parameters on the block decl.
-  if (!Params.empty())
+  if (!Params.empty()) {
     CurBlock->TheDecl->setParams(Params.data(), Params.size());
-
+    CheckParmsForFunctionDef(CurBlock->TheDecl->param_begin(),
+                             CurBlock->TheDecl->param_end(),
+                             /*CheckParameterNames=*/false);
+  }
+  
   // Finally we can process decl attributes.
   ProcessDeclAttributes(CurScope, CurBlock->TheDecl, ParamInfo);
 
@@ -7464,7 +7468,6 @@
   // Pop off CurBlock, handle nested blocks.
   PopDeclContext();
   PopFunctionOrBlockScope();
-  // FIXME: Delete the ParmVarDecl objects as well???
 }
 
 /// ActOnBlockStmtExpr - This is called when the body of a block statement
@@ -7526,7 +7529,6 @@
                              FunctionType::ExtInfo(NoReturn, 0, CC_Default));
   }
 
-  // FIXME: Check that return/parameter types are complete/non-abstract
   DiagnoseUnusedParameters(BSI->TheDecl->param_begin(),
                            BSI->TheDecl->param_end());
   BlockTy = Context.getBlockPointerType(BlockTy);

Modified: cfe/branches/Apple/whitney/test/SemaObjCXX/blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/SemaObjCXX/blocks.mm?rev=118535&r1=118534&r2=118535&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/SemaObjCXX/blocks.mm (original)
+++ cfe/branches/Apple/whitney/test/SemaObjCXX/blocks.mm Tue Nov  9 11:30:18 2010
@@ -50,3 +50,27 @@
 	void (^vb)(id obj, int idx, BOOL *stop) = (void (^)(id, int, BOOL *))block;
     BOOL (^bb)(id obj, int idx, BOOL *stop) = (BOOL (^)(id, int, BOOL *))block;
 }
+
+// <rdar://problem/8600419>: Require that the types of block
+// parameters are complete.
+namespace N1 {
+  template<class _T> class ptr; // expected-note{{template is declared here}}
+
+  template<class _T>
+    class foo {
+  public:
+    void bar(void (^)(ptr<_T>));
+  };
+
+  class X;
+
+  void test2();
+
+  void test()
+  {
+    foo<X> f;
+    f.bar(^(ptr<X> _f) { // expected-error{{implicit instantiation of undefined template 'N1::ptr<N1::X>'}}
+        test2();
+      });
+  }
+}





More information about the llvm-branch-commits mailing list