This is an archive of the discontinued LLVM Phabricator instance.

[MS ABI] Add mangled type for auto template parameter whose argument kind is Integeral
ClosedPublic

Authored by zequanwu on May 21 2020, 2:45 PM.

Details

Reviewers
thakis
rnk
Summary

Add mangled type for auto template parameter to differentiate different types of template integer arguments, as MSVC does: https://godbolt.org/z/6FMZbF

Bug filed here: https://bugs.llvm.org/show_bug.cgi?id=45969 which is caused by missing mangled type for template integer argument.

Diff Detail

Event Timeline

zequanwu created this revision.May 21 2020, 2:45 PM
zequanwu abandoned this revision.May 21 2020, 6:43 PM
zequanwu updated this revision to Diff 266082.May 25 2020, 3:06 PM
zequanwu retitled this revision from [MS ABI] Add mangled type for template integer argument to [MS ABI] Add mangled type for auto template parameter whose argument kind is Integeral .
zequanwu edited the summary of this revision. (Show Details)
  • Only add mangled type for auto template parameter, whose argument kind is Integral.
  • MSVC mangled name has 1 more letter M before the mangled type, but I don't do it here because I think the M is from mangled qualifier and the function mangleQualifiers is incomplete yet.
thakis added inline comments.May 25 2020, 6:06 PM
clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp
17 ↗(On Diff #266082)

Are you sure this is correct? MSVC produces a different mangling (https://godbolt.org/z/VxRfJd) and neither undname nor llvm-undname / demumble can demangle the symbol here (while they demange the msvc output according to godbolt fine).

zequanwu marked an inline comment as done.May 26 2020, 9:52 AM
zequanwu added inline comments.
clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp
17 ↗(On Diff #266082)

I use x64 msvc v19.24 version, which gives @"??0?$AutoParmTemplate@$MH0A@@@QAE@XZ". The extra M might come from qualifier mangling.

For x86 msvc v19.24(WINE) version, it produces ??0?$AutoParmTemplate@$0A@@@QAE@XZ for both AutoParmTemplate<0> auto_int and AutoParmTemplate<false> auto_int. Isn't this a bug?

zequanwu edited the summary of this revision. (Show Details)May 26 2020, 11:08 AM
thakis added inline comments.May 26 2020, 1:05 PM
clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp
17 ↗(On Diff #266082)

The test at the top says -triple=i386. If you have x64 mangling results in here, you should use a 64-bit triple (ie -tripe=x86_64-pc-windows). If the mangling is structurally different for different bitnesses, we should probably have tests for both.

For symbols that can be exported, we need to match msvc's mangling to be abi-compatible, no matter if we consider the mangling a bug or not.

zequanwu marked an inline comment as done.May 26 2020, 2:04 PM
zequanwu added inline comments.
clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp
17 ↗(On Diff #266082)

In x64 msvc v19.14, it still gives the same mangling results as x86. From godbolt, it looks like that the mangled type was only added since msvc v19.20. (https://godbolt.org/z/xGT3w-). But the MSVCMajorVersion is only up to 1914, which I guess means v19.14.

I will add a new version for v19.20 which will add M[type] for each auto template parameter.

zequanwu updated this revision to Diff 266339.May 26 2020, 2:59 PM

Add 19.20 version. Only add mangled type for version 19. 20 or later to be abi-compatible with https://godbolt.org/z/Bhc__A

Do you think adding MSVC2019 to make the name mangling compatible with MSVC v19.20 is acceptable?

rnk added inline comments.Sep 10 2020, 2:33 PM
clang/lib/AST/MicrosoftMangle.cpp
384

I see you need an optional QualType here. Can you do this: QualType TemplateArgType = QualType()? I believe it will create a null QualType, which you can then check for with .isNull().

QualType is pointer-sized and is generally passed by value. I think it will help make the other call sites shorter, so they don't need to take the address of a local variable.

1378

For example, if you can avoid the pointer indirection, you can avoid the local variable here.

zequanwu updated this revision to Diff 291111.Sep 10 2020, 6:52 PM
zequanwu marked 2 inline comments as done.
zequanwu retitled this revision from [MS ABI] Add mangled type for auto template parameter whose argument kind is Integeral to [MS ABI] Add mangled type for auto template parameter whose argument kind is Integeral.

rebase and address comment.

rnk added a comment.Sep 11 2020, 12:21 PM

Looks good, but we should test both sides of the MSVC behavior.

clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp
17 ↗(On Diff #266082)

Please add a second RUN line with a new check prefix to test the behavior both before and after.

zequanwu updated this revision to Diff 291331.Sep 11 2020, 1:55 PM

Add check for MSVC version 19.14 (removed AutoParmTemplate<false> auto_bool as its mangled name conflicts with AutoParmTemplate<0> auto_int in V19.14).

zequanwu marked an inline comment as done.Sep 11 2020, 1:55 PM
rnk accepted this revision.Sep 11 2020, 2:42 PM

lgtm, thanks!

This revision is now accepted and ready to land.Sep 11 2020, 2:42 PM
zequanwu updated this revision to Diff 291355.Sep 11 2020, 4:18 PM

update comment.
add a test case for template function.