From 6f10b74be0dd6f21453492214fef18eb2c2fd12d Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 14 Jul 2016 20:21:16 +0000 Subject: [PATCH] [arcmt/objcmt] Fix ParentMap crash with invalid code. rdar://22489560 llvm-svn: 275466 --- clang/lib/AST/ParentMap.cpp | 2 ++ clang/test/ARCMT/objcmt-invalid-code.mm | 19 +++++++++++++++++++ clang/test/ARCMT/objcmt-invalid-code.mm.result | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 clang/test/ARCMT/objcmt-invalid-code.mm create mode 100644 clang/test/ARCMT/objcmt-invalid-code.mm.result diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp index d7d5f9c..d8882c9 100644 --- a/clang/lib/AST/ParentMap.cpp +++ b/clang/lib/AST/ParentMap.cpp @@ -28,6 +28,8 @@ enum OpaqueValueMode { static void BuildParentMap(MapTy& M, Stmt* S, OpaqueValueMode OVMode = OV_Transparent) { + if (!S) + return; switch (S->getStmtClass()) { case Stmt::PseudoObjectExprClass: { diff --git a/clang/test/ARCMT/objcmt-invalid-code.mm b/clang/test/ARCMT/objcmt-invalid-code.mm new file mode 100644 index 0000000..f780d3d --- /dev/null +++ b/clang/test/ARCMT/objcmt-invalid-code.mm @@ -0,0 +1,19 @@ +// REQUIRES: x86-registered-target +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only %s -verify +// RUN: not %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result + +// Make sure there is no crash. + +@interface NSObject @end +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +void foo(int x = undeclared) { // expected-error {{undeclared}} + NSNumber *n = [NSNumber numberWithInt:1]; +} diff --git a/clang/test/ARCMT/objcmt-invalid-code.mm.result b/clang/test/ARCMT/objcmt-invalid-code.mm.result new file mode 100644 index 0000000..52b2db0 --- /dev/null +++ b/clang/test/ARCMT/objcmt-invalid-code.mm.result @@ -0,0 +1,19 @@ +// REQUIRES: x86-registered-target +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only %s -verify +// RUN: not %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result + +// Make sure there is no crash. + +@interface NSObject @end +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +void foo(int x = undeclared) { // expected-error {{undeclared}} + NSNumber *n = @1; +} -- 2.7.4