Skip to content

[lldb/cmake] Normalize use of HAVE_LIBCOMPRESSION #135528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

labath
Copy link
Collaborator

@labath labath commented Apr 13, 2025

I think this was the reason behind the failures in 2fd860c: the clang include tool showed the Config.h headers as unused, and because the macro was referenced through an #ifdef, its removal didn't cause build failures. Switching to #cmakedefine01 + #if should make sure this does not happen again.

According to D48977, the #ifndef+#cmakedefine patterns is due to some files redefining the macro themselves. I no longer see any such files in the source tree (there also were no files like that in the source tree at the revision mentioned, but the macro was defined in the hand-maintained XCode project we had at the time).

I *think* this was the reason behind the failures in
2fd860c: the clang include tool showed the
Config.h headers as unused, and because the macro was referenced through an
`#ifdef`, its removal didn't cause build failures.  Switching to
`#cmakedefine01` + `#if` should make sure this does not happen again.

According to D48977, the `#ifndef`+`#cmakedefine` patterns is due to some files
redefining the macro themselves. I no longer see any such files in the source
tree (there also were no files like that in the source tree at the revision
mentioned, but the macro *was* defined in the hand-maintained XCode project
we had at the time).
@labath labath requested a review from JDevlieghere as a code owner April 13, 2025 07:29
@llvmbot llvmbot added the lldb label Apr 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 13, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

I think this was the reason behind the failures in 2fd860c: the clang include tool showed the Config.h headers as unused, and because the macro was referenced through an #ifdef, its removal didn't cause build failures. Switching to #cmakedefine01 + #if should make sure this does not happen again.

According to D48977, the #ifndef+#cmakedefine patterns is due to some files redefining the macro themselves. I no longer see any such files in the source tree (there also were no files like that in the source tree at the revision mentioned, but the macro was defined in the hand-maintained XCode project we had at the time).


Full diff: https://github.com/llvm/llvm-project/pull/135528.diff

4 Files Affected:

  • (modified) lldb/include/lldb/Host/Config.h.cmake (+1-3)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (+1-1)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+3-9)
diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index 9e538534086a2..46e9a95781c32 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -23,9 +23,7 @@
 
 #cmakedefine01 HAVE_NR_PROCESS_VM_READV
 
-#ifndef HAVE_LIBCOMPRESSION
-#cmakedefine HAVE_LIBCOMPRESSION
-#endif
+#cmakedefine01 HAVE_LIBCOMPRESSION
 
 #cmakedefine01 LLDB_ENABLE_POSIX
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 77eadfc8c9f6c..ed9a0dad48eb9 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -46,7 +46,7 @@
 #define DEBUGSERVER_BASENAME "lldb-server"
 #endif
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
 #include <compression.h>
 #endif
 
@@ -77,7 +77,7 @@ GDBRemoteCommunication::~GDBRemoteCommunication() {
     Disconnect();
   }
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
   if (m_decompression_scratch)
     free (m_decompression_scratch);
 #endif
@@ -514,7 +514,7 @@ bool GDBRemoteCommunication::DecompressPacket() {
     }
   }
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
   if (m_compression_type == CompressionType::ZlibDeflate ||
       m_compression_type == CompressionType::LZFSE ||
       m_compression_type == CompressionType::LZ4 ||
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 107c0896c4e61..45688d24bc5c2 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -227,7 +227,7 @@ class GDBRemoteCommunication : public Communication {
   HostThread m_listen_thread;
   std::string m_listen_url;
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
   CompressionType m_decompression_scratch_type = CompressionType::None;
   void *m_decompression_scratch = nullptr;
 #endif
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 501670d62e75b..748f95c61cd3c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -41,7 +41,7 @@
 #include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_ZLIB
 #include "llvm/Support/JSON.h"
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
 #include <compression.h>
 #endif
 
@@ -1104,7 +1104,7 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
   CompressionType avail_type = CompressionType::None;
   llvm::StringRef avail_name;
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
   if (avail_type == CompressionType::None) {
     for (auto compression : supported_compressions) {
       if (compression == "lzfse") {
@@ -1114,9 +1114,6 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
       }
     }
   }
-#endif
-
-#if defined(HAVE_LIBCOMPRESSION)
   if (avail_type == CompressionType::None) {
     for (auto compression : supported_compressions) {
       if (compression == "zlib-deflate") {
@@ -1140,7 +1137,7 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
   }
 #endif
 
-#if defined(HAVE_LIBCOMPRESSION)
+#if HAVE_LIBCOMPRESSION
   if (avail_type == CompressionType::None) {
     for (auto compression : supported_compressions) {
       if (compression == "lz4") {
@@ -1150,9 +1147,6 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
       }
     }
   }
-#endif
-
-#if defined(HAVE_LIBCOMPRESSION)
   if (avail_type == CompressionType::None) {
     for (auto compression : supported_compressions) {
       if (compression == "lzma") {

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants