From: Ted Kremenek Date: Tue, 15 Mar 2011 23:47:49 +0000 (+0000) Subject: c-index-test shouldn't crash when a goto has no matching label. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127711 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/cindex-on-invalid.m b/test/Index/cindex-on-invalid.m index d2d952d8b1..d223c2ad59 100644 --- a/test/Index/cindex-on-invalid.m +++ b/test/Index/cindex-on-invalid.m @@ -1,6 +1,13 @@ // RUN: c-index-test -test-load-source local %s 2>&1 | FileCheck %s +// +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 '(' + diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 290146fa4d..538efd7ae3 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3709,7 +3709,9 @@ CXCursor clang_getCursorReferenced(CXCursor C) { if (clang_isStatement(C.kind)) { Stmt *S = getCursorStmt(C); if (GotoStmt *Goto = dyn_cast_or_null(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(); }