Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clang/lib/AST/MicrosoftMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3374,7 +3374,15 @@ void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T,

void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T,
Qualifiers, SourceRange Range) {
Error(Range.getBegin(), "template type parameter type") << Range;
Out << '?';

llvm::SmallString<64> Name;
Name += "<TTPT_";
Name += llvm::utostr(T->getDepth());
Name += "_";
Name += llvm::utostr(T->getIndex());
Name += ">";
mangleSourceName(Name);
}

void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T,
Expand Down
25 changes: 25 additions & 0 deletions clang/test/AST/ms-uneval-context-crash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fms-compatibility-version=19.33 -emit-llvm %s -o - -triple=x86_64-windows-msvc | FileCheck %s
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think doing codegen (-emit-llvm) in clang/test/AST/ is unusual, those tests normally just look at the AST (though there are exceptions). Maybe there is a better place for this?


template <typename T>
concept C = requires
{
{ T::test([](){}) };
};

template<typename T>
struct Widget {};

template <C T>
struct Widget<T> {};

struct Baz
{
template<typename F>
static constexpr decltype(auto) test(F&&) {}
};

void test()
{
Widget<Baz> w;
}
// CHECK: @"?test@@YAXXZ"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose the mangling you're adding doesn't actually show up anywhere since it's only used for a concept? But then why do we need to mangle it in the first place?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once we get to CodeGen, the method looks like a regular method, except for the fact that one of the template arguments is a class defined inside a concept instantiation. And CodeGen doesn't have any way to check for "is a template argument a class defined inside a concept". So, like all other methods, we stick it into DeferredDecls. And the key for the DeferredDecls map is the mangled name.

We end up trying to mangle a TemplateTypeParmType because we stick the instantiated class into the scope of an uninstantiated class template.

So no, we don't actually need to mangle it, but there's currently no way for CodeGen to check for this situation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(If we wanted to, we could maybe encode this as a kind of linkage in clang/include/clang/Basic/Linkage.h . It's sort of a variation of UniqueExternal: we have an entity with external linkage, but there are restrictions on which generated code can actually refer to it. And the restriction propagates exactly the same way.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(If we wanted to, we could maybe encode this as a kind of linkage in clang/include/clang/Basic/Linkage.h . It's sort of a variation of UniqueExternal: we have an entity with external linkage, but there are restrictions on which generated code can actually refer to it. And the restriction propagates exactly the same way.)

That is a neat idea from looking at Linkage.h and how it is used.
I am going to merge this PR for now if that is ok to fix the regression and then look at this alternative for a future PR. That area of the codebase is still new to me so I am going to take a bit of time to spelunk and better understand it.