[clang] c4a3157 - Add mangling for type trait expressions.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 21 12:59:00 PDT 2023
Author: Richard Smith
Date: 2023-09-21T12:58:32-07:00
New Revision: c4a3157d6622928b3773695159d8039cdea140e3
URL: https://github.com/llvm/llvm-project/commit/c4a3157d6622928b3773695159d8039cdea140e3
DIFF: https://github.com/llvm/llvm-project/commit/c4a3157d6622928b3773695159d8039cdea140e3.diff
LOG: Add mangling for type trait expressions.
libc++ uses type traits directly in constraints in some places, and
constraints now appear in manglings. There's a defined mangling for
these traits in the ABI already, so we should use it.
Fixes #67031.
Added:
Modified:
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGenCXX/mangle-exprs.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 3bbc0a5767ff49d..e7a5a6b6b8119c0 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4640,7 +4640,6 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
case Expr::ShuffleVectorExprClass:
case Expr::ConvertVectorExprClass:
case Expr::StmtExprClass:
- case Expr::TypeTraitExprClass:
case Expr::ArrayTypeTraitExprClass:
case Expr::ExpressionTraitExprClass:
case Expr::VAArgExprClass:
@@ -4992,6 +4991,10 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
// If the result of the operator is implicitly converted to a known
// integer type, that type is used for the literal; otherwise, the type
// of std::size_t or std::ptr
diff _t is used.
+ //
+ // FIXME: We still include the operand in the profile in this case. This
+ // can lead to mangling collisions between function templates that we
+ // consider to be
diff erent.
QualType T = (ImplicitlyConvertedToType.isNull() ||
!ImplicitlyConvertedToType->isIntegerType())? SAE->getType()
: ImplicitlyConvertedToType;
@@ -5054,6 +5057,20 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
break;
}
+ case Expr::TypeTraitExprClass: {
+ // <expression> ::= u <source-name> <template-arg>* E # vendor extension
+ const TypeTraitExpr *TTE = cast<TypeTraitExpr>(E);
+ NotPrimaryExpr();
+ Out << 'u';
+ llvm::StringRef Spelling = getTraitSpelling(TTE->getTrait());
+ Out << Spelling.size() << Spelling;
+ for (TypeSourceInfo *TSI : TTE->getArgs()) {
+ mangleType(TSI->getType());
+ }
+ Out << 'E';
+ break;
+ }
+
case Expr::CXXThrowExprClass: {
NotPrimaryExpr();
const CXXThrowExpr *TE = cast<CXXThrowExpr>(E);
diff --git a/clang/test/CodeGenCXX/mangle-exprs.cpp b/clang/test/CodeGenCXX/mangle-exprs.cpp
index 88406d7fe6d80b5..6ebca562caad58f 100644
--- a/clang/test/CodeGenCXX/mangle-exprs.cpp
+++ b/clang/test/CodeGenCXX/mangle-exprs.cpp
@@ -389,3 +389,13 @@ namespace null {
// CHECK-LABEL: define {{.*}} @_ZN4null8gnu_nullILPv0EEEvPN9enable_ifIXeqT_Ll0EEvE4typeE
template void gnu_null<nullptr>(void *);
}
+
+namespace type_trait {
+ template<typename T> void f(decltype(__is_trivially_copyable(T))) {}
+ // CHECK-LABEL: define {{.*}} @_ZN10type_trait1fIiEEvDTu23__is_trivially_copyableT_EE
+ template void f<int>(bool);
+
+ template<typename T> void g(decltype(__is_trivially_copyable(int) + T())) {}
+ // CHECK-LABEL: define {{.*}} @_ZN10type_trait1gIiEEvDTplu23__is_trivially_copyableiEcvT__EE
+ template void g<int>(int);
+}
More information about the cfe-commits
mailing list