r240691 - [modules] Fix findDirectiveAtLoc to not call a member function on a null pointer.

Richard Smith richard-llvm at metafoo.co.uk
Thu Jun 25 13:48:44 PDT 2015


Author: rsmith
Date: Thu Jun 25 15:48:44 2015
New Revision: 240691

URL: http://llvm.org/viewvc/llvm-project?rev=240691&view=rev
Log:
[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.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=240691&r1=240690&r2=240691&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Jun 25 15:48:44 2015
@@ -454,7 +454,9 @@ class Preprocessor : public RefCountedBa
     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) {





More information about the cfe-commits mailing list