[libc-commits] [libc] 2157aec - [libc] Produce standard-compliant header guard macros in hdrgen (#127356)

via libc-commits libc-commits at lists.llvm.org
Sat Feb 15 17:36:47 PST 2025


Author: Roland McGrath
Date: 2025-02-15T17:36:44-08:00
New Revision: 2157aecfe429f763c23d0ec8a59b896799e2d031

URL: https://github.com/llvm/llvm-project/commit/2157aecfe429f763c23d0ec8a59b896799e2d031
DIFF: https://github.com/llvm/llvm-project/commit/2157aecfe429f763c23d0ec8a59b896799e2d031.diff

LOG: [libc] Produce standard-compliant header guard macros in hdrgen (#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.

Added: 
    

Modified: 
    libc/include/__llvm-libc-common.h
    libc/utils/hdrgen/header.py
    libc/utils/hdrgen/tests/expected_output/subdir/test.h

Removed: 
    


################################################################################
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