This is an archive of the discontinued LLVM Phabricator instance.

[ms] Fix mangling of vector types in QMM_Result contexts.
ClosedPublic

Authored by thakis on Jul 20 2018, 6:47 AM.

Details

Reviewers
zturner
rnk
Summary

If QMM_Result is set (which it is for return types, RTTI descriptors, and exception type descriptors), tag types (structs, enums, classes, unions) get their qualifiers mangled in.

__m64 and friends is a struct/union thingy in MSVC, but not in clang's headers. To make mangling work, we call mangleArtificalTagType(TTK_Union/TTK_Struct for the vector types to mangle them as tag types -- but the isa<TagType> check when mangling in QMM_Result mode isn't true these vector types. Add an isArtificialTagType() function and check for that too. Fixes PR37276 and some other issues.

I tried to audit all references to TagDecl and TagType in MicrosoftMangle.cpp to see if there are other places where we need to call mangleArtificalTagType(), but I couldn't find other places.

I tried to audit all calls to mangleArtificalTagType() to see if isArtificialTagType() needs to handle more than just the vector types, but as far as I can tell all other types we use it for are types that MSVC can't handle at all (Objective-C types etc).

Diff Detail

Event Timeline

thakis created this revision.Jul 20 2018, 6:47 AM

If you want to compare the CHECK lines to MSVC's output: https://godbolt.org/g/Cvf4p4

thakis added a reviewer: rnk.Jul 21 2018, 5:47 PM

rnk, since zturner is out until Thu, can you take a look?

rnk added a comment.Jul 23 2018, 10:16 AM

Thanks!

rnk, since zturner is out until Thu, can you take a look?

Yep.

clang/lib/AST/MicrosoftMangle.cpp
1756

I think we might as well mangle qualifiers into all vector types. Ultimately, they are all mangled as artificial tag types, and MSVC mangles qualifiers into tag return types. I don't think it's worth the code complexity to distinguish between the m64 / m128* vector types that require ABI compatibility and those that don't.

clang/test/CodeGenCXX/mangle-ms-vector-types.cpp
50–51

Probably worth testing a const return type to show we're mangling the qualifiers and not just adding "?A" sometimes.

thakis updated this revision to Diff 156858.Jul 23 2018, 12:54 PM

Address comments.

thakis marked 2 inline comments as done.Jul 23 2018, 12:55 PM

Thanks! All done.

rnk accepted this revision.Jul 23 2018, 12:57 PM

lgtm

This revision is now accepted and ready to land.Jul 23 2018, 12:57 PM
thakis closed this revision.Jul 23 2018, 1:04 PM

r337732, thanks!