From: Richard Smith Date: Thu, 25 Jun 2015 20:48:44 +0000 (+0000) Subject: [modules] Fix findDirectiveAtLoc to not call a member function on a null pointer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c90c3532b1666e20c1666a96c921ac93c6ac7257;p=clang [modules] Fix findDirectiveAtLoc to not call a member function on a null pointer. This is exercised by existing tests, and fixes a failure with -fsanitize=null. No observable change otherwise; the code happened to do the right thing in practice under recent versions of Clang and GCC because MacroDirective::getDefinition happens to check whether this == null. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240691 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 439a28041e..f02364a385 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -454,7 +454,9 @@ class Preprocessor : public RefCountedBase { MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc, SourceManager &SourceMgr) const { // FIXME: Incorporate module macros into the result of this. - return getLatest()->findDirectiveAtLoc(Loc, SourceMgr); + if (auto *Latest = getLatest()) + return Latest->findDirectiveAtLoc(Loc, SourceMgr); + return MacroDirective::DefInfo(); } void overrideActiveModuleMacros(Preprocessor &PP, IdentifierInfo *II) {