forked from OSchip/llvm-project
MS ABI: Support mangling of return-types deducing to local types
The MS ABI forces us into catch-22 when it comes to functions which return types which are local: - A function is mangled with it's return type. - A type is mangled with it's surrounding context. Avoid this by mangling auto and decltype(autp) directly into the function's return type. Using this mangling has the double advantage of being compatible with the C++ standard without crashing the compiler. N.B. For the curious, the MSVC mangling leads to collisions amongst template functions and either crashes when faced with local types or is otherwise incapable of returning them. llvm-svn: 205282
This commit is contained in:
parent
762bdd5118
commit
2e1e0491b7
|
@ -1545,9 +1545,18 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
|
||||||
Out << '@';
|
Out << '@';
|
||||||
} else {
|
} else {
|
||||||
QualType ResultType = Proto->getReturnType();
|
QualType ResultType = Proto->getReturnType();
|
||||||
if (ResultType->isVoidType())
|
if (const auto *AT =
|
||||||
ResultType = ResultType.getUnqualifiedType();
|
dyn_cast_or_null<AutoType>(ResultType->getContainedAutoType())) {
|
||||||
mangleType(ResultType, Range, QMM_Result);
|
Out << '?';
|
||||||
|
mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false);
|
||||||
|
Out << '?';
|
||||||
|
mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>");
|
||||||
|
Out << '@';
|
||||||
|
} else {
|
||||||
|
if (ResultType->isVoidType())
|
||||||
|
ResultType = ResultType.getUnqualifiedType();
|
||||||
|
mangleType(ResultType, Range, QMM_Result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <argument-list> ::= X # void
|
// <argument-list> ::= X # void
|
||||||
|
|
|
@ -6,3 +6,35 @@ template <typename> int x = 0;
|
||||||
template <> int x<void>;
|
template <> int x<void>;
|
||||||
// CHECK: "\01??$x@H@@3HA"
|
// CHECK: "\01??$x@H@@3HA"
|
||||||
template <> int x<int>;
|
template <> int x<int>;
|
||||||
|
|
||||||
|
// CHECK: "\01?FunctionWithLocalType@@YA?A?<auto>@@XZ"
|
||||||
|
auto FunctionWithLocalType() {
|
||||||
|
struct LocalType {};
|
||||||
|
return LocalType{};
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: "\01?ValueFromFunctionWithLocalType@@3ULocalType@?0??FunctionWithLocalType@@YA?A?<auto>@@XZ@A"
|
||||||
|
auto ValueFromFunctionWithLocalType = FunctionWithLocalType();
|
||||||
|
|
||||||
|
// CHECK: "\01??R<lambda_0>@@QBE?A?<auto>@@XZ"
|
||||||
|
auto LambdaWithLocalType = [] {
|
||||||
|
struct LocalType {};
|
||||||
|
return LocalType{};
|
||||||
|
};
|
||||||
|
|
||||||
|
// CHECK: "\01?ValueFromLambdaWithLocalType@@3ULocalType@?0???R<lambda_0>@@QBE?A?<auto>@@XZ@A"
|
||||||
|
auto ValueFromLambdaWithLocalType = LambdaWithLocalType();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto TemplateFuncionWithLocalLambda(T) {
|
||||||
|
auto LocalLambdaWithLocalType = []() {
|
||||||
|
struct LocalType {};
|
||||||
|
return LocalType{};
|
||||||
|
};
|
||||||
|
return LocalLambdaWithLocalType();
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@??$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z@QBA?A?3@XZ@A"
|
||||||
|
// CHECK: "\01??$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z"
|
||||||
|
// CHECK: "\01??R<lambda_1>@??$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z@QBA?A?1@XZ"
|
||||||
|
auto ValueFromTemplateFuncionWithLocalLambda = TemplateFuncionWithLocalLambda(0);
|
||||||
|
|
Loading…
Reference in New Issue