[libc-commits] [libc] [libc] Produce standard-compliant header guard macros in hdrgen (PR #127356)
Roland McGrath via libc-commits
libc-commits at lists.llvm.org
Sat Feb 15 16:35:02 PST 2025
https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/127356
Macros starting with alphabetic characters such as "LLVM" are in
the application name space and cannot be defined or used by a
conforming implementation's headers. This fixes the headers that
are entirely generated, and the __llvm-libc-common.h header to
use a conforming macro name for the header guard. That is, it
starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers
starting with an underscore followed by a capital letter are in
the name space reserved for the implementation.
The remaining headers either will be fixed implicitly by removal
of their custom template files, or will need to be fixed by hand.
>From afe5bb65c5fd6c1df1582f2fc15e0465b366d306 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Fri, 14 Feb 2025 00:45:09 -0800
Subject: [PATCH] [libc] Produce standard-compliant header guard macros in
hdrgen
Macros starting with alphabetic characters such as "LLVM" are in
the application name space and cannot be defined or used by a
conforming implementation's headers. This fixes the headers that
are entirely generated, and the __llvm-libc-common.h header to
use a conforming macro name for the header guard. That is, it
starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers
starting with an underscore followed by a capital letter are in
the name space reserved for the implementation.
The remaining headers either will be fixed implicitly by removal
of their custom template files, or will need to be fixed by hand.
---
libc/include/__llvm-libc-common.h | 6 +++---
libc/utils/hdrgen/header.py | 2 +-
libc/utils/hdrgen/tests/expected_output/subdir/test.h | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index a0fa506c01ab8..212e3c6a9446c 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_COMMON_H
-#define LLVM_LIBC_COMMON_H
+#ifndef _LLVM_LIBC_COMMON_H
+#define _LLVM_LIBC_COMMON_H
#define __LLVM_LIBC__ 1
@@ -87,4 +87,4 @@
#endif // __cplusplus
-#endif // LLVM_LIBC_COMMON_H
+#endif // _LLVM_LIBC_COMMON_H
diff --git a/libc/utils/hdrgen/header.py b/libc/utils/hdrgen/header.py
index 9ea9f98f8fc83..42a075c4b6c89 100644
--- a/libc/utils/hdrgen/header.py
+++ b/libc/utils/hdrgen/header.py
@@ -124,7 +124,7 @@ def includes(self):
}
def header_guard(self):
- return "LLVM_LIBC_" + "_".join(
+ return "_LLVM_LIBC_" + "_".join(
word.upper() for word in NONIDENTIFIER.split(self.name) if word
)
diff --git a/libc/utils/hdrgen/tests/expected_output/subdir/test.h b/libc/utils/hdrgen/tests/expected_output/subdir/test.h
index 20bab502e6821..40936bcfcba6d 100644
--- a/libc/utils/hdrgen/tests/expected_output/subdir/test.h
+++ b/libc/utils/hdrgen/tests/expected_output/subdir/test.h
@@ -6,8 +6,8 @@
//
//===---------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SUBDIR_TEST_H
-#define LLVM_LIBC_SUBDIR_TEST_H
+#ifndef _LLVM_LIBC_SUBDIR_TEST_H
+#define _LLVM_LIBC_SUBDIR_TEST_H
#include "../__llvm-libc-common.h"
#include "../llvm-libc-types/type_a.h"
@@ -23,4 +23,4 @@ int *ptrfunc(void) __NOEXCEPT;
__END_C_DECLS
-#endif // LLVM_LIBC_SUBDIR_TEST_H
+#endif // _LLVM_LIBC_SUBDIR_TEST_H
More information about the libc-commits
mailing list