Skip to content

Add SAL annotation extraction to windows-rdl clang parser#4303

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/add-sal-annotations-extraction
Draft

Add SAL annotation extraction to windows-rdl clang parser#4303
Copilot wants to merge 3 commits intomasterfrom
copilot/add-sal-annotations-extraction

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

Win32 parameters are annotated with SAL macros (_In_, _Out_, _Inout_, _In_opt_, etc.) that encode direction and optional metadata. The windows-rdl clang parser previously ignored these, losing parameter direction information when generating RDL from C/C++ headers.

Core changes

  • clang/sal.rs (new): ParamAnnotation { in_param, out_param, optional } struct + extract_sal(cursor, tu) that checks CXCursor_AnnotateAttr children (from __attribute__((annotate("_In_"))) portable stubs) and CXCursor_UnexposedAttr children (from MSVC __declspec(...) SAL expansion). Maps ~40 common SAL macros to flags.

  • clang/field.rs: Param promoted from a type alias for Field to a proper struct with an annotation: ParamAnnotation field.

  • clang/fn.rs: parse() calls extract_sal() per CXCursor_ParmDecl; write() emits #[in]/#[out]/#[opt] using the same logic as writer::write_params() to guarantee stable roundtrips. New sal_attrs_for_param() helper shared with interface.rs.

  • clang/interface.rs, clang/callback.rs: updated to construct Param with annotation field.

Example

Given a header with SAL stubs:

#define _In_     __attribute__((annotate("_In_")))
#define _Inout_  __attribute__((annotate("_Inout_")))
#define _In_opt_ __attribute__((annotate("_In_opt_")))

void ReadBuffer(_In_ int* data, int count);
void Transform(_Inout_ int* value);
void LookupByName(_In_opt_ const char* name);

The clang parser now emits:

extern fn ReadBuffer(#[in] data: *mut i32, count: i32);
extern fn Transform(#[in] #[out] value: *mut i32);
extern fn LookupByName(#[opt] name: *const i8);

Test + docs

  • New roundtrip test sal.h/sal.rdl exercising _In_, _Out_, _Inout_, _In_opt_, _Out_opt_.
  • rdl.md: new "Parameter Direction Attributes" section documenting #[in], #[out], #[opt] and their SAL correspondence.

Copilot AI linked an issue Apr 25, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 25, 2026 02:09
- Add clang/sal.rs with ParamAnnotation struct and SAL extraction logic
- Update clang/field.rs: Param is now a proper struct with annotation field
- Update clang/fn.rs: extract SAL in parse(), emit #[in]/#[out]/#[opt] in write()
- Update clang/interface.rs: extract SAL for interface method parameters
- Update clang/callback.rs: use default annotation for callback params
- Add roundtrip test: sal.h and sal.rdl golden file
- Document parameter direction attributes in rdl.md

Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/476e9b85-a07f-4412-9784-776a3b26537b

Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Copilot AI changed the title [WIP] Add extraction of SAL annotations for Win32 parameters Add SAL annotation extraction to windows-rdl clang parser Apr 25, 2026
Copilot AI requested a review from kennykerr April 25, 2026 02:11
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.

windows-rdl gaps - SAL annotations

2 participants