Skip to content

Commit 8ba442b

Browse files
committed
Revert "Following up on PR48517, fix handling of template arguments that refer"
Combined with 'da98651 - Revert "DR2064: decltype(E) is only a dependent', this change (5a391d3) caused verifier errors when building Chromium. See https://crbug.com/1168494#c1 for a reproducer. Additionally it reverts changes that were dependent on this one, see below. > Following up on PR48517, fix handling of template arguments that refer > to dependent declarations. > > Treat an id-expression that names a local variable in a templated > function as being instantiation-dependent. > > This addresses a language defect whereby a reference to a dependent > declaration can be formed without any construct being value-dependent. > Fixing that through value-dependence turns out to be problematic, so > instead this patch takes the approach (proposed on the core reflector) > of allowing the use of pointers or references to (but not values of) > dependent declarations inside value-dependent expressions, and instead > treating template arguments as dependent if they evaluate to a constant > involving such dependent declarations. > > This ends up affecting a bunch of OpenMP tests, due to OpenMP > imprecisely handling instantiation-dependent constructs, bailing out > early instead of processing dependent constructs to the extent possible > when handling the template. > > Previously committed as 8c1f2d1, and > reverted because a dependency commit was reverted. This reverts commit 5a391d3. It also restores clang/test/SemaCXX/coroutines.cpp to its state before da98651. Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type." > Previously committed as 9e08e51, and > reverted because a dependency commit was reverted. This incorporates the > following follow-on commits that were also reverted: > > 7e84aa1 by Simon Pilgrim > ed13d8c by me > 95c7b6c by Sam McCall > 430d5d8 by Dave Zarzycki This reverts commit 4b57400. Revert "[msabi] Mangle a template argument referring to array-to-pointer decay" > [msabi] Mangle a template argument referring to array-to-pointer decay > applied to an array the same as the array itself. > > This follows MS ABI, and corrects a regression from the implementation > of generalized non-type template parameters, where we "forgot" how to > mangle this case. This reverts commit 18e093f.
1 parent 4f5f29d commit 8ba442b

File tree

66 files changed

+354
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+354
-885
lines changed

clang-tools-extra/clangd/DumpAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
143143
TEMPLATE_ARGUMENT_KIND(Declaration);
144144
TEMPLATE_ARGUMENT_KIND(Template);
145145
TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
146-
TEMPLATE_ARGUMENT_KIND(UncommonValue);
147146
#undef TEMPLATE_ARGUMENT_KIND
148147
}
149148
llvm_unreachable("Unhandled ArgKind enum");

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ class ExplicitReferenceCollector
10791079
case TemplateArgument::Pack:
10801080
case TemplateArgument::Type:
10811081
case TemplateArgument::Expression:
1082-
case TemplateArgument::UncommonValue:
10831082
break; // Handled by VisitType and VisitExpression.
10841083
};
10851084
return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);

clang-tools-extra/clangd/index/remote/Client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ class IndexClient : public clangd::SymbolIndex {
152152
});
153153
}
154154

