]> granicus.if.org Git - clang/commitdiff
[libclang] Fix crash on invalid code. Fixes rdar://10451854
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Nov 2011 02:35:10 +0000 (02:35 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Nov 2011 02:35:10 +0000 (02:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144766 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp
lib/Parse/ParseObjc.cpp
test/Index/invalid-code-rdar10451854.m [new file with mode: 0644]

index 0b9c37a2237280be9d9e19c5f72f854d36ab82d2..64b931f5a85846ea9e66a8f9debb87ac1a61d752 100644 (file)
@@ -853,6 +853,9 @@ public:
   }
 
   void handleTopLevelDecl(Decl *D) {
+    if (!D)
+      return;
+
     // FIXME: Currently ObjC method declarations are incorrectly being
     // reported as top-level declarations, even though their DeclContext
     // is the containing ObjC @interface/@implementation.  This is a
index 88044d1bc9d8c459adb576c911b2941fafc7726c..3cb2aaaec3822ad73a9290aa242f3ea65e2b861e 100644 (file)
@@ -1487,7 +1487,8 @@ Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) {
   Actions.DefaultSynthesizeProperties(getCurScope(), ObjCImpDecl);
   for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) {
     Decl *D = ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i]);
-    DeclsInGroup.push_back(D);
+    if (D)
+      DeclsInGroup.push_back(D);
   }
   DeclsInGroup.push_back(ObjCImpDecl);
   
diff --git a/test/Index/invalid-code-rdar10451854.m b/test/Index/invalid-code-rdar10451854.m
new file mode 100644 (file)
index 0000000..1562671
--- /dev/null
@@ -0,0 +1,15 @@
+struct {
+
+@implementation Foo
+
+- (void)finalize {
+  NSLog(@"bar");
+}
+
+- (NSArray *)graphics {
+}
+
+@end
+
+// Test that we don't crash
+// RUN: c-index-test -test-load-source-reparse 3 local %s