Skip to content

Commit 2157aec

Browse files
authored
[libc] Produce standard-compliant header guard macros in hdrgen (llvm#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.
1 parent 3e3af86 commit 2157aec

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

libc/include/__llvm-libc-common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_COMMON_H
10-
#define LLVM_LIBC_COMMON_H
9+
#ifndef _LLVM_LIBC_COMMON_H
10+
#define _LLVM_LIBC_COMMON_H
1111

1212
#define __LLVM_LIBC__ 1
1313

@@ -87,4 +87,4 @@
8787

8888
#endif // __cplusplus
8989

90-
#endif // LLVM_LIBC_COMMON_H
90+
#endif // _LLVM_LIBC_COMMON_H

libc/utils/hdrgen/header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def includes(self):
124124
}
125125

126126
def header_guard(self):
127-
return "LLVM_LIBC_" + "_".join(
127+
return "_LLVM_LIBC_" + "_".join(
128128
word.upper() for word in NONIDENTIFIER.split(self.name) if word
129129
)
130130

libc/utils/hdrgen/tests/expected_output/subdir/test.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===---------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SUBDIR_TEST_H
10-
#define LLVM_LIBC_SUBDIR_TEST_H
9+
#ifndef _LLVM_LIBC_SUBDIR_TEST_H
10+
#define _LLVM_LIBC_SUBDIR_TEST_H
1111

1212
#include "../__llvm-libc-common.h"
1313
#include "../llvm-libc-types/type_a.h"
@@ -23,4 +23,4 @@ int *ptrfunc(void) __NOEXCEPT;
2323

2424
__END_C_DECLS
2525

26-
#endif // LLVM_LIBC_SUBDIR_TEST_H
26+
#endif // _LLVM_LIBC_SUBDIR_TEST_H

0 commit comments

Comments
 (0)