From 80f5475adfe179739a45d42850f8c06a630bc3a0 Mon Sep 17 00:00:00 2001
From: Chandler Carruth <chandlerc@gmail.com>
Date: Fri, 17 Jun 2022 09:10:41 +0000
Subject: [PATCH] Patch for mallinfo2 when using Bazel build system.

This detects and defines the `HAVE_MALLINFO2` macro based on the glibc
version to allow easy use of the Bazel build on systems with modern
glibc installs.
---
 llvm/lib/Support/Unix/Process.inc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 550b0de2e045..6d449489c450 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -22,6 +22,13 @@
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <signal.h>
+// When glibc is in use, detect mallinfo2 to address mallinfo deprecation
+// warnings.
+#if !defined(HAVE_MALLINFO2) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 33)
+#define HAVE_MALLINFO2
+#endif  // __GLIBC_PREREQ(2, 33)
+#endif  // !defined(HAVE_MALLINFO2) && defined(__GLIBC_PREREQ)
 #if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
 #include <malloc.h>
 #endif
--
2.48.1
