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

Victor Campos via libc-commits libc-commits at lists.llvm.org
Wed Apr 8 08:08:13 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("")
----------------
vhscampos wrote:

This is very similar to the logic in the case of functions. Consider extracting it into a new function to cut duplication

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


More information about the libc-commits mailing list