]> granicus.if.org Git - clang/commitdiff
[modules] Fix findDirectiveAtLoc to not call a member function on a null pointer.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Jun 2015 20:48:44 +0000 (20:48 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Jun 2015 20:48:44 +0000 (20:48 +0000)
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

include/clang/Lex/Preprocessor.h

index 439a28041e2d79df753d0e5f7fd71d12a68a0340..f02364a385ea7f4b847a89d9a4dd3bafd6b2f626 100644 (file)
@@ -454,7 +454,9 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
     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) {