[cfe-commits] r39219 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Basic/DiagnosticKinds.def

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:41:24 PDT 2007


Author: sabre
Date: Wed Jul 11 11:41:23 2007
New Revision: 39219

URL: http://llvm.org/viewvc/llvm-project?rev=39219&view=rev
Log:
verify C99 6.7.5.3p2

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39219&r1=39218&r2=39219&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:41:23 2007
@@ -908,12 +908,6 @@
   
   // Okay, this is the parameter list of a function definition, or it is an
   // identifier list of a K&R-style function.
-
-  
-  
-  // TODO: enter function-declaration scope, limiting any declarators for
-  // arguments to the function scope.
-  // NOTE: better to only create a scope if not '()'
   bool IsVariadic;
   bool HasPrototype;
   bool IsEmpty = false;
@@ -955,9 +949,14 @@
     IsVariadic = false;
     HasPrototype = false;
   } else {
+    // Finally, a normal, non-empty parameter type list.
+    
+    // Enter function-declaration scope, limiting any declarators for arguments
+    // to the function scope.
+    EnterScope(0);
+    
     IsVariadic = false;
     bool ReadArg = false;
-    // Finally, a normal, non-empty parameter type list.
     while (1) {
       if (Tok.getKind() == tok::ellipsis) {
         IsVariadic = true;
@@ -990,7 +989,24 @@
       if (Tok.getKind() == tok::kw___attribute)
         ParseAttributes();
       
-      // TODO: do something with the declarator, if it is valid.
+      // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'.
+      switch (DS.StorageClassSpec) {
+      case DeclSpec::SCS_unspecified:
+      case DeclSpec::SCS_register:
+        break;
+      case DeclSpec::SCS_auto:
+        // NOTE: we could trivially allow 'int foo(auto int X)' if we wanted.
+      default:
+        // FIXME: Get better loc info from declspecs!
+        Diag(DeclaratorInfo.getIdentifierLoc(),
+             diag::err_invalid_storage_class_in_func_decl);
+        DS.StorageClassSpec = DeclSpec::SCS_unspecified;
+        break;
+      }
+      
+      // Inform the actions module about the parameter declarator, so it gets
+      // added to the current scope.
+      Actions.ParseDeclarator(CurScope, DeclaratorInfo, 0, 0);
       
       // If the next token is a comma, consume it and keep reading arguments.
       if (Tok.getKind() != tok::comma) break;
@@ -1000,10 +1016,11 @@
     }
     
     HasPrototype = true;
+    
+    // Leave prototype scope.
+    ExitScope();
   }
   
-  // TODO: pop the scope.  
-
   // TODO: capture argument info.
   
   // Remember that we parsed a function type, and remember the attributes.

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39219&r1=39218&r2=39219&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:41:23 2007
@@ -390,6 +390,8 @@
      "ISO C requires a named argument before '...'")
 DIAG(err_unspecified_vla_size_with_static, ERROR,
      "'static' may not be used with an unspecified variable length array size")
+DIAG(err_invalid_storage_class_in_func_decl, ERROR,
+     "invalid storage class specifier in function declarator")
 
 DIAG(err_unexpected_typedef, ERROR,
      "unexpected type name '%s': expected expression")





More information about the cfe-commits mailing list