Skip to content

[llvm] [Demangle] Fix MSVC demangling for placeholder return types #106178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

MaxEW707
Copy link
Contributor

Properly demangle _T and _P return type manglings for MSVC 1920+.
Also added a unit test for @ return type that is used when mangling non-template auto placeholder return type function.

Tested the output against the undname shipped with MSVC 19.40.

@MaxEW707 MaxEW707 force-pushed the mew/fix-undname-auto-return-typ branch from f1bca93 to f7d7506 Compare August 27, 2024 05:45
Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

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

lgtm

@Ryan-rsm-McKenzie
Copy link

Can't you just add these to PrimitiveKind and add the match cases to the end of demanglePrimitiveType? It already tries to parse _*:

case '_': {
if (MangledName.empty()) {
Error = true;
return nullptr;
}
const char F = MangledName.front();
MangledName.remove_prefix(1);
switch (F) {
case 'N':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Bool);
case 'J':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Int64);
case 'K':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Uint64);
case 'W':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Wchar);
case 'Q':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char8);
case 'S':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char16);
case 'U':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char32);
}
break;
}

I don't see why you need to create and entirely new node type for something so simple.

@MaxEW707
Copy link
Contributor Author

Can't you just add these to PrimitiveKind and add the match cases to the end of demanglePrimitiveType? It already tries to parse _*:

case '_': {
if (MangledName.empty()) {
Error = true;
return nullptr;
}
const char F = MangledName.front();
MangledName.remove_prefix(1);
switch (F) {
case 'N':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Bool);
case 'J':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Int64);
case 'K':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Uint64);
case 'W':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Wchar);
case 'Q':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char8);
case 'S':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char16);
case 'U':
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Char32);
}
break;
}

I don't see why you need to create and entirely new node type for something so simple.

Agreed. I assumed that wouldn't fly since pedantically auto and decltype(auto) aren't considered primitive types but I probably should have went with the easiest solution first.

I'll change the code to just add the two new cases to demanglePrimitiveType.

@MaxEW707
Copy link
Contributor Author

@zmodem Let me know if the new changes in this PR are ok with you.

@MaxEW707 MaxEW707 merged commit 8280651 into llvm:main Sep 18, 2024
8 checks passed
@MaxEW707 MaxEW707 deleted the mew/fix-undname-auto-return-typ branch September 18, 2024 03:05
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
…lvm#106178)

Properly demangle `_T` and `_P` return type manglings for MSVC 1920+.
Also added a unit test for `@` return type that is used when mangling
non-template auto placeholder return type function.

Tested the output against the undname shipped with MSVC 19.40.
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.

3 participants