Add SAL annotation extraction to windows-rdl clang parser#4303
Draft
Add SAL annotation extraction to windows-rdl clang parser#4303
Conversation
- 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>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Win32 parameters are annotated with SAL macros (
_In_,_Out_,_Inout_,_In_opt_, etc.) that encode direction and optional metadata. Thewindows-rdlclang 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 checksCXCursor_AnnotateAttrchildren (from__attribute__((annotate("_In_")))portable stubs) andCXCursor_UnexposedAttrchildren (from MSVC__declspec(...)SAL expansion). Maps ~40 common SAL macros to flags.clang/field.rs:Parampromoted from a type alias forFieldto a proper struct with anannotation: ParamAnnotationfield.clang/fn.rs:parse()callsextract_sal()perCXCursor_ParmDecl;write()emits#[in]/#[out]/#[opt]using the same logic aswriter::write_params()to guarantee stable roundtrips. Newsal_attrs_for_param()helper shared with interface.rs.clang/interface.rs,clang/callback.rs: updated to constructParamwith annotation field.Example
Given a header with SAL stubs:
The clang parser now emits:
Test + docs
sal.h/sal.rdlexercising_In_,_Out_,_Inout_,_In_opt_,_Out_opt_.rdl.md: new "Parameter Direction Attributes" section documenting#[in],#[out],#[opt]and their SAL correspondence.