Improve undefined type detection in llcppsigfetch to mark with Void+Signed pattern - #531
Improve undefined type detection in llcppsigfetch to mark with Void+Signed pattern#531luoliwoshang with Copilot wants to merge 8 commits into
Conversation
|
@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. |
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>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
…igned Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
There was a problem hiding this comment.
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 {
}There was a problem hiding this comment.
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>
When libclang encounters undefined types in C/C++ code, it performs error recovery by defaulting them to
int. This causesllcppsigfetchto incorrectly generateBuiltinTypenodes withKind: 6(int) for undefined types, misleading downstream processing.Problem
Consider this C code with an undefined type:
Previously,
llcppsigfetch --extract "undef fn();" -temp=true -cpp=falsewould generate misleading output that treatsundefas legitimateint:{ "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
inttypes, check ifTypeDeclaration()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
BuiltinTypewith: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
Kind: 0, Flags: 1patternTesting
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.