https://github.com/lzcunt updated 
https://github.com/llvm/llvm-project/pull/225654

>From a5eaa71dc128da2c8f8b7907d39cf9d0b1f5693c Mon Sep 17 00:00:00 2001
From: lzcunt <[email protected]>
Date: Sun, 27 Sep 2026 19:36:53 +0300
Subject: [PATCH 1/3] [TargetParser] Add Triple::isMlibc()

---
 llvm/include/llvm/TargetParser/Triple.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index b369b66960b1a..091eda7a8d03e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -848,7 +848,8 @@ class Triple {
   bool isOSGlibc() const {
     return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD ||
             getOS() == Triple::Hurd) &&
-           !isAndroid() && !isMusl() && getEnvironment() != Triple::PAuthTest;
+           !isAndroid() && !isMusl() && !isMlibc() &&
+            getEnvironment() != Triple::PAuthTest;
   }
 
   /// Tests whether the OS is AIX.
@@ -921,6 +922,11 @@ class Triple {
     return Version < VersionTuple(Major);
   }
 
+  /// Tests whether the environment is mlibc.
+  bool isMlibc() const {
+    return getEnvironment() == Triple::Mlibc;
+  }
+
   /// Tests whether the environment is musl-libc
   bool isMusl() const {
     return getEnvironment() == Triple::Musl ||

>From 65a172ac60899abdbe7d72d3e15cdca9c77e8e5b Mon Sep 17 00:00:00 2001
From: lzcunt <[email protected]>
Date: Wed, 23 Sep 2026 12:18:59 +0300
Subject: [PATCH 2/3] [clang][mlibc] Predefine `__mlibc__` for mlibc targets

Also makes `__gnu_linux__` not defined for non-glibc Linux targets.
---
 clang/lib/Basic/Targets/OSTargets.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index fb5c17cefc004..c1f86b9eb1ada 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -393,7 +393,9 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo<Target> {
         // defined for compatibility.
         Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
       }
-    } else {
+    } else if (Triple.isMlibc()) {
+        Builder.defineMacro("__mlibc__");
+    } else if (Triple.isGNUEnvironment()) {
         Builder.defineMacro("__gnu_linux__");
     }
     if (Opts.POSIXThreads)
@@ -452,6 +454,8 @@ class LLVM_LIBRARY_VISIBILITY ManagarmTargetInfo : public 
OSTargetInfo<Target> {
                     MacroBuilder &Builder) const override {
     DefineStd(Builder, "unix", Opts);
     Builder.defineMacro("__managarm__");
+    if (Triple.getEnvironmentName() == "mlibc")
+      Builder.defineMacro("__mlibc__");
     if (Opts.POSIXThreads)
       Builder.defineMacro("_REENTRANT");
     if (Opts.CPlusPlus)

>From b5591c1f51f5344b0c849d2a7ccc4817d34037aa Mon Sep 17 00:00:00 2001
From: lzcunt <[email protected]>
Date: Thu, 24 Sep 2026 16:47:12 +0300
Subject: [PATCH 3/3] __mlibc__ test

---
 clang/test/Preprocessor/init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index faeb7861e5d21..76baba31b2fcd 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1663,6 +1663,7 @@
 // RUN: %clang_cc1 -triple=riscv64-unknown-managarm-mlibc -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix MANAGARM %s
 // RUN: %clang_cc1 -triple=x86_64-unknown-managarm-mlibc -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix MANAGARM %s
 // MANAGARM: #define __managarm__ 1
+// MANAGARM: #define __mlibc__ 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=xcore-none-none < /dev/null | 
FileCheck -match-full-lines -check-prefix XCORE %s
 // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to