[clang-tools-extra] [lldb] [clang] Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type." (PR #79302)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 24 07:16:02 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clang-codegen
Author: Erich Keane (erichkeane)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->78041
Based on this comment: https://github.com/llvm/llvm-project/pull/78041#issuecomment-1908243345
and the author's nonavailability to get to it quickly, we're reverting (and will have to revert from the release branch). Hopefully this can be reapplied for 19.
---
Patch is 100.32 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/79302.diff
46 Files Affected:
- (modified) clang-tools-extra/clangd/DumpAST.cpp (-1)
- (modified) clang-tools-extra/clangd/FindTarget.cpp (-1)
- (modified) clang/include/clang/AST/ODRHash.h (-3)
- (modified) clang/include/clang/AST/PropertiesBase.td (-14)
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (-2)
- (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (-2)
- (modified) clang/include/clang/AST/TemplateBase.h (+31-55)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5)
- (modified) clang/include/clang/Sema/Sema.h (+2-2)
- (modified) clang/lib/AST/ASTContext.cpp (-5)
- (modified) clang/lib/AST/ASTImporter.cpp (-13)
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (-3)
- (modified) clang/lib/AST/Decl.cpp (-4)
- (modified) clang/lib/AST/ItaniumMangle.cpp (+2-34)
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+16-62)
- (modified) clang/lib/AST/ODRHash.cpp (-67)
- (modified) clang/lib/AST/StmtProfile.cpp (-6)
- (modified) clang/lib/AST/TemplateBase.cpp (+3-110)
- (modified) clang/lib/AST/TypeLoc.cpp (-1)
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (-10)
- (modified) clang/lib/CodeGen/CGExpr.cpp (+3-9)
- (modified) clang/lib/Index/USRGeneration.cpp (-10)
- (modified) clang/lib/Sema/SemaLookup.cpp (-1)
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-9)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+88-130)
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+18-46)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+8-6)
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (-2)
- (modified) clang/lib/Sema/TreeTransform.h (+2-10)
- (modified) clang/lib/Serialization/ASTReader.cpp (-1)
- (modified) clang/lib/Serialization/ASTWriter.cpp (-1)
- (modified) clang/test/CXX/drs/dr18xx.cpp (+2-2)
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (+1-3)
- (modified) clang/test/CodeGenCXX/mangle-ms-templates.cpp (-48)
- (modified) clang/test/CodeGenCXX/mangle-template.cpp (+1-39)
- (removed) clang/test/CodeGenCXX/template-arguments.cpp (-113)
- (removed) clang/test/Index/USR/structural-value-tpl-arg.cpp (-23)
- (modified) clang/test/Modules/odr_hash.cpp (+3-190)
- (modified) clang/test/SemaCXX/warn-bool-conversion.cpp (-2)
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+21-19)
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+18-22)
- (modified) clang/tools/libclang/CIndex.cpp (-5)
- (modified) clang/tools/libclang/CXCursor.cpp (-3)
- (modified) clang/www/cxx_status.html (+5-13)
- (modified) lldb/include/lldb/lldb-enumerations.h (-1)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (-3)
``````````diff
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 9a525efb938e8d5..b0cec65c39fa31d 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -143,7 +143,6 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
TEMPLATE_ARGUMENT_KIND(Declaration);
TEMPLATE_ARGUMENT_KIND(Template);
TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
- TEMPLATE_ARGUMENT_KIND(StructuralValue);
#undef TEMPLATE_ARGUMENT_KIND
}
llvm_unreachable("Unhandled ArgKind enum");
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a098..3d73e77b16aff4e 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1039,7 +1039,6 @@ class ExplicitReferenceCollector
case TemplateArgument::Pack:
case TemplateArgument::Type:
case TemplateArgument::Expression:
- case TemplateArgument::StructuralValue:
break; // Handled by VisitType and VisitExpression.
};
return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
diff --git a/clang/include/clang/AST/ODRHash.h b/clang/include/clang/AST/ODRHash.h
index a1caa6d39a87c3c..cedf644520fc320 100644
--- a/clang/include/clang/AST/ODRHash.h
+++ b/clang/include/clang/AST/ODRHash.h
@@ -25,7 +25,6 @@
namespace clang {
-class APValue;
class Decl;
class IdentifierInfo;
class NestedNameSpecifier;
@@ -102,8 +101,6 @@ class ODRHash {
// Save booleans until the end to lower the size of data to process.
void AddBoolean(bool value);
- void AddStructuralValue(const APValue &);
-
static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent);
private:
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 0270c086d06b6ad..d86c4eba6a22511 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -808,20 +808,6 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
return TemplateArgument(ctx, value, type, isDefaulted);
}]>;
}
-let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
- def : Property<"value", APValue> {
- let Read = [{ node.getAsStructuralValue() }];
- }
- def : Property<"type", QualType> {
- let Read = [{ node.getStructuralValueType() }];
- }
- def : Property<"isDefaulted", Bool> {
- let Read = [{ node.getIsDefaulted() }];
- }
- def : Creator<[{
- return TemplateArgument(ctx, type, value, isDefaulted);
- }]>;
-}
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
def : Property<"name", TemplateName> {
let Read = [{ node.getAsTemplateOrTemplatePattern() }];
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 2aee6a947141b6c..8f2714e142bbe3e 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -850,7 +850,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
case TemplateArgument::Declaration:
case TemplateArgument::Integral:
case TemplateArgument::NullPtr:
- case TemplateArgument::StructuralValue:
return true;
case TemplateArgument::Type:
@@ -883,7 +882,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
case TemplateArgument::Declaration:
case TemplateArgument::Integral:
case TemplateArgument::NullPtr:
- case TemplateArgument::StructuralValue:
return true;
case TemplateArgument::Type: {
diff --git a/clang/include/clang/AST/TemplateArgumentVisitor.h b/clang/include/clang/AST/TemplateArgumentVisitor.h
index cf0d32201580633..190aa97adf45516 100644
--- a/clang/include/clang/AST/TemplateArgumentVisitor.h
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -37,7 +37,6 @@ class Base {
DISPATCH(Declaration);
DISPATCH(NullPtr);
DISPATCH(Integral);
- DISPATCH(StructuralValue);
DISPATCH(Template);
DISPATCH(TemplateExpansion);
DISPATCH(Expression);
@@ -60,7 +59,6 @@ class Base {
VISIT_METHOD(Declaration);
VISIT_METHOD(NullPtr);
VISIT_METHOD(Integral);
- VISIT_METHOD(StructuralValue);
VISIT_METHOD(Template);
VISIT_METHOD(TemplateExpansion);
VISIT_METHOD(Expression);
diff --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h
index fea2c8ccfee675e..b7cd71f17c9442c 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -50,7 +50,6 @@ template <> struct PointerLikeTypeTraits<clang::Expr *> {
namespace clang {
-class APValue;
class ASTContext;
class Expr;
struct PrintingPolicy;
@@ -81,13 +80,6 @@ class TemplateArgument {
/// that was provided for an integral non-type template parameter.
Integral,
- /// The template argument is a non-type template argument that can't be
- /// represented by the special-case Declaration, NullPtr, or Integral
- /// forms. These values are only ever produced by constant evaluation,
- /// so cannot be dependent.
- /// TODO: merge Declaration, NullPtr and Integral into this?
- StructuralValue,
-
/// The template argument is a template name that was provided for a
/// template template parameter.
Template,
@@ -138,14 +130,6 @@ class TemplateArgument {
};
void *Type;
};
- struct V {
- LLVM_PREFERRED_TYPE(ArgKind)
- unsigned Kind : 31;
- LLVM_PREFERRED_TYPE(bool)
- unsigned IsDefaulted : 1;
- APValue *Value;
- void *Type;
- };
struct A {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
@@ -172,19 +156,11 @@ class TemplateArgument {
union {
struct DA DeclArg;
struct I Integer;
- struct V Value;
struct A Args;
struct TA TemplateArg;
struct TV TypeOrValue;
};
- void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
- void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
- void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
- QualType Type, bool IsDefaulted);
- void initFromStructural(const ASTContext &Ctx, QualType Type,
- const APValue &V, bool IsDefaulted);
-
public:
/// Construct an empty, invalid template argument.
constexpr TemplateArgument() : TypeOrValue({Null, 0, /* IsDefaulted */ 0}) {}
@@ -192,22 +168,25 @@ class TemplateArgument {
/// Construct a template type argument.
TemplateArgument(QualType T, bool isNullPtr = false,
bool IsDefaulted = false) {
- initFromType(T, isNullPtr, IsDefaulted);
+ TypeOrValue.Kind = isNullPtr ? NullPtr : Type;
+ TypeOrValue.IsDefaulted = IsDefaulted;
+ TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
}
- /// Construct a template argument that refers to a (non-dependent)
- /// declaration.
+ /// Construct a template argument that refers to a
+ /// declaration, which is either an external declaration or a
+ /// template declaration.
TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
- initFromDeclaration(D, QT, IsDefaulted);
+ assert(D && "Expected decl");
+ DeclArg.Kind = Declaration;
+ DeclArg.IsDefaulted = IsDefaulted;
+ DeclArg.QT = QT.getAsOpaquePtr();
+ DeclArg.D = D;
}
/// Construct an integral constant template argument. The memory to
/// store the value is allocated with Ctx.
- TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
- QualType Type, bool IsDefaulted = false);
-
- /// Construct a template argument from an arbitrary constant value.
- TemplateArgument(const ASTContext &Ctx, QualType Type, const APValue &Value,
+ TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type,
bool IsDefaulted = false);
/// Construct an integral constant template argument with the same
@@ -318,7 +297,7 @@ class TemplateArgument {
/// Retrieve the type for a type template argument.
QualType getAsType() const {
assert(getKind() == Type && "Unexpected kind");
- return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
+ return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
}
/// Retrieve the declaration for a declaration non-type
@@ -336,7 +315,7 @@ class TemplateArgument {
/// Retrieve the type for null non-type template argument.
QualType getNullPtrType() const {
assert(getKind() == NullPtr && "Unexpected kind");
- return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
+ return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
}
/// Retrieve the template name for a template name argument.
@@ -392,14 +371,6 @@ class TemplateArgument {
/// default template parameter.
bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
- /// Get the value of a StructuralValue.
- const APValue &getAsStructuralValue() const { return *Value.Value; }
-
- /// Get the type of a StructuralValue.
- QualType getStructuralValueType() const {
- return QualType::getFromOpaquePtr(Value.Type);
- }
-
/// If this is a non-type template argument, get its type. Otherwise,
/// returns a null QualType.
QualType getNonTypeTemplateArgumentType() const;
@@ -545,7 +516,6 @@ class TemplateArgumentLoc {
assert(Argument.getKind() == TemplateArgument::NullPtr ||
Argument.getKind() == TemplateArgument::Integral ||
Argument.getKind() == TemplateArgument::Declaration ||
- Argument.getKind() == TemplateArgument::StructuralValue ||
Argument.getKind() == TemplateArgument::Expression);
}
@@ -571,9 +541,13 @@ class TemplateArgumentLoc {
/// - Fetches the full source range of the argument.
SourceRange getSourceRange() const LLVM_READONLY;
- const TemplateArgument &getArgument() const { return Argument; }
+ const TemplateArgument &getArgument() const {
+ return Argument;
+ }
- TemplateArgumentLocInfo getLocInfo() const { return LocInfo; }
+ TemplateArgumentLocInfo getLocInfo() const {
+ return LocInfo;
+ }
TypeSourceInfo *getTypeSourceInfo() const {
if (Argument.getKind() != TemplateArgument::Type)
@@ -601,11 +575,6 @@ class TemplateArgumentLoc {
return LocInfo.getAsExpr();
}
- Expr *getSourceStructuralValueExpression() const {
- assert(Argument.getKind() == TemplateArgument::StructuralValue);
- return LocInfo.getAsExpr();
- }
-
NestedNameSpecifierLoc getTemplateQualifierLoc() const {
if (Argument.getKind() != TemplateArgument::Template &&
Argument.getKind() != TemplateArgument::TemplateExpansion)
@@ -637,7 +606,8 @@ class TemplateArgumentListInfo {
public:
TemplateArgumentListInfo() = default;
- TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
+ TemplateArgumentListInfo(SourceLocation LAngleLoc,
+ SourceLocation RAngleLoc)
: LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
// This can leak if used in an AST node, use ASTTemplateArgumentListInfo
@@ -656,15 +626,21 @@ class TemplateArgumentListInfo {
return Arguments.data();
}
- llvm::ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
+ llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
+ return Arguments;
+ }
const TemplateArgumentLoc &operator[](unsigned I) const {
return Arguments[I];
}
- TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
+ TemplateArgumentLoc &operator[](unsigned I) {
+ return Arguments[I];
+ }
- void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
+ void addArgument(const TemplateArgumentLoc &Loc) {
+ Arguments.push_back(Loc);
+ }
};
/// Represents an explicit template argument list in C++, e.g.,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1c32abb4dcd880..cce58b571a584b3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5161,6 +5161,8 @@ def err_non_type_template_arg_subobject : Error<
"non-type template argument refers to subobject '%0'">;
def err_non_type_template_arg_addr_label_diff : Error<
"template argument / label address difference / what did you expect?">;
+def err_non_type_template_arg_unsupported : Error<
+ "non-type template argument of type %0 is not yet supported">;
def err_template_arg_not_convertible : Error<
"non-type template argument of type %0 cannot be converted to a value "
"of type %1">;
@@ -5212,6 +5214,9 @@ def err_template_arg_not_object_or_func : Error<
"non-type template argument does not refer to an object or function">;
def err_template_arg_not_pointer_to_member_form : Error<
"non-type template argument is not a pointer to member constant">;
+def err_template_arg_member_ptr_base_derived_not_supported : Error<
+ "non-type template argument of pointer-to-member type %1 that refers "
+ "to member %q0 of a different class is not supported yet">;
def err_template_arg_invalid : Error<
"non-type template argument '%0' is invalid">;
def ext_template_arg_extra_parens : ExtWarn<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd11ff73581..d4c33dd65bb96f1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8595,8 +8595,8 @@ class Sema final {
QualType ParamType,
SourceLocation Loc);
ExprResult
- BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
- SourceLocation Loc);
+ BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
+ SourceLocation Loc);
/// Enumeration describing how template parameter lists are compared
/// for equality.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..0fc0831b221aab3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6754,11 +6754,6 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
case TemplateArgument::Integral:
return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
- case TemplateArgument::StructuralValue:
- return TemplateArgument(*this,
- getCanonicalType(Arg.getStructuralValueType()),
- Arg.getAsStructuralValue());
-
case TemplateArgument::Type:
return TemplateArgument(getCanonicalType(Arg.getAsType()),
/*isNullPtr*/ false, Arg.getIsDefaulted());
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 12734d62ed9fb76..b364796073022bd 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -823,17 +823,6 @@ ASTNodeImporter::import(const TemplateArgument &From) {
From.getIsDefaulted());
}
- case TemplateArgument::StructuralValue: {
- ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
- if (!ToTypeOrErr)
- return ToTypeOrErr.takeError();
- Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
- if (!ToValueOrErr)
- return ToValueOrErr.takeError();
- return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
- *ToValueOrErr);
- }
-
case TemplateArgument::Template: {
Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
if (!ToTemplateOrErr)
@@ -3583,8 +3572,6 @@ class IsTypeDeclaredInsideVisitor
case TemplateArgument::NullPtr:
// FIXME: The type is not allowed to be in the function?
return CheckType(Arg.getNullPtrType());
- case TemplateArgument::StructuralValue:
- return CheckType(Arg.getStructuralValueType());
case TemplateArgument::Pack:
for (const auto &PackArg : Arg.getPackAsArray())
if (checkTemplateArgument(PackArg))
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp
index be7a850a2982c73..5103fc86a800513 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -685,9 +685,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
Arg2.getAsExpr());
- case TemplateArgument::StructuralValue:
- return Arg1.structurallyEquals(Arg2);
-
case TemplateArgument::Pack:
return IsStructurallyEquivalent(Context, Arg1.pack_elements(),
Arg2.pack_elements());
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed4..2c3a0afee8cefc2 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -343,10 +343,6 @@ LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args,
LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType()));
continue;
- case TemplateArgument::StructuralValue:
- LV.merge(getLVForValue(Arg.getAsStructuralValue(), computation));
- continue;
-
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
if (TemplateDecl *Template =
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 40b1e086ddd0c61..f78265df0713f55 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4833,23 +4833,9 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
E = cast<CXXStdInitializerListExpr>(E)->getSubExpr();
goto recurse;
- case Expr::SubstNonTypeTemplateParmExprClass: {
- // Mangle a substituted parameter the same way we mangle the template
- // argument.
- auto *SNTTPE = cast<SubstNonTypeTemplateParmExpr>(E);
- if (auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
- // Pull out the constant value and mangle it as a template argument.
- QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
- assert(CE->hasAPValueResult() && "expected the NTTP to have an APValue");
- mangleValueInTemplateArg(ParamType, CE->getAPValueResult(), false,
- /*NeedExactType=*/true);
- break;
- }
- // The remaining cases all happen to be substituted with expressions that
- // mangle the same as a corresponding template argument anyway.
+ case Expr::SubstNonTypeTemplateParmExprClass:
E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement();
goto recurse;
- }
case Expr::UserDefinedLiteralClass:
// We follow g++'s approach of mangling a UDL as a call to the literal
@@ -6078,11 +6064,6 @@ void CXXNameMangler::mangleTemplateArg(TemplateArgument A, bool NeedExactType) {
mangleNullPointer(A.getNullPtrType());
break;
}
- case TemplateArgument::StructuralValue:
- mangleValueInTemplateArg(A.getStructuralValueType(),
- A.getAsStructuralValue(),
- /*TopLevel=*/true, NeedExactType);
- break;
case TemplateArgument::Pack: {
// <template-arg> ::= J <template-arg>* E
Out << 'J';
@@ -6491,20 +6472,7 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
Out << "plcvPcad";
Kind = Offset;
} else {
- // Clang 11 and before mangled an array subject to array-to-pointer decay
- // as if it were the declaration itself.
- bool IsArrayToPointerDecayMangledAsDecl = false;
- if (TopLevel && Ctx.getLangOpts().getClangABICompat() <=
- LangOptions::ClangABI::Ver11) {
- QualType BType = B.getType();
- IsArrayToPointerDecayMangledAsDecl =
- BType->isArrayType() && V.getLValuePath().size() == 1 &&
- V.getLValuePath()[0].getAsArrayIndex() == 0 &&
- Ctx.hasSimilarType(T, Ctx.getDecayedType(BType));
- }
-
- if ((!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) &&
- !IsArrayToPointerDecayMangledAsDecl) {
+ if (!V.getLValuePath().empty() || V.i...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/79302
More information about the cfe-commits
mailing list