[cfe-commits] r39304 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:42:47 PDT 2007


Author: sabre
Date: Wed Jul 11 11:42:46 2007
New Revision: 39304

URL: http://llvm.org/viewvc/llvm-project?rev=39304&view=rev
Log:
Don't crash if GetTypeForDeclarator can't grok a type.

Modified:
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/Sema/SemaDecl.cpp

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39304&r1=39303&r2=39304&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:46 2007
@@ -111,14 +111,18 @@
   }
   
   Decl *New;
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
     New = ParseTypedefDecl(S, D);
-  else if (D.isFunctionDeclarator())
-    New = new FunctionDecl(D.getIdentifierLoc(), II, GetTypeForDeclarator(D,S));
-  else
-    New = new VarDecl(D.getIdentifierLoc(), II, GetTypeForDeclarator(D, S));
-  
-  if (!New) return 0;
+    if (!New) return 0;
+  } else if (D.isFunctionDeclarator()) {
+    TypeRef R = GetTypeForDeclarator(D, S);
+    if (R.isNull()) return 0;
+    New = new FunctionDecl(D.getIdentifierLoc(), II, R);
+  } else {
+    TypeRef R = GetTypeForDeclarator(D, S);
+    if (R.isNull()) return 0;
+    New = new VarDecl(D.getIdentifierLoc(), II, R);
+  }
   
   
   // If this has an identifier, add it to the scope stack.
@@ -368,7 +372,7 @@
   
   if (BitWidth) {
     // TODO: Validate.
-    assert(0 && "bitfields unimp");
+    printf("WARNING: BITFIELDS IGNORED!\n");
     
     // 6.7.2.1p3
     // 6.7.2.1p4
@@ -380,7 +384,10 @@
     
   }
   
-  return new FieldDecl(Loc, II, GetTypeForDeclarator(D, S));
+  TypeRef T = GetTypeForDeclarator(D, S);
+  if (T.isNull()) return 0;
+
+  return new FieldDecl(Loc, II, T);
 }
 
 void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:46 2007
@@ -111,14 +111,18 @@
   }
   
   Decl *New;
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
     New = ParseTypedefDecl(S, D);
-  else if (D.isFunctionDeclarator())
-    New = new FunctionDecl(D.getIdentifierLoc(), II, GetTypeForDeclarator(D,S));
-  else
-    New = new VarDecl(D.getIdentifierLoc(), II, GetTypeForDeclarator(D, S));
-  
-  if (!New) return 0;
+    if (!New) return 0;
+  } else if (D.isFunctionDeclarator()) {
+    TypeRef R = GetTypeForDeclarator(D, S);
+    if (R.isNull()) return 0;
+    New = new FunctionDecl(D.getIdentifierLoc(), II, R);
+  } else {
+    TypeRef R = GetTypeForDeclarator(D, S);
+    if (R.isNull()) return 0;
+    New = new VarDecl(D.getIdentifierLoc(), II, R);
+  }
   
   
   // If this has an identifier, add it to the scope stack.
@@ -368,7 +372,7 @@
   
   if (BitWidth) {
     // TODO: Validate.
-    assert(0 && "bitfields unimp");
+    printf("WARNING: BITFIELDS IGNORED!\n");
     
     // 6.7.2.1p3
     // 6.7.2.1p4
@@ -380,7 +384,10 @@
     
   }
   
-  return new FieldDecl(Loc, II, GetTypeForDeclarator(D, S));
+  TypeRef T = GetTypeForDeclarator(D, S);
+  if (T.isNull()) return 0;
+
+  return new FieldDecl(Loc, II, T);
 }
 
 void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,





More information about the cfe-commits mailing list