[libc-commits] [libc] [libc][hdrgen] Extend guard attribute support for types (PR #189803)

via libc-commits libc-commits at lists.llvm.org
Fri Apr 10 13:26:33 PDT 2026


================
@@ -248,6 +248,38 @@ def relpath(file):
             )
         ]
 
+        # Add guarded types
+        append_blank_line_if_guarded_types_exist = True
+        current_guard = None
+        for typ in sorted(self.types):
+            path = COMPILER_HEADER_TYPES.get(
+                typ.name,
+                PurePosixPath("llvm-libc-types") / f"{typ.name}.h",
+            )
+            if append_blank_line_if_guarded_types_exist and typ.guard is not None:
+                append_blank_line_if_guarded_types_exist = False
+                content.append("")
+            if typ.guard is None:
+                continue
+            if current_guard is None:
+                current_guard = typ.guard
+                content.append(f"#ifdef {current_guard}")
+                content.append(f'#include "{relpath(path)!s}"')
+            elif current_guard == typ.guard:
+                content.append(f'#include "{relpath(path)!s}"')
+            else:
+                content.append(f"#endif // {current_guard}")
+                content.append("")
+                current_guard = typ.guard
+                if current_guard is not None:
+                    content.append(f"#ifdef {current_guard}")
+                content.append(f'#include "{relpath(path)!s}"')
+        if current_guard is not None:
+            content.append(f"#endif // {current_guard}")
+            content.append("")
----------------
un-pixelated wrote:

I'll work on the suggested changes, thank you!

https://github.com/llvm/llvm-project/pull/189803


More information about the libc-commits mailing list