[cfe-commits] r70023 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/Sema/function.c test/Sema/nested-redef.c test/SemaObjC/ivar-sem-check-1.m

Chris Lattner sabre at nondot.org
Sat Apr 25 01:47:56 PDT 2009


Author: lattner
Date: Sat Apr 25 03:47:54 2009
New Revision: 70023

URL: http://llvm.org/viewvc/llvm-project?rev=70023&view=rev
Log:
Change SemaType's "GetTypeForDeclarator" and "ConvertDeclSpecToType" to 
always return a non-null QualType + error bit.  This fixes a bunch of 
cases that didn't check for null result (and could thus crash) and eliminates
some crappy code scattered throughout sema.

This also improves the diagnostics in the recursive struct case to eliminate
a bogus second error.  It also cleans up the case added to function.c by forming
a proper function type even though the declarator is erroneous, allowing the
parameter to be added to the function.  Before:

t.c:2:1: error: unknown type name 'unknown_type'
unknown_type f(void*P)
^
t.c:4:3: error: use of undeclared identifier 'P'
  P+1;
  ^

After:
t.c:2:1: error: unknown type name 'unknown_type'
unknown_type f(void*P)
^


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/function.c
    cfe/trunk/test/Sema/nested-redef.c
    cfe/trunk/test/SemaObjC/ivar-sem-check-1.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 25 03:47:54 2009
@@ -1361,13 +1361,6 @@
   NamedDecl *New;
 
   QualType R = GetTypeForDeclarator(D, S);
-  if (R.isNull()) {
-    D.setInvalidType();
-    R = Context.IntTy;
-    if (IsFunctionDefinition) // int(...)
-      R = Context.getFunctionType(R, 0, 0, true, 0);
-      
-  }
 
   // See if this is a redefinition of a variable in the same scope.
   if (D.getCXXScopeSpec().isInvalid()) {
@@ -2798,10 +2791,6 @@
     CheckExtraCXXDefaultArguments(D);
  
   QualType parmDeclType = GetTypeForDeclarator(D, S);
-  if (parmDeclType.isNull()) {
-    D.setInvalidType(true);
-    parmDeclType = Context.IntTy;
-  }
   
   // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
   // Can this happen for params?  We already checked that they don't conflict
@@ -3816,10 +3805,6 @@
   // example, unnamed unions inject all members into the struct namespace!
   
   QualType T = GetTypeForDeclarator(D, S);
- if (T.isNull()) {
-   D.setInvalidType();
-   T = Context.IntTy;
- }
   
   if (BitWidth) {
     // 6.7.2.1p3, 6.7.2.1p4

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr 25 03:47:54 2009
@@ -4703,10 +4703,6 @@
       || ParamInfo.getTypeObject(0).Kind != DeclaratorChunk::Function) {
     QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
 
-    // The type is entirely optional as well, if none, use DependentTy.
-    if (T.isNull())
-      T = Context.DependentTy;
-
     // The parameter list is optional, if there was none, assume ().
     if (!T->isFunctionType())
       T = Context.getFunctionType(T, NULL, 0, 0, 0);
@@ -4722,9 +4718,6 @@
            diag::err_object_cannot_be_passed_returned_by_value) << 0 << RetTy;
       return;
     }
-
-    if (!RetTy->isDependentType())
-      CurBlock->ReturnType = RetTy.getTypePtr();
     return;
   }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Apr 25 03:47:54 2009
@@ -47,8 +47,8 @@
 /// object.
 /// \param DS  the declaration specifiers
 /// \param DeclLoc The location of the declarator identifier or invalid if none.
-/// \returns The type described by the declaration specifiers, or NULL
-/// if there was an error.
+/// \returns The type described by the declaration specifiers.  This function
+/// never returns null.
 QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
                                      SourceLocation DeclLoc,
                                      bool &isInvalid) {
@@ -176,6 +176,9 @@
            "Can't handle qualifiers on typedef names yet!");
     // TypeQuals handled by caller.
     Result = Context.getTypeDeclType(cast<TypeDecl>(D));
+    
+    if (D->isInvalidDecl())
+      isInvalid = true;
     break;
   }    
   case DeclSpec::TST_typename: {
@@ -232,7 +235,9 @@
     break;
   }
   case DeclSpec::TST_error:
-    return QualType();
+    Result = Context.IntTy;
+    isInvalid = true;
+    break;
   }
   
   // Handle complex types.
@@ -624,8 +629,6 @@
     } else {
       bool isInvalid = false;
       T = ConvertDeclSpecToType(DS, D.getIdentifierLoc(), isInvalid);
-      if (T.isNull())
-        return T;
       if (isInvalid)
         D.setInvalidType(true);
     }
@@ -938,7 +941,7 @@
   assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
   
   QualType T = GetTypeForDeclarator(D, S);
-  if (T.isNull())
+  if (D.isInvalidType())
     return true;
 
   // Check that there are no default arguments (C++ only).

Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=70023&r1=70022&r2=70023&view=diff

==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Sat Apr 25 03:47:54 2009
@@ -80,6 +80,10 @@
 fn_t t17;
 
 // PR4049
-unknown_type t18(void*) {   // expected-error {{unknown type name 'unknown_type'}}
+unknown_type t18(void*) {   // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
+}
+
+unknown_type t19(int* P) {   // expected-error {{unknown type name 'unknown_type'}}
+  P = P+1;  // no warning.
 }
 

Modified: cfe/trunk/test/Sema/nested-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nested-redef.c?rev=70023&r1=70022&r2=70023&view=diff

==============================================================================
--- cfe/trunk/test/Sema/nested-redef.c (original)
+++ cfe/trunk/test/Sema/nested-redef.c Sat Apr 25 03:47:54 2009
@@ -1,7 +1,6 @@
 // RUN: clang-cc -fsyntax-only -verify %s
 struct X { // expected-note{{previous definition is here}}
-  struct X { } x; // expected-error{{nested redefinition of 'X'}} \
-                     expected-error {{field has incomplete type}}
+  struct X { } x; // expected-error{{nested redefinition of 'X'}}
 }; 
 
 struct Y { };

Modified: cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-sem-check-1.m?rev=70023&r1=70022&r2=70023&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-sem-check-1.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-sem-check-1.m Sat Apr 25 03:47:54 2009
@@ -9,8 +9,7 @@
 	int arr[];  // expected-error {{field has incomplete type}}
 	struct S IC;  // expected-error {{field has incomplete type}}
 	struct T { // expected-note {{previous definition is here}}
-	  struct T {} X;  // expected-error {{nested redefinition of 'T'}} \
-                             expected-error {{field has incomplete type}}
+	  struct T {} X;  // expected-error {{nested redefinition of 'T'}}
 	}YYY; 
 	FOO    BADFUNC;  // expected-error {{field 'BADFUNC' declared as a function}}
 	int kaka;	// expected-note {{previous declaration is here}}





More information about the cfe-commits mailing list