Skip to content

Improve undefined type detection in llcppsigfetch to mark with Void+Signed pattern - #531

Closed
luoliwoshang with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-22
Closed

Improve undefined type detection in llcppsigfetch to mark with Void+Signed pattern#531
luoliwoshang with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-22

Conversation

Copilot AI commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

When libclang encounters undefined types in C/C++ code, it performs error recovery by defaulting them to int. This causes llcppsigfetch to incorrectly generate BuiltinType nodes with Kind: 6 (int) for undefined types, misleading downstream processing.

Problem

Consider this C code with an undefined type:

undef fn();

Previously, llcppsigfetch --extract "undef fn();" -temp=true -cpp=false would generate misleading output that treats undef as legitimate int:

{
  "Ret": {
    "_Type": "BuiltinType", 
    "Kind": 6,    // int
    "Flags": 0
  }
}

Solution

This PR implements undefined type detection that marks such types with a distinctive pattern instead of misleading int types:

Detection Logic: When processing builtin int types, check if TypeDeclaration() returns a non-null cursor. For legitimate builtin types, this should return null, but for error-recovery types from undefined names, it may return a non-null cursor.

Marking Strategy: Functions with undefined types generate a BuiltinType with:

  • Kind: 0 (Void)
  • Flags: 1 (Signed)

This unique combination provides a clear marker for undefined types since Void+Signed is not a natural builtin type mapping.

Example Output

After this fix, undef fn(); generates:

{
  "Name": {"Name": "fn"},
  "Type": {
    "Ret": {
      "_Type": "BuiltinType", 
      "Kind": 0,    // Void
      "Flags": 1    // Signed
    }
  }
}

Impact

  • Functions with undefined types: Marked with distinctive Kind: 0, Flags: 1 pattern
  • Legitimate functions: Continue to be processed normally
  • Debugging: Easy identification of problematic declarations through the unique Void+Signed signature
  • Downstream processing: Can detect and handle undefined types appropriately without losing function declarations

Testing

Comprehensive test case in testdata/undef_type/ validates the new Void+Signed marking behavior.

Fixes #22.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

@luoliwoshang 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 3 commits August 7, 2025 14:38
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Copilot AI changed the title [WIP] llcppsigfetch:unexpected undef type's default type Fix undefined type detection in llcppsigfetch to prevent incorrect int type defaults Aug 7, 2025
Copilot AI requested a review from luoliwoshang August 7, 2025 14:45
Comment thread _xtool/internal/parser/parser.go
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Copilot AI changed the title Fix undefined type detection in llcppsigfetch to prevent incorrect int type defaults Improve undefined type detection in llcppsigfetch to mark rather than skip invalid declarations Aug 7, 2025
Copilot AI requested a review from luoliwoshang August 7, 2025 15:16
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
…igned

Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Copilot AI changed the title Improve undefined type detection in llcppsigfetch to mark rather than skip invalid declarations Improve undefined type detection in llcppsigfetch to mark with Void+Signed pattern Aug 7, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some update nil check is not nessary! restore it! beacuse the undefined type current is a builtin type @copilot

	if funcDecl != nil {}
if pointeeType == nil {
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unnecessary nil checks as requested. Since undefined types are now properly handled as builtin types with the special Kind: Void (0) and Flags: Signed (1) marking, these functions now return valid BuiltinType objects instead of nil. Commit 5b7d754.

Since undefined types are now properly handled as builtin types with special
Kind: Void (0) and Flags: Signed (1) marking, the nil checks for funcDecl
and pointeeType are no longer necessary. Functions with undefined types now
return valid BuiltinType objects instead of nil.

Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
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.

llcppsigfetch:unexpected undef type's default type

2 participants