155-
llvm::unique_function<bool(llvm::StringRef) const>
156-
indexedFiles() const override {
155+
llvm::unique_function<bool(llvm::StringRef) const> indexedFiles() const {
157156
// FIXME: For now we always return "false" regardless of whether the file
158157
// was indexed or not. A possible implementation could be based on
159158
// the idea that we do not want to send a request at every

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,8 +2818,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
28182818
/// for destruction.
28192819
template <typename T> void addDestruction(T *Ptr) const {
28202820
if (!std::is_trivially_destructible<T>::value) {
2821-
auto DestroyPtr = [](void *V) { ((T*)V)->~T(); };
2822-
AddDeallocation(DestroyPtr, (void*)Ptr);
2821+
auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2822+
AddDeallocation(DestroyPtr, Ptr);
28232823
}
28242824
}
28252825

clang/include/clang/AST/Expr.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,12 @@ class Expr : public ValueStmt {
578578
struct EvalStatus {
579579
/// Whether the evaluated expression has side effects.
580580
/// For example, (f() && 0) can be folded, but it still has side effects.
581-
bool HasSideEffects = false;
581+
bool HasSideEffects;
582582

583583
/// Whether the evaluation hit undefined behavior.
584584
/// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
585585
/// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
586-
bool HasUndefinedBehavior = false;
586+
bool HasUndefinedBehavior;
587587

588588
/// Diag - If this is non-null, it will be filled in with a stack of notes
589589
/// indicating why evaluation failed (or why it failed to produce a constant
@@ -592,7 +592,10 @@ class Expr : public ValueStmt {
592592
/// foldable. If the expression is foldable, but not a constant expression,
593593
/// the notes will describes why it isn't a constant expression. If the
594594
/// expression *is* a constant expression, no notes will be produced.
595-
SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr;
595+
SmallVectorImpl<PartialDiagnosticAt> *Diag;
596+
597+
EvalStatus()
598+
: HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
596599

597600
// hasSideEffects - Return true if the evaluated expression has
598601
// side effects.
@@ -603,11 +606,8 @@ class Expr : public ValueStmt {
603606

604607
/// EvalResult is a struct with detailed info about an evaluated expression.
605608
struct EvalResult : EvalStatus {
606-
/// This is the value the expression can be folded to.
609+
/// Val - This is the value the expression can be folded to.
607610
APValue Val;
608-
/// Indicates whether Val contains a pointer or reference or pointer to
609-
/// member naming a templated entity, and thus the value is dependent.
610-
bool Dependent = false;
611611

612612
// isGlobalLValue - Return true if the evaluated lvalue expression
613613
// is global.

clang/include/clang/AST/PropertiesBase.td

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -758,17 +758,6 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
758758
return TemplateArgument(ctx, value, type);
759759
}]>;
760760
}
761-
let Class = PropertyTypeCase<TemplateArgument, "UncommonValue"> in {
762-
def : Property<"value", APValue> {
763-
let Read = [{ node.getAsUncommonValue() }];
764-
}
765-
def : Property<"type", QualType> {
766-
let Read = [{ node.getUncommonValueType() }];
767-
}
768-
def : Creator<[{
769-
return TemplateArgument(ctx, type, value);
770-
}]>;
771-
}
772761
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
773762
def : Property<"name", TemplateName> {
774763
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: 11 additions & 42 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.
@@ -268,12 +252,6 @@ class TemplateArgument {
268252
/// Whether this template argument is dependent on a template
269253
/// parameter such that its result can change from one instantiation to
270254
/// another.
271-
///
272-
/// It's not always meaningful to ask whether a template argument is
273-
/// dependent before it's been converted to match a template parameter;
274-
/// whether a non-type template argument is dependent depends on the
275-
/// corresponding parameter. For an unconverted template argument, this
276-
/// returns true if the argument *might* be dependent.
277255
bool isDependent() const;
278256

279257
/// Whether this template argument is dependent on a template
@@ -356,16 +334,6 @@ class TemplateArgument {
356334
Integer.Type = T.getAsOpaquePtr();
357335
}
358336

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-
369337
/// If this is a non-type template argument, get its type. Otherwise,
370338
/// returns a null QualType.
371339
QualType getNonTypeTemplateArgumentType() const;
@@ -510,7 +478,6 @@ class TemplateArgumentLoc {
510478
assert(Argument.getKind() == TemplateArgument::NullPtr ||
511479
Argument.getKind() == TemplateArgument::Integral ||
512480
Argument.getKind() == TemplateArgument::Declaration ||
513-
Argument.getKind() == TemplateArgument::UncommonValue ||
514481
Argument.getKind() == TemplateArgument::Expression);
515482
}
516483

@@ -569,11 +536,6 @@ class TemplateArgumentLoc {
569536
return LocInfo.getAsExpr();
570537
}
571538

572-
Expr *getSourceUncommonValueExpression() const {
573-
assert(Argument.getKind() == TemplateArgument::UncommonValue);
574-
return LocInfo.getAsExpr();
575-
}
576-
577539
NestedNameSpecifierLoc getTemplateQualifierLoc() const {
578540
if (Argument.getKind() != TemplateArgument::Template &&
579541
Argument.getKind() != TemplateArgument::TemplateExpansion)
@@ -712,6 +674,13 @@ struct alignas(void *) ASTTemplateKWAndArgsInfo {
712674
void initializeFrom(SourceLocation TemplateKWLoc,
713675
const TemplateArgumentListInfo &List,
714676
TemplateArgumentLoc *OutArgArray);
677+
// FIXME: The parameter Deps is the result populated by this method, the
678+
// caller doesn't need it since it is populated by computeDependence. remove
679+
// it.
680+
void initializeFrom(SourceLocation TemplateKWLoc,
681+
const TemplateArgumentListInfo &List,
682+
TemplateArgumentLoc *OutArgArray,
683+
TemplateArgumentDependence &Deps);
715684
void initializeFrom(SourceLocation TemplateKWLoc);
716685

717686
void copyInto(const TemplateArgumentLoc *ArgArray,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4695,6 +4695,8 @@ def err_non_type_template_arg_subobject : Error<
46954695
"non-type template argument refers to subobject '%0'">;
46964696
def err_non_type_template_arg_addr_label_diff : Error<
46974697
"template argument / label address difference / what did you expect?">;
4698+
def err_non_type_template_arg_unsupported : Error<
4699+
"sorry, non-type template argument of type %0 is not yet supported">;
46984700
def err_template_arg_not_convertible : Error<
46994701
"non-type template argument of type %0 cannot be converted to a value "
47004702
"of type %1">;
@@ -4746,6 +4748,9 @@ def err_template_arg_not_object_or_func : Error<
47464748
"non-type template argument does not refer to an object or function">;
47474749
def err_template_arg_not_pointer_to_member_form : Error<
47484750
"non-type template argument is not a pointer to member constant">;
4751+
def err_template_arg_member_ptr_base_derived_not_supported : Error<
4752+
"sorry, non-type template argument of pointer-to-member type %1 that refers "
4753+
"to member %q0 of a different class is not supported yet">;
47494754
def ext_template_arg_extra_parens : ExtWarn<
47504755
"address non-type template argument cannot be surrounded by parentheses">;
47514756
def warn_cxx98_compat_template_arg_extra_parens : Warning<

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,8 +3465,7 @@ class Sema final {
34653465
llvm::APSInt &Value, CCEKind CCE);
34663466
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
34673467
APValue &Value, CCEKind CCE,
3468-
NamedDecl *Dest = nullptr,
3469-
bool *ValueDependent = nullptr);
3468+
NamedDecl *Dest = nullptr);
34703469

34713470
/// Abstract base class used to perform a contextual implicit
34723471
/// conversion from an expression to any type passing a filter.
@@ -7735,8 +7734,8 @@ class Sema final {
77357734
QualType ParamType,
77367735
SourceLocation Loc);
77377736
ExprResult
7738-
BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
7739-
SourceLocation Loc);
7737+
BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
7738+
SourceLocation Loc);
77407739

77417740
/// Enumeration describing how template parameter lists are compared
77427741
/// for equality.

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/ComputeDependence.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ExprDependence clang::computeDependence(UnaryOperator *E,
6464
if (VD && VD->isTemplated()) {
6565
auto *VarD = dyn_cast<VarDecl>(VD);
6666
if (!VarD || !VarD->hasLocalStorage())
67-
Dep |= ExprDependence::ValueInstantiation;
67+
Dep |= ExprDependence::Value;
6868
}
6969
}
7070
}
@@ -443,21 +443,12 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
443443
if (auto *FirstArg = E->getTemplateArgs()) {
444444
unsigned NumArgs = E->getNumTemplateArgs();
445445
for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)
446-
Deps |= toExprDependence(Arg->getArgument().getDependence() &
447-
~TemplateArgumentDependence::Dependent);
446+
Deps |= toExprDependence(Arg->getArgument().getDependence());
448447
}
449448

450449
auto *Decl = E->getDecl();
451-
auto *Found = E->getFoundDecl();
452450
auto Type = E->getType();
453451

454-
// FIXME: For a ParmVarDecl referenced in a function signature, we don't know
455-
// its dependence yet!
456-
if (!isa<ParmVarDecl>(Decl)) {
457-
if (Decl->getDeclContext()->isDependentContext() ||
458-
(Found && Found->getDeclContext()->isDependentContext()))
459-
Deps |= ExprDependence::Instantiation;
460-
}
461452
if (Decl->isParameterPack())
462453
Deps |= ExprDependence::UnexpandedPack;
463454
Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error;

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 =

0 commit comments

Comments
 (0)