Skip to content

Commit 2080232

Browse files
committed
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
This reverts commit 9e08e51. This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
1 parent ab7a60e commit 2080232

36 files changed

+188
-621
lines changed

clang/include/clang/AST/PropertiesBase.td

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class CountPropertyType<string typeName = ""> : PropertyType<typeName> {
7272

7373
def APInt : PropertyType<"llvm::APInt"> { let PassByReference = 1; }
7474
def APSInt : PropertyType<"llvm::APSInt"> { let PassByReference = 1; }
75-
def APValue : PropertyType { let PassByReference = 1; }
7675
def ArraySizeModifier : EnumPropertyType<"ArrayType::ArraySizeModifier">;
7776
def AttrKind : EnumPropertyType<"attr::Kind">;
7877
def AutoTypeKeyword : EnumPropertyType;
@@ -451,17 +450,6 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
451450
return TemplateArgument(ctx, value, type);
452451
}]>;
453452
}
454-
let Class = PropertyTypeCase<TemplateArgument, "UncommonValue"> in {
455-
def : Property<"value", APValue> {
456-
let Read = [{ node.getAsUncommonValue() }];
457-
}
458-
def : Property<"type", QualType> {
459-
let Read = [{ node.getUncommonValueType() }];
460-
}
461-
def : Creator<[{
462-
return TemplateArgument(ctx, type, value);
463-
}]>;
464-
}
465453
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
466454
def : Property<"name", TemplateName> {
467455
let Read = [{ node.getAsTemplateOrTemplatePattern() }];

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
768768
case TemplateArgument::Declaration:
769769
case TemplateArgument::Integral:
770770
case TemplateArgument::NullPtr:
771-
case TemplateArgument::UncommonValue:
772771
return true;
773772

774773
case TemplateArgument::Type:
@@ -802,7 +801,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
802801
case TemplateArgument::Declaration:
803802
case TemplateArgument::Integral:
804803
case TemplateArgument::NullPtr:
805-
case TemplateArgument::UncommonValue:
806804
return true;
807805

808806
case TemplateArgument::Type: {

clang/include/clang/AST/TemplateArgumentVisitor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Base {
3737
DISPATCH(Declaration);
3838
DISPATCH(NullPtr);
3939
DISPATCH(Integral);
40-
DISPATCH(UncommonValue);
4140
DISPATCH(Template);
4241
DISPATCH(TemplateExpansion);
4342
DISPATCH(Expression);
@@ -60,7 +59,6 @@ class Base {
6059
VISIT_METHOD(Declaration);
6160
VISIT_METHOD(NullPtr);
6261
VISIT_METHOD(Integral);
63-
VISIT_METHOD(UncommonValue);
6462
VISIT_METHOD(Template);
6563
VISIT_METHOD(TemplateExpansion);
6664
VISIT_METHOD(Expression);

clang/include/clang/AST/TemplateBase.h

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ template <> struct PointerLikeTypeTraits<clang::Expr *> {
5151

5252
namespace clang {
5353

54-
class APValue;
5554
class ASTContext;
5655
class DiagnosticBuilder;
5756
class Expr;
@@ -83,12 +82,6 @@ class TemplateArgument {
8382
/// that was provided for an integral non-type template parameter.
8483
Integral,
8584

86-
/// The template argument is a non-type template argument that can't be
87-
/// represented by the special-case Declaration, NullPtr, or Integral
88-
/// forms. These values are only ever produced by constant evaluation,
89-
/// so cannot be dependent.
90-
UncommonValue,
91-
9285
/// The template argument is a template name that was provided for a
9386
/// template template parameter.
9487
Template,
@@ -132,11 +125,6 @@ class TemplateArgument {
132125
};
133126
void *Type;
134127
};
135-
struct V {
136-
unsigned Kind;
137-
const APValue *Value;
138-
void *Type;
139-
};
140128
struct A {
141129
unsigned Kind;
142130
unsigned NumArgs;
@@ -154,7 +142,6 @@ class TemplateArgument {
154142
union {
155143
struct DA DeclArg;
156144
struct I Integer;
157-
struct V Value;
158145
struct A Args;
159146
struct TA TemplateArg;
160147
struct TV TypeOrValue;
@@ -170,8 +157,9 @@ class TemplateArgument {
170157
TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
171158
}
172159

173-
/// Construct a template argument that refers to a (non-dependent)
174-
/// declaration.
160+
/// Construct a template argument that refers to a
161+
/// declaration, which is either an external declaration or a
162+
/// template declaration.
175163
TemplateArgument(ValueDecl *D, QualType QT) {
176164
assert(D && "Expected decl");
177165
DeclArg.Kind = Declaration;
@@ -181,11 +169,7 @@ class TemplateArgument {
181169

182170
/// Construct an integral constant template argument. The memory to
183171
/// store the value is allocated with Ctx.
184-
TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
185-
QualType Type);
186-
187-
/// Construct a template argument from an arbitrary constant value.
188-
TemplateArgument(const ASTContext &Ctx, QualType Type, const APValue &Value);
172+
TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type);
189173

190174
/// Construct an integral constant template argument with the same
191175
/// value as Other but a different type.
@@ -356,16 +340,6 @@ class TemplateArgument {
356340
Integer.Type = T.getAsOpaquePtr();
357341
}
358342

359-
/// Get the value of an UncommonValue.
360-
const APValue &getAsUncommonValue() const {
361-
return *Value.Value;
362-
}
363-
364-
/// Get the type of an UncommonValue.
365-
QualType getUncommonValueType() const {
366-
return QualType::getFromOpaquePtr(Value.Type);
367-
}
368-
369343
/// If this is a non-type template argument, get its type. Otherwise,
370344
/// returns a null QualType.
371345
QualType getNonTypeTemplateArgumentType() const;
@@ -510,7 +484,6 @@ class TemplateArgumentLoc {
510484
assert(Argument.getKind() == TemplateArgument::NullPtr ||
511485
Argument.getKind() == TemplateArgument::Integral ||
512486
Argument.getKind() == TemplateArgument::Declaration ||
513-
Argument.getKind() == TemplateArgument::UncommonValue ||
514487
Argument.getKind() == TemplateArgument::Expression);
515488
}
516489

@@ -569,11 +542,6 @@ class TemplateArgumentLoc {
569542
return LocInfo.getAsExpr();
570543
}
571544

572-
Expr *getSourceUncommonValueExpression() const {
573-
assert(Argument.getKind() == TemplateArgument::UncommonValue);
574-
return LocInfo.getAsExpr();
575-
}
576-
577545
NestedNameSpecifierLoc getTemplateQualifierLoc() const {
578546
if (Argument.getKind() != TemplateArgument::Template &&
579547
Argument.getKind() != TemplateArgument::TemplateExpansion)

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,6 +4656,8 @@ def err_non_type_template_arg_subobject : Error<
46564656
"non-type template argument refers to subobject '%0'">;
46574657
def err_non_type_template_arg_addr_label_diff : Error<
46584658
"template argument / label address difference / what did you expect?">;
4659+
def err_non_type_template_arg_unsupported : Error<
4660+
"sorry, non-type template argument of type %0 is not yet supported">;
46594661
def err_template_arg_not_convertible : Error<
46604662
"non-type template argument of type %0 cannot be converted to a value "
46614663
"of type %1">;
@@ -4707,6 +4709,9 @@ def err_template_arg_not_object_or_func : Error<
47074709
"non-type template argument does not refer to an object or function">;
47084710
def err_template_arg_not_pointer_to_member_form : Error<
47094711
"non-type template argument is not a pointer to member constant">;
4712+
def err_template_arg_member_ptr_base_derived_not_supported : Error<
4713+
"sorry, non-type template argument of pointer-to-member type %1 that refers "
4714+
"to member %q0 of a different class is not supported yet">;
47104715
def ext_template_arg_extra_parens : ExtWarn<
47114716
"address non-type template argument cannot be surrounded by parentheses">;
47124717
def warn_cxx98_compat_template_arg_extra_parens : Warning<

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7623,8 +7623,8 @@ class Sema final {
76237623
QualType ParamType,
76247624
SourceLocation Loc);
76257625
ExprResult
7626-
BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
7627-
SourceLocation Loc);
7626+
BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
7627+
SourceLocation Loc);
76287628

76297629
/// Enumeration describing how template parameter lists are compared
76307630
/// for equality.

clang/include/clang/Serialization/ASTRecordWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ class ASTRecordWriter
166166

167167
/// Emit an APvalue.
168168
void AddAPValue(const APValue &Value);
169-
void writeAPValue(const APValue &Value) { AddAPValue(Value); }
170169

171170
/// Emit a reference to an identifier.
172171
void AddIdentifierRef(const IdentifierInfo *II) {

clang/lib/AST/ASTContext.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,11 +5941,6 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
59415941
case TemplateArgument::Integral:
59425942
return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
59435943

5944-
case TemplateArgument::UncommonValue:
5945-
return TemplateArgument(*this,
5946-
getCanonicalType(Arg.getUncommonValueType()),
5947-
Arg.getAsUncommonValue());
5948-
59495944
case TemplateArgument::Type:
59505945
return TemplateArgument(getCanonicalType(Arg.getAsType()));
59515946

clang/lib/AST/ASTImporter.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -808,17 +808,6 @@ ASTNodeImporter::import(const TemplateArgument &From) {
808808
return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true);
809809
}
810810

811-
case TemplateArgument::UncommonValue: {
812-
ExpectedType ToTypeOrErr = import(From.getUncommonValueType());
813-
if (!ToTypeOrErr)
814-
return ToTypeOrErr.takeError();
815-
Expected<APValue> ToValueOrErr = import(From.getAsUncommonValue());
816-
if (!ToValueOrErr)
817-
return ToValueOrErr.takeError();
818-
return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
819-
*ToValueOrErr);
820-
}
821-
822811
case TemplateArgument::Template: {
823812
Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
824813
if (!ToTemplateOrErr)

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
565565
return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
566566
Arg2.getAsExpr());
567567

568-
case TemplateArgument::UncommonValue:
569-
// FIXME: Do we need to customize the comparison?
570-
return Arg1.structurallyEquals(Arg2);
571-
572568
case TemplateArgument::Pack:
573569
if (Arg1.pack_size() != Arg2.pack_size())
574570
return false;

clang/lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,6 @@ LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args,
342342
LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType()));
343343
continue;
344344

345-
case TemplateArgument::UncommonValue:
346-
LV.merge(getLVForValue(Arg.getAsUncommonValue(), computation));
347-
continue;
348-
349345
case TemplateArgument::Template:
350346
case TemplateArgument::TemplateExpansion:
351347
if (TemplateDecl *Template =

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,28 +4079,10 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) {
40794079
mangleExpression(cast<CXXStdInitializerListExpr>(E)->getSubExpr(), Arity);
40804080
break;
40814081

4082-
case Expr::SubstNonTypeTemplateParmExprClass: {
4083-
// Mangle a substituted parameter the same way we mangle the template
4084-
// argument.
4085-
// As proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/111.
4086-
auto *SNTTPE = cast<SubstNonTypeTemplateParmExpr>(E);
4087-
if (auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
4088-
// Pull out the constant value and mangle it as a template argument.
4089-
QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
4090-
if (CE->hasAPValueResult())
4091-
mangleValueInTemplateArg(ParamType, CE->getResultAsAPValue(), false,
4092-
/*NeedExactType=*/true);
4093-
else
4094-
mangleValueInTemplateArg(ParamType, CE->getAPValueResult(), false,
4095-
/*NeedExactType=*/true);
4096-
} else {
4097-
// The remaining cases all happen to be substituted with expressions that
4098-
// mangle the same as a corresponding template argument anyway.
4099-
mangleExpression(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(),
4100-
Arity);
4101-
}
4082+
case Expr::SubstNonTypeTemplateParmExprClass:
4083+
mangleExpression(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(),
4084+
Arity);
41024085
break;
4103-
}
41044086

41054087
case Expr::UserDefinedLiteralClass:
41064088
// We follow g++'s approach of mangling a UDL as a call to the literal
@@ -5057,10 +5039,6 @@ void CXXNameMangler::mangleTemplateArg(TemplateArgument A, bool NeedExactType) {
50575039
mangleNullPointer(A.getNullPtrType());
50585040
break;
50595041
}
5060-
case TemplateArgument::UncommonValue:
5061-
mangleValueInTemplateArg(A.getUncommonValueType(), A.getAsUncommonValue(),
5062-
/*TopLevel=*/true, NeedExactType);
5063-
break;
50645042
case TemplateArgument::Pack: {
50655043
// <template-arg> ::= J <template-arg>* E
50665044
Out << 'J';
@@ -5395,20 +5373,7 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
53955373
Out << "plcvPcad";
53965374
Kind = Offset;
53975375
} else {
5398-
// Clang 11 and before mangled an array subject to array-to-pointer decay
5399-
// as if it were the declaration itself.
5400-
bool IsArrayToPointerDecayMangledAsDecl = false;
5401-
if (TopLevel && Ctx.getLangOpts().getClangABICompat() <=
5402-
LangOptions::ClangABI::Ver11) {
5403-
QualType BType = B.getType();
5404-
IsArrayToPointerDecayMangledAsDecl =
5405-
BType->isArrayType() && V.getLValuePath().size() == 1 &&
5406-
V.getLValuePath()[0].getAsArrayIndex() == 0 &&
5407-
Ctx.hasSimilarType(T, Ctx.getDecayedType(BType));
5408-
}
5409-
5410-
if ((!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) &&
5411-
!IsArrayToPointerDecayMangledAsDecl) {
5376+
if (!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) {
54125377
NotPrimaryExpr();
54135378
// A final conversion to the template parameter's type is usually
54145379
// folded into the 'so' mangling, but we can't do that for 'void*'

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,17 +1575,6 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
15751575
cast<NonTypeTemplateParmDecl>(Parm), T);
15761576
break;
15771577
}
1578-
case TemplateArgument::UncommonValue:
1579-
Out << "$";
1580-
if (cast<NonTypeTemplateParmDecl>(Parm)
1581-
->getType()
1582-
->getContainedDeducedType()) {
1583-
Out << "M";
1584-
mangleType(TA.getNonTypeTemplateArgumentType(), SourceRange(), QMM_Drop);
1585-
}
1586-
mangleTemplateArgValue(TA.getUncommonValueType(), TA.getAsUncommonValue(),
1587-
/*WithScalarType=*/false);
1588-
break;
15891578
case TemplateArgument::Expression:
15901579
mangleExpression(TA.getAsExpr(), cast<NonTypeTemplateParmDecl>(Parm));
15911580
break;

clang/lib/AST/ODRHash.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ void ODRHash::AddTemplateArgument(TemplateArgument TA) {
169169
break;
170170
case TemplateArgument::NullPtr:
171171
case TemplateArgument::Integral:
172-
case TemplateArgument::UncommonValue:
173-
// FIXME: Include a representation of these arguments.
174172
break;
175173
case TemplateArgument::Template:
176174
case TemplateArgument::TemplateExpansion:

clang/lib/AST/StmtProfile.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,12 +2208,6 @@ void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
22082208
Arg.getAsIntegral().Profile(ID);
22092209
break;
22102210

2211-
case TemplateArgument::UncommonValue:
2212-
VisitType(Arg.getUncommonValueType());
2213-
// FIXME: Do we need to recursively decompose this ourselves?
2214-
Arg.getAsUncommonValue().Profile(ID);
2215-
break;
2216-
22172211
case TemplateArgument::Expression:
22182212
Visit(Arg.getAsExpr());
22192213
break;

0 commit comments

Comments
 (0)