[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 00:42:10 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff f8042171552ca16e77a5e9367188e7f218474380 ce6501638142a9cbce7733ff9acab70f82d65891 -- clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/cxx20-module-file-info-macros.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index aa2781daef..c6ed8231af 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -935,28 +935,31 @@ void DumpModuleInfoAction::ExecuteAction() {
         SourceManager &SM = PP.getSourceManager();
         clang::MacroInfo *MacroInfo = PP.getMacroInfo(Macro.first);
         if (MacroInfo) {
-          bool isInvalid=true;
-          const char* ContentStrPtr=SM.getCharacterData(MacroInfo->getDefinitionLoc(),&isInvalid);
+          bool isInvalid = true;
+          const char *ContentStrPtr =
+              SM.getCharacterData(MacroInfo->getDefinitionLoc(), &isInvalid);
           if (!isInvalid) {
-          int ContentLength=0;
-          while ( !(*(ContentStrPtr+ContentLength)=='\n') ||  *(ContentStrPtr+ContentLength-1)=='\\') {
-            ContentLength++;
+            int ContentLength = 0;
+            while (!(*(ContentStrPtr + ContentLength) == '\n') ||
+                   *(ContentStrPtr + ContentLength - 1) == '\\') {
+              ContentLength++;
+            }
+            std::string MacroContent =
+                std::string(ContentStrPtr, ContentLength);
+            // Replace '\\\n' with space
+            size_t pos = 0;
+            while ((pos = MacroContent.find("\\\n", pos)) !=
+                   std::string::npos) {
+              MacroContent.replace(pos, 2, " ");
+            }
+            // Merge spaces
+            auto new_end = std::unique(
+                MacroContent.begin(), MacroContent.end(),
+                [](char a, char b) { return a == ' ' && b == ' '; });
+            MacroContent.erase(new_end, MacroContent.end());
+            Out << "     " << MacroContent << '\n';
           }
-          std::string MacroContent=std::string(ContentStrPtr,ContentLength);
-          // Replace '\\\n' with space
-          size_t pos = 0;
-          while ((pos = MacroContent.find("\\\n", pos)) != std::string::npos) {
-            MacroContent.replace(pos, 2," ");
-          }
-          // Merge spaces
-          auto new_end = std::unique(MacroContent.begin(), MacroContent.end(), [](char a, char b) {
-            return a == ' ' && b == ' ';
-          });
-          MacroContent.erase(new_end, MacroContent.end());
-          Out << "     " << MacroContent << '\n';
-          }
-        }
-        else {
+        } else {
           Out << "     " << Macro.first->getName() << "\n";
         }
       }

``````````

</details>


https://github.com/llvm/llvm-project/pull/85745


More information about the cfe-commits mailing list