Skip to content

Conversation

@vonosmas
Copy link
Contributor

This PR adds required macro definitions to <nl_types.h> header, so that they're available to the code including it.

The header itself was added in 12abe8a, together with stub definitions of the three required functions.

@vonosmas vonosmas requested review from lntue and petrhosek October 21, 2025 18:41
@llvmbot llvmbot added the libc label Oct 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Changes

This PR adds required macro definitions to &lt;nl_types.h&gt; header, so that they're available to the code including it.

The header itself was added in 12abe8a, together with stub definitions of the three required functions.


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

6 Files Affected:

  • (modified) libc/include/CMakeLists.txt (+1)
  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/nl-types-macros.h (+16)
  • (modified) libc/include/nl_types.yaml (+5-1)
  • (modified) libc/test/src/nl_types/CMakeLists.txt (+1)
  • (modified) libc/test/src/nl_types/nl_types_test.cpp (+3-2)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 09f169b9a985f..a277690ae2e17 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -776,6 +776,7 @@ add_header_macro(
   ../libc/include/nl_types.yaml
   nl_types.h
   DEPENDS
+    .llvm-libc-macros.nl_types_macros
     .llvm-libc-types.nl_catd
   )
 
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 76c03d913ee12..a33ff6cabbcf5 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -345,6 +345,12 @@ add_macro_header(
     locale-macros.h
 )
 
+add_macro_header(
+  nl_types_macros
+  HDR
+    nl-types-macros.h
+)
+
 add_macro_header(
   pthread_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/nl-types-macros.h b/libc/include/llvm-libc-macros/nl-types-macros.h
new file mode 100644
index 0000000000000..095b9ed1170b0
--- /dev/null
+++ b/libc/include/llvm-libc-macros/nl-types-macros.h
@@ -0,0 +1,16 @@
+//===-- Definition of macros from nl_types.h ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_NL_TYPES_MACROS_H
+#define LLVM_LIBC_MACROS_NL_TYPES_MACROS_H
+
+#define NL_SETD 1
+#define NL_CAT_LOCALE 1
+
+#endif // LLVM_LIBC_MACROS_NL_TYPES_MACROS_H
+
diff --git a/libc/include/nl_types.yaml b/libc/include/nl_types.yaml
index aecbb44a02224..bdb59a82a3337 100644
--- a/libc/include/nl_types.yaml
+++ b/libc/include/nl_types.yaml
@@ -1,7 +1,11 @@
 header: nl_types.h
 standards:
   - posix
-macros: []
+macros:
+  - macro_name: NL_SETD
+    macro_header: nl-types-macros.h
+  - macro_name: NL_CAT_LOCALE
+    macro_header: nl-types-macros.h
 types:
   - type_name: nl_catd
 enums: []
diff --git a/libc/test/src/nl_types/CMakeLists.txt b/libc/test/src/nl_types/CMakeLists.txt
index 4fce637baa726..6bafb32f15c0b 100644
--- a/libc/test/src/nl_types/CMakeLists.txt
+++ b/libc/test/src/nl_types/CMakeLists.txt
@@ -7,6 +7,7 @@ add_libc_test(
   SRCS
     nl_types_test.cpp
   DEPENDS
+    libc.include.llvm-libc-macros.nl_types_macros
     libc.include.llvm-libc-types.nl_catd
     libc.src.nl_types.catopen
     libc.src.nl_types.catclose
diff --git a/libc/test/src/nl_types/nl_types_test.cpp b/libc/test/src/nl_types/nl_types_test.cpp
index 5ae5c5ab28546..7392200272dfd 100644
--- a/libc/test/src/nl_types/nl_types_test.cpp
+++ b/libc/test/src/nl_types/nl_types_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "include/llvm-libc-macros/nl-types-macros.h"
 #include "include/llvm-libc-types/nl_catd.h"
 #include "src/nl_types/catclose.h"
 #include "src/nl_types/catgets.h"
@@ -15,7 +16,7 @@
 using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
 
 TEST_F(LlvmLibcNlTypesTest, CatopenFails) {
-  ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", 0),
+  ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", NL_CAT_LOCALE),
             reinterpret_cast<nl_catd>(-1));
   ASSERT_ERRNO_EQ(EINVAL);
 }
@@ -28,6 +29,6 @@ TEST_F(LlvmLibcNlTypesTest, CatgetsFails) {
   const char *message = "message";
   // Note that we test for pointer equality here, since catgets
   // is expected to return the input argument as-is.
-  ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, 0, 0, message),
+  ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, NL_SETD, 1, message),
             const_cast<char *>(message));
 }

@github-actions
Copy link

github-actions bot commented Oct 21, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@vonosmas vonosmas merged commit 57a8228 into llvm:main Oct 22, 2025
20 checks passed
@vonosmas vonosmas deleted the nl-types-macros branch October 22, 2025 16:41
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
This PR adds required macro definitions to `<nl_types.h>` header, so
that they're available to the code including it.

The header itself was added in 12abe8a,
together with stub definitions of the three required functions.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
This PR adds required macro definitions to `<nl_types.h>` header, so
that they're available to the code including it.

The header itself was added in 12abe8a,
together with stub definitions of the three required functions.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
This PR adds required macro definitions to `<nl_types.h>` header, so
that they're available to the code including it.

The header itself was added in 12abe8a,
together with stub definitions of the three required functions.
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