summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-09-30 20:00:18 +0000
committerBen Langmuir <blangmuir@apple.com>2014-09-30 20:00:18 +0000
commitc28ce3aba646d0ea24ab584b9bac88e3a2a7374e (patch)
tree6905ba39906cfd0275cda91407d0e6f1a03211ff
parentc110c0b99a2b1ef9f5bbad280abc42664971dc80 (diff)
downloadbcm5719-llvm-c28ce3aba646d0ea24ab584b9bac88e3a2a7374e.tar.gz
bcm5719-llvm-c28ce3aba646d0ea24ab584b9bac88e3a2a7374e.zip
Avoid a crash after loading an #undef'd macro in code completion
In code-completion, don't assume there is a MacroInfo for everything, since we aren't serializing the def corresponding to a later #undef in the same module. Also setup the HadMacro bit correctly for undefs to avoid an assertion failure. rdar://18416901 llvm-svn: 218694
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp5
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp3
-rw-r--r--clang/test/Index/Inputs/module-undef.h2
-rw-r--r--clang/test/Index/Inputs/module.map2
-rw-r--r--clang/test/Index/complete-module-undef.m8
5 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 62d2da56ba9..e875860f820 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -49,7 +49,10 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){
MacroDirective *&StoredMD = Macros[II];
MD->setPrevious(StoredMD);
StoredMD = MD;
- II->setHasMacroDefinition(MD->isDefined());
+ // Setup the identifier as having associated macro history.
+ II->setHasMacroDefinition(true);
+ if (!MD->isDefined())
+ II->setHasMacroDefinition(false);
bool isImportedMacro = isa<DefMacroDirective>(MD) &&
cast<DefMacroDirective>(MD)->isImported();
if (II->isFromAST() && !isImportedMacro)
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 3d250e3bef1..10b243cd509 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2575,11 +2575,12 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
const MacroDirective *MD = PP.getMacroDirectiveHistory(Macro);
assert(MD && "Not a macro?");
const MacroInfo *MI = MD->getMacroInfo();
+ assert((!MD->isDefined() || MI) && "missing MacroInfo for define");
Result.AddTypedTextChunk(
Result.getAllocator().CopyString(Macro->getName()));
- if (!MI->isFunctionLike())
+ if (!MI || !MI->isFunctionLike())
return Result.TakeString();
// Format a function-like macro with placeholders for the arguments.
diff --git a/clang/test/Index/Inputs/module-undef.h b/clang/test/Index/Inputs/module-undef.h
new file mode 100644
index 00000000000..8212d755a0f
--- /dev/null
+++ b/clang/test/Index/Inputs/module-undef.h
@@ -0,0 +1,2 @@
+#define MY_MACRO 1
+#undef MY_MACRO
diff --git a/clang/test/Index/Inputs/module.map b/clang/test/Index/Inputs/module.map
index 8f24840c81f..4bfc109a8b1 100644
--- a/clang/test/Index/Inputs/module.map
+++ b/clang/test/Index/Inputs/module.map
@@ -4,3 +4,5 @@ module ModuleNeedsVFS {
export *
}
framework module * { }
+
+module ModuleUndef { header "module-undef.h" }
diff --git a/clang/test/Index/complete-module-undef.m b/clang/test/Index/complete-module-undef.m
new file mode 100644
index 00000000000..a9dd0009641
--- /dev/null
+++ b/clang/test/Index/complete-module-undef.m
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: env CINDEXTEST_COMPLETION_CACHING=1 \
+// RUN: c-index-test -test-load-source-reparse 2 local %s -fmodules -fmodules-cache-path=%t -I %S/Inputs \
+// RUN: | FileCheck %s
+
+// rdar://18416901 (used to crash)
+// CHECK: complete-module-undef.m:8:1: ModuleImport=ModuleUndef:8:1 (Definition) Extent=[8:1 - 8:20]
+@import ModuleUndef;
OpenPOWER on IntegriCloud