[libc-commits] [libc] [libc] Avoid host header collisions in full builds (-nostdinc) (PR #187025)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Tue Mar 17 06:48:25 PDT 2026


https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/187025

When building the full library with -nostdinc, directly including <stdint.h> may pull in host or compiler-provided headers that collide with LLVM-libc's local macro definitions. Switch to using our internal stdint-macros.h when LIBC_FULL_BUILD is enabled.

Additionally, declare aligned_alloc with noexcept in C++ to match common C library declarations and avoid fatal type specification mismatches during sysroot builds.

>From eca2a0e9f4dc6a279c01266bd81ce72eae438aae Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jeffbailey at google.com>
Date: Tue, 17 Mar 2026 11:37:47 +0000
Subject: [PATCH] [libc] Avoid host header collisions in full builds
 (-nostdinc)

When building the full library with -nostdinc, directly including
<stdint.h> may pull in host or compiler-provided headers that collide
with LLVM-libc's local macro definitions. Switch to using our internal
stdint-macros.h when LIBC_FULL_BUILD is enabled.

Additionally, declare aligned_alloc with noexcept in C++ to match common
C library declarations and avoid fatal type specification mismatches
during sysroot builds.
---
 libc/hdr/func/aligned_alloc.h | 4 ++++
 libc/hdr/stdint_proxy.h       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/libc/hdr/func/aligned_alloc.h b/libc/hdr/func/aligned_alloc.h
index b3436dfee1f23..3c197f4671a76 100644
--- a/libc/hdr/func/aligned_alloc.h
+++ b/libc/hdr/func/aligned_alloc.h
@@ -11,7 +11,11 @@
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
+#ifdef __cplusplus
+extern "C" void *aligned_alloc(size_t, size_t) noexcept;
+#else
 extern "C" void *aligned_alloc(size_t, size_t);
+#endif
 
 #else // Overlay mode
 
diff --git a/libc/hdr/stdint_proxy.h b/libc/hdr/stdint_proxy.h
index 8e815679a4e24..d5c600d5a28bf 100644
--- a/libc/hdr/stdint_proxy.h
+++ b/libc/hdr/stdint_proxy.h
@@ -13,6 +13,10 @@
 // that is `libc.include.stdint` is added to the dependency of all targets
 // that use <stdint.h> header.
 
+#ifdef LIBC_FULL_BUILD
+#include "include/llvm-libc-macros/stdint-macros.h"
+#else
 #include <stdint.h>
+#endif
 
 #endif // LLVM_LIBC_HDR_STDINT_PROXY_H



More information about the libc-commits mailing list