]> granicus.if.org Git - clang/commitdiff
[Modules] Fix crash in Preprocessor::getLastMacroWithSpelling().
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 4 Mar 2015 16:03:07 +0000 (16:03 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 4 Mar 2015 16:03:07 +0000 (16:03 +0000)
Macro names that got undefined inside a module may not have their MacroInfo set.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Preprocessor.cpp
test/Modules/Inputs/Module.framework/Headers/Module.h
test/Modules/crashes.m [new file with mode: 0644]

index b2a6d933a0f2973e1ba644c8628ee6f03328056d..51a038ac728fddec532d0890d0c68c1302af8542 100644 (file)
@@ -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;
index 9a1c2b9bd877eb38275a2e27d41822f4d0067d0c..55ce7a3e30fd45a2194859134033d4fd641fe368 100644 (file)
@@ -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/test/Modules/crashes.m b/test/Modules/crashes.m
new file mode 100644 (file)
index 0000000..cfdd1b2
--- /dev/null
@@ -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