[cfe-commits] r127711 - in /cfe/trunk: test/Index/cindex-on-invalid.m tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Tue Mar 15 16:47:49 PDT 2011


Author: kremenek
Date: Tue Mar 15 18:47:49 2011
New Revision: 127711

URL: http://llvm.org/viewvc/llvm-project?rev=127711&view=rev
Log:
c-index-test shouldn't crash when a goto has no matching label.  Fixes <rdar://problem/9123493>.

Modified:
    cfe/trunk/test/Index/cindex-on-invalid.m
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/test/Index/cindex-on-invalid.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cindex-on-invalid.m?rev=127711&r1=127710&r2=127711&view=diff
==============================================================================
--- cfe/trunk/test/Index/cindex-on-invalid.m (original)
+++ cfe/trunk/test/Index/cindex-on-invalid.m Tue Mar 15 18:47:49 2011
@@ -1,6 +1,13 @@
 // RUN: c-index-test -test-load-source local %s 2>&1 | FileCheck %s
 
+// <rdar://problem/9123493>
+void test() {                              
+  goto exit;
+}
+
 int foo;
 int
 
-// CHECK: cindex-on-invalid.m:6:70: error: expected identifier or '('
\ No newline at end of file
+// CHECK: cindex-on-invalid.m:5:8: error: use of undeclared label 'exit'
+// CHECK: cindex-on-invalid.m:13:1: error: expected identifier or '('
+

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127711&r1=127710&r2=127711&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Mar 15 18:47:49 2011
@@ -3709,7 +3709,9 @@
   if (clang_isStatement(C.kind)) {
     Stmt *S = getCursorStmt(C);
     if (GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
-      return MakeCXCursor(Goto->getLabel()->getStmt(), getCursorDecl(C), tu);
+      if (LabelDecl *label = Goto->getLabel())
+        if (LabelStmt *labelS = label->getStmt())
+        return MakeCXCursor(labelS, getCursorDecl(C), tu);
 
     return clang_getNullCursor();
   }





More information about the cfe-commits mailing list