Skip to content

fix: anonymous struct detection uses wrong spelling marker - #2460

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/abi-anonymous-struct-detection-uses-wrong
Open

fix: anonymous struct detection uses wrong spelling marker#2460
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/abi-anonymous-struct-detection-uses-wrong

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in ci/check_c_abi/check_c_abi/abi.py: anonymous struct detection uses wrong spelling marker.

Changes

  • ci/check_c_abi/check_c_abi/abi.py: anonymous struct detection uses wrong spelling marker.

Details

--- a/ci/check_c_abi/check_c_abi/abi.py
+++ b/ci/check_c_abi/check_c_abi/abi.py
@@ -1,6 +1,6 @@
-def _is_unnamed_struct(cursor: clang.cindex.Cursor) -> bool:
-    return (
-        cursor.kind == clang.cindex.CursorKind.STRUCT_DECL
-        and cursor.spelling.startswith("struct ")
-        and "unnamed " in cursor.spelling
-    )
+def _is_unnamed_struct(cursor: clang.cindex.Cursor) -> bool:
+    # Anonymous record declarations have no tag, so libclang reports an empty spelling.
+    return (
+        cursor.kind == clang.cindex.CursorKind.STRUCT_DECL
+        and not cursor.spelling
+    )

Tests

  • ci/check_c_abi/tests/test_abi.py
--- /dev/null
+++ b/ci/check_c_abi/tests/test_abi.py
@@ -0,0 +1,53 @@
+import types
+
+import pytest
+
+import clang.cindex
+
+from check_c_abi.abi import _is_unnamed_struct, Abi
+
+
+def _make_cursor(kind, spelling):
+    return types.SimpleNamespace(kind=kind, spelling=spelling)
+
+
+def test_is_unnamed_struct_detects_empty_spelling():
+    cursor = _make_cursor(clang.cindex.CursorKind.STRUCT_DECL, "")
+    assert _is_unnamed_struct(cursor) is True
+
+
+def test_is_unnamed_struct_rejects_named_struct():
+    cursor = _make_cursor(clang.cindex.CursorKind.STRUCT_DECL, "my_struct")
+    assert _is_unnamed_struct(cursor) is False
+
+
+def test_is_unnamed_struct_rejects_non_struct():
+    cursor = _make_cursor(clang.cindex.CursorKind.FUNCTION_DECL, "")
+    assert _is_unnamed_struct(cursor) is False
+
+
+def test_abi_skips_and_renames_anonymous_structs(tmp_path):
+    root = tmp_path / "include"
+    root.mkdir()
+    header = root / "all.h"
+    header.write_text(
+        """
+struct { int a; } unnamed_global;
+typedef struct { int b; } named_t;
+struct real_struct { int c; };
+"""
+    )
+
+    abi = Abi.from_include_path(root, "all.h")
+    struct_names = {s.name for s in abi.structs}
+
+    assert len(abi.structs) == 2
+    assert "" not in struct_names
+    assert "named_t" in struct_names
+    assert "real_struct" in struct_names
+    named = next(s for s in abi.structs if s.name == "named_t")
+    assert ("int", "b") in named.members

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@andrewwhitecdw
andrewwhitecdw requested a review from a team as a code owner August 17, 2026 20:25
@copy-pr-bot

copy-pr-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant