dang created this revision.
dang added reviewers: zixuw, ributzka.
Herald added a project: All.
dang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123295

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===================================================================
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -587,7 +587,8 @@
 
 class MacroCallback : public PPCallbacks {
 public:
-  MacroCallback(const SourceManager &SM, APISet &API) : SM(SM), API(API) {}
+  MacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP)
+      : SM(SM), API(API), PP(PP) {}
 
   void MacroDefined(const Token &MacroNameToken,
                     const MacroDirective *MD) override {
@@ -614,9 +615,9 @@
     if (!Undef)
       return;
 
-    llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) {
-      return MD.getMacroInfo()->getDefinitionLoc() ==
-             PM.MD->getMacroInfo()->getDefinitionLoc();
+    llvm::erase_if(PendingMacros, [&MD, this](const PendingMacro &PM) {
+      return MD.getMacroInfo()->isIdenticalTo(*PM.MD->getMacroInfo(), PP,
+                                              /*Syntactically*/ false);
     });
   }
 
@@ -652,6 +653,7 @@
 
   const SourceManager &SM;
   APISet &API;
+  Preprocessor &PP;
   llvm::SmallVector<PendingMacro> PendingMacros;
 };
 
@@ -672,8 +674,8 @@
       CI.getFrontendOpts().Inputs.back().getKind().getLanguage());
 
   // Register preprocessor callbacks that will add macro definitions to API.
-  CI.getPreprocessor().addPPCallbacks(
-      std::make_unique<MacroCallback>(CI.getSourceManager(), *API));
+  CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
+      CI.getSourceManager(), *API, CI.getPreprocessor()));
 
   return std::make_unique<ExtractAPIConsumer>(CI.getASTContext(), *API);
 }


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===================================================================
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -587,7 +587,8 @@
 
 class MacroCallback : public PPCallbacks {
 public:
-  MacroCallback(const SourceManager &SM, APISet &API) : SM(SM), API(API) {}
+  MacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP)
+      : SM(SM), API(API), PP(PP) {}
 
   void MacroDefined(const Token &MacroNameToken,
                     const MacroDirective *MD) override {
@@ -614,9 +615,9 @@
     if (!Undef)
       return;
 
-    llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) {
-      return MD.getMacroInfo()->getDefinitionLoc() ==
-             PM.MD->getMacroInfo()->getDefinitionLoc();
+    llvm::erase_if(PendingMacros, [&MD, this](const PendingMacro &PM) {
+      return MD.getMacroInfo()->isIdenticalTo(*PM.MD->getMacroInfo(), PP,
+                                              /*Syntactically*/ false);
     });
   }
 
@@ -652,6 +653,7 @@
 
   const SourceManager &SM;
   APISet &API;
+  Preprocessor &PP;
   llvm::SmallVector<PendingMacro> PendingMacros;
 };
 
@@ -672,8 +674,8 @@
       CI.getFrontendOpts().Inputs.back().getKind().getLanguage());
 
   // Register preprocessor callbacks that will add macro definitions to API.
-  CI.getPreprocessor().addPPCallbacks(
-      std::make_unique<MacroCallback>(CI.getSourceManager(), *API));
+  CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
+      CI.getSourceManager(), *API, CI.getPreprocessor()));
 
   return std::make_unique<ExtractAPIConsumer>(CI.getASTContext(), *API);
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to