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
This commit is contained in:
Ben Langmuir 2014-09-30 20:00:18 +00:00
parent c110c0b99a
commit c28ce3aba6
5 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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.

View File

@ -0,0 +1,2 @@
#define MY_MACRO 1
#undef MY_MACRO

View File

@ -4,3 +4,5 @@ module ModuleNeedsVFS {
export *
}
framework module * { }
module ModuleUndef { header "module-undef.h" }

View File

@ -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;