diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h
index 19e8521..ce116e1 100644
--- a/include/clang/Lex/PPCallbacks.h
+++ b/include/clang/Lex/PPCallbacks.h
@@ -175,8 +175,7 @@ public:
   }
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
-  /// MI is released immediately following this callback.
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  virtual void MacroUndefined(const Token &MacroNameTok) {
   }
   
   /// Defined - This hook is called whenever the 'defined' operator is seen.
@@ -319,9 +318,9 @@ public:
     Second->MacroDefined(MacroNameTok, MI);
   }
 
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
-    First->MacroUndefined(MacroNameTok, MI);
-    Second->MacroUndefined(MacroNameTok, MI);
+  virtual void MacroUndefined(const Token &MacroNameTok) {
+    First->MacroUndefined(MacroNameTok);
+    Second->MacroUndefined(MacroNameTok);
   }
 
   virtual void Defined(const Token &MacroNameTok) {
diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h
index 2947c9e..043d3ac 100644
--- a/include/clang/Lex/PreprocessingRecord.h
+++ b/include/clang/Lex/PreprocessingRecord.h
@@ -25,6 +25,7 @@
 namespace clang {
   class IdentifierInfo;
   class PreprocessingRecord;
+  class Preprocessor;
 }
 
 /// \brief Allocates memory within a Clang preprocessing record.
@@ -283,6 +284,7 @@ namespace clang {
   /// including the various preprocessing directives processed, macros 
   /// expanded, etc.
   class PreprocessingRecord : public PPCallbacks {
+    Preprocessor *PP;
     SourceManager &SourceMgr;
 
     /// \brief Whether we should include nested macro expansions in
@@ -353,7 +355,7 @@ namespace clang {
     
   public:
     /// \brief Construct a new preprocessing record.
-    PreprocessingRecord(SourceManager &SM, bool IncludeNestedMacroExpansions);
+    PreprocessingRecord(Preprocessor *PP, bool IncludeNestedMacroExpansions);
     
     /// \brief Allocate memory in the preprocessing record.
     void *Allocate(unsigned Size, unsigned Align = 8) {
@@ -537,7 +539,7 @@ namespace clang {
     virtual void MacroExpands(const Token &Id, const MacroInfo* MI,
                               SourceRange Range);
     virtual void MacroDefined(const Token &Id, const MacroInfo *MI);
-    virtual void MacroUndefined(const Token &Id, const MacroInfo *MI);
+    virtual void MacroUndefined(const Token &Id);
     virtual void InclusionDirective(SourceLocation HashLoc,
                                     const Token &IncludeTok,
                                     StringRef FileName,
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index f62ca57..87efe9b 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -151,7 +151,7 @@ public:
   void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI);
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
-  void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI);
+  void MacroUndefined(const Token &MacroNameTok);
 };
 }  // end anonymous namespace
 
@@ -310,8 +310,7 @@ void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
   EmittedMacroOnThisLine = true;
 }
 
-void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
-                                              const MacroInfo *MI) {
+void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok) {
   // Only print out macro definitions in -dD mode.
   if (!DumpDefines) return;
 
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 748bc38..6e8fb53 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1810,6 +1810,10 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
   // Check to see if this is the last token on the #undef line.
   CheckEndOfDirective("undef");
 
+  // If the callbacks want to know, tell them about the macro #undef.
+  if (Callbacks)
+    Callbacks->MacroUndefined(MacroNameTok);
+
   // Okay, we finally have a valid identifier to undef.
   MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
 
@@ -1819,10 +1823,6 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
   if (!MI->isUsed() && MI->isWarnIfUnused())
     Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
-  // If the callbacks want to know, tell them about the macro #undef.
-  if (Callbacks)
-    Callbacks->MacroUndefined(MacroNameTok, MI);
-
   if (MI->isWarnIfUnused())
     WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
 
diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp
index 6c36e73..d02270b 100644
--- a/lib/Lex/PreprocessingRecord.cpp
+++ b/lib/Lex/PreprocessingRecord.cpp
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "clang/Lex/PreprocessingRecord.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Token.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -37,9 +38,10 @@ InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
   this->FileName = StringRef(Memory, FileName.size());
 }
 
-PreprocessingRecord::PreprocessingRecord(SourceManager &SM,
+PreprocessingRecord::PreprocessingRecord(Preprocessor *PP,
                                          bool IncludeNestedMacroExpansions)
-  : SourceMgr(SM), IncludeNestedMacroExpansions(IncludeNestedMacroExpansions),
+  : PP(PP), SourceMgr(PP->getSourceManager()),
+    IncludeNestedMacroExpansions(IncludeNestedMacroExpansions),
     ExternalSource(0)
 {
 }
@@ -352,12 +354,13 @@ void PreprocessingRecord::MacroDefined(const Token &Id,
                                        /*isLoaded=*/false);
 }
 
-void PreprocessingRecord::MacroUndefined(const Token &Id,
-                                         const MacroInfo *MI) {
-  llvm::DenseMap<const MacroInfo *, PPEntityID>::iterator Pos
-    = MacroDefinitions.find(MI);
-  if (Pos != MacroDefinitions.end())
-    MacroDefinitions.erase(Pos);
+void PreprocessingRecord::MacroUndefined(const Token &Id) {
+  if (const MacroInfo *MI = PP->getMacroInfo(Id.getIdentifierInfo())) {
+    llvm::DenseMap<const MacroInfo *, PPEntityID>::iterator Pos
+      = MacroDefinitions.find(MI);
+    if (Pos != MacroDefinitions.end())
+      MacroDefinitions.erase(Pos);
+  }
 }
 
 void PreprocessingRecord::InclusionDirective(
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 75ab89d..f8b0dad 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -659,7 +659,6 @@ void Preprocessor::createPreprocessingRecord(
   if (Record)
     return;
   
-  Record = new PreprocessingRecord(getSourceManager(),
-                                   IncludeNestedMacroExpansions);
+  Record = new PreprocessingRecord(this, IncludeNestedMacroExpansions);
   addPPCallbacks(Record);
 }
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 69ddc42..7610142 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -82,8 +82,7 @@ public:
   }
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
-  /// MI is released immediately following this callback.
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  virtual void MacroUndefined(const Token &MacroNameTok) {
   }
 
   /// MacroExpands - This is called by when a macro invocation is found.
