[libc-commits] [libc] [libc] allow libc-hdrgen to work on windows files (PR #87292)

Stephen Neuendorffer via libc-commits libc-commits at lists.llvm.org
Mon Apr 1 16:48:57 PDT 2024


https://github.com/stephenneuendorffer updated https://github.com/llvm/llvm-project/pull/87292

>From ada546ddfd0d408cf207d3b08a25f491e28bbed9 Mon Sep 17 00:00:00 2001
From: Stephen Neuendorffer <stephen.neuendorffer at amd.com>
Date: Mon, 1 Apr 2024 15:50:27 -0700
Subject: [PATCH 1/2] [libc] allow libc-hdrgen to work on windows files

The code does some (overly simple?) checks on file syntax.
These checks assume unix line endings and fail on windows.
This commit updates the code to strip extra whitespace,
making the checks more robust, particularly in the presence
of windows line endings.

Fixes #86023
---
 libc/utils/HdrGen/Generator.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp
index 3bcf005adda74f..e1e2e1004ebae5 100644
--- a/libc/utils/HdrGen/Generator.cpp
+++ b/libc/utils/HdrGen/Generator.cpp
@@ -84,11 +84,19 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
       Line = Line.drop_front(CommandPrefixSize);
 
       P = Line.split("(");
+      // It's possible that we have windows line endings, so strip off the extra CR.
+      P.second = P.second.trim();
       if (P.second.empty() || P.second[P.second.size() - 1] != ')') {
         SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
                             llvm::SourceMgr::DK_Error,
                             "Command argument list should begin with '(' "
                             "and end with ')'.");
+        SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
+                            llvm::SourceMgr::DK_Error,
+                            P.second.data());
+        SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
+                            llvm::SourceMgr::DK_Error,
+                            std::to_string(P.second.size()));
         std::exit(1);
       }
       llvm::StringRef CommandName = P.first;

>From fff00ab4f9297c4599422ba3feb630a0823a4101 Mon Sep 17 00:00:00 2001
From: Stephen Neuendorffer <stephen.neuendorffer at amd.com>
Date: Mon, 1 Apr 2024 16:45:07 -0700
Subject: [PATCH 2/2] clang-format

---
 libc/utils/HdrGen/Generator.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp
index e1e2e1004ebae5..d926d5d9ac3c8d 100644
--- a/libc/utils/HdrGen/Generator.cpp
+++ b/libc/utils/HdrGen/Generator.cpp
@@ -84,7 +84,8 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
       Line = Line.drop_front(CommandPrefixSize);
 
       P = Line.split("(");
-      // It's possible that we have windows line endings, so strip off the extra CR.
+      // It's possible that we have windows line endings, so strip off the extra
+      // CR.
       P.second = P.second.trim();
       if (P.second.empty() || P.second[P.second.size() - 1] != ')') {
         SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
@@ -92,8 +93,7 @@ void Generator::generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
                             "Command argument list should begin with '(' "
                             "and end with ')'.");
         SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
-                            llvm::SourceMgr::DK_Error,
-                            P.second.data());
+                            llvm::SourceMgr::DK_Error, P.second.data());
         SrcMgr.PrintMessage(llvm::SMLoc::getFromPointer(P.second.data()),
                             llvm::SourceMgr::DK_Error,
                             std::to_string(P.second.size()));



More information about the libc-commits mailing list