From 5c585253e5f66affee0ce1d3db18ea2cfdfcdd82 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 4 Mar 2015 16:03:07 +0000 Subject: [PATCH] [Modules] Fix crash in Preprocessor::getLastMacroWithSpelling(). Macro names that got undefined inside a module may not have their MacroInfo set. llvm-svn: 231251 --- clang/lib/Lex/Preprocessor.cpp | 6 +++--- .../test/Modules/Inputs/Module.framework/Headers/Module.h | 3 +++ clang/test/Modules/crashes.m | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 clang/test/Modules/crashes.m diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index b2a6d93..51a038a 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -321,11 +321,11 @@ StringRef Preprocessor::getLastMacroWithSpelling( StringRef BestSpelling; for (Preprocessor::macro_iterator I = macro_begin(), E = macro_end(); I != E; ++I) { - if (!I->second->getMacroInfo()->isObjectLike()) - continue; const MacroDirective::DefInfo Def = I->second->findDirectiveAtLoc(Loc, SourceMgr); - if (!Def) + if (!Def || !Def.getMacroInfo()) + continue; + if (!Def.getMacroInfo()->isObjectLike()) continue; if (!MacroDefinitionEquals(Def.getMacroInfo(), Tokens)) continue; diff --git a/clang/test/Modules/Inputs/Module.framework/Headers/Module.h b/clang/test/Modules/Inputs/Module.framework/Headers/Module.h index 9a1c2b9..55ce7a3 100644 --- a/clang/test/Modules/Inputs/Module.framework/Headers/Module.h +++ b/clang/test/Modules/Inputs/Module.framework/Headers/Module.h @@ -31,4 +31,7 @@ typedef struct __sFILE { extern FILE *myFile; +#define SOME_MACRO_GETTING_UNDEFINED 1 +#undef SOME_MACRO_GETTING_UNDEFINED + #endif // MODULE_H diff --git a/clang/test/Modules/crashes.m b/clang/test/Modules/crashes.m new file mode 100644 index 0000000..cfdd1b2 --- /dev/null +++ b/clang/test/Modules/crashes.m @@ -0,0 +1,14 @@ +// RUN: rm -rf %t.mcp +// RUN: %clang_cc1 -fmodules-cache-path=%t.mcp -fmodules -F %S/Inputs -fobjc-arc %s -verify + +@import Module; + +__attribute__((objc_root_class)) +@interface Test +// rdar://19904648 +@property (assign) id newFile; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} \ + // expected-note {{explicitly declare getter}} +@end + +@implementation Test +@end -- 2.7.4