2017-11-21 23:26:08 +00:00
|
|
|
//===- TemplateBase.cpp - Common template AST class implementation --------===//
|
2009-10-29 07:48:15 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-10-29 07:48:15 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements common classes used throughout C++ template
|
|
|
|
// representations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/TemplateBase.h"
|
2010-12-20 16:52:59 +00:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include "clang/AST/Decl.h"
|
2009-10-29 07:48:15 +00:00
|
|
|
#include "clang/AST/DeclBase.h"
|
2009-11-23 12:52:47 +00:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2020-03-16 13:43:40 +01:00
|
|
|
#include "clang/AST/DependenceFlags.h"
|
2009-10-29 07:48:15 +00:00
|
|
|
#include "clang/AST/Expr.h"
|
2011-01-03 17:17:50 +00:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
|
|
|
#include "clang/AST/TemplateName.h"
|
2011-02-19 00:21:00 +00:00
|
|
|
#include "clang/AST/Type.h"
|
2009-10-29 08:12:44 +00:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2010-05-08 17:41:32 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "llvm/ADT/APSInt.h"
|
2010-12-20 16:52:59 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include "llvm/ADT/None.h"
|
2012-02-04 13:45:25 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-01 17:12:56 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-11-21 23:26:08 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
2009-10-29 07:48:15 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2018-05-09 01:00:01 +00:00
|
|
|
/// Print a template integral argument value.
|
2011-02-19 00:21:00 +00:00
|
|
|
///
|
|
|
|
/// \param TemplArg the TemplateArgument instance to print.
|
|
|
|
///
|
|
|
|
/// \param Out the raw_ostream instance to use for printing.
|
2014-12-13 04:31:07 +00:00
|
|
|
///
|
|
|
|
/// \param Policy the printing policy for EnumConstantDecl printing.
|
2021-05-12 17:28:41 +00:00
|
|
|
///
|
|
|
|
/// \param IncludeType If set, ensure that the type of the expression printed
|
|
|
|
/// matches the type of the template argument.
|
|
|
|
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
|
|
|
|
const PrintingPolicy &Policy, bool IncludeType) {
|
2017-11-21 23:26:08 +00:00
|
|
|
const Type *T = TemplArg.getIntegralType().getTypePtr();
|
2012-06-07 15:09:51 +00:00
|
|
|
const llvm::APSInt &Val = TemplArg.getAsIntegral();
|
2011-02-19 00:21:00 +00:00
|
|
|
|
2014-12-13 04:38:19 +00:00
|
|
|
if (const EnumType *ET = T->getAs<EnumType>()) {
|
2014-12-13 04:31:07 +00:00
|
|
|
for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
|
2015-01-09 00:58:16 +00:00
|
|
|
// In Sema::CheckTemplateArugment, enum template arguments value are
|
|
|
|
// extended to the size of the integer underlying the enum type. This
|
|
|
|
// may create a size difference between the enum value and template
|
|
|
|
// argument value, requiring isSameValue here instead of operator==.
|
|
|
|
if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
|
2014-12-13 04:31:07 +00:00
|
|
|
ECD->printQualifiedName(Out, Policy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 17:28:41 +00:00
|
|
|
if (Policy.MSVCFormatting)
|
|
|
|
IncludeType = false;
|
|
|
|
|
|
|
|
if (T->isBooleanType()) {
|
|
|
|
if (!Policy.MSVCFormatting)
|
|
|
|
Out << (Val.getBoolValue() ? "true" : "false");
|
|
|
|
else
|
|
|
|
Out << Val;
|
2011-02-19 00:21:00 +00:00
|
|
|
} else if (T->isCharType()) {
|
2021-05-12 17:28:41 +00:00
|
|
|
if (IncludeType) {
|
|
|
|
if (T->isSpecificBuiltinType(BuiltinType::SChar))
|
|
|
|
Out << "(signed char)";
|
|
|
|
else if (T->isSpecificBuiltinType(BuiltinType::UChar))
|
|
|
|
Out << "(unsigned char)";
|
|
|
|
}
|
|
|
|
CharacterLiteral::print(Val.getZExtValue(), CharacterLiteral::Ascii, Out);
|
|
|
|
} else if (T->isAnyCharacterType() && !Policy.MSVCFormatting) {
|
|
|
|
CharacterLiteral::CharacterKind Kind;
|
|
|
|
if (T->isWideCharType())
|
|
|
|
Kind = CharacterLiteral::Wide;
|
|
|
|
else if (T->isChar8Type())
|
|
|
|
Kind = CharacterLiteral::UTF8;
|
|
|
|
else if (T->isChar16Type())
|
|
|
|
Kind = CharacterLiteral::UTF16;
|
|
|
|
else if (T->isChar32Type())
|
|
|
|
Kind = CharacterLiteral::UTF32;
|
|
|
|
else
|
|
|
|
Kind = CharacterLiteral::Ascii;
|
|
|
|
CharacterLiteral::print(Val.getExtValue(), Kind, Out);
|
|
|
|
} else if (IncludeType) {
|
|
|
|
if (const auto *BT = T->getAs<BuiltinType>()) {
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
Out << Val << "ULL";
|
|
|
|
break;
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
Out << Val << "LL";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
Out << Val << "UL";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Long:
|
|
|
|
Out << Val << "L";
|
|
|
|
break;
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
Out << Val << "U";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Int:
|
|
|
|
Out << Val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
|
|
|
|
<< Val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
|
|
|
|
<< Val;
|
|
|
|
} else
|
2012-06-07 15:09:51 +00:00
|
|
|
Out << Val;
|
2011-02-19 00:21:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 18:47:27 +00:00
|
|
|
static unsigned getArrayDepth(QualType type) {
|
|
|
|
unsigned count = 0;
|
|
|
|
while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
|
|
|
|
count++;
|
|
|
|
type = arrayType->getElementType();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType) {
|
|
|
|
// Generally, if the parameter type is a pointer, we must be taking the
|
|
|
|
// address of something and need a &. However, if the argument is an array,
|
|
|
|
// this could be implicit via array-to-pointer decay.
|
|
|
|
if (!paramType->isPointerType())
|
|
|
|
return paramType->isMemberPointerType();
|
|
|
|
if (argType->isArrayType())
|
|
|
|
return getArrayDepth(argType) == getArrayDepth(paramType->getPointeeType());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-29 07:48:15 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateArgument Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
|
|
|
|
QualType Type) {
|
2013-08-21 23:05:56 +00:00
|
|
|
Integer.Kind = Integral;
|
2012-06-07 15:09:51 +00:00
|
|
|
// Copy the APSInt value into our decomposed form.
|
|
|
|
Integer.BitWidth = Value.getBitWidth();
|
|
|
|
Integer.IsUnsigned = Value.isUnsigned();
|
|
|
|
// If the value is large, we have to get additional memory from the ASTContext
|
2012-06-07 15:54:03 +00:00
|
|
|
unsigned NumWords = Value.getNumWords();
|
|
|
|
if (NumWords > 1) {
|
|
|
|
void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
|
|
|
|
std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
|
2012-06-07 15:09:51 +00:00
|
|
|
Integer.pVal = static_cast<uint64_t *>(Mem);
|
|
|
|
} else {
|
|
|
|
Integer.VAL = Value.getZExtValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer.Type = Type.getAsOpaquePtr();
|
|
|
|
}
|
|
|
|
|
2015-08-05 09:40:22 +00:00
|
|
|
TemplateArgument
|
|
|
|
TemplateArgument::CreatePackCopy(ASTContext &Context,
|
|
|
|
ArrayRef<TemplateArgument> Args) {
|
|
|
|
if (Args.empty())
|
2012-09-26 02:36:12 +00:00
|
|
|
return getEmptyPack();
|
2015-08-05 09:40:22 +00:00
|
|
|
|
|
|
|
return TemplateArgument(Args.copy(Context));
|
2011-01-11 23:09:57 +00:00
|
|
|
}
|
|
|
|
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
TemplateArgumentDependence TemplateArgument::getDependence() const {
|
|
|
|
auto Deps = TemplateArgumentDependence::None;
|
2010-12-15 01:34:56 +00:00
|
|
|
switch (getKind()) {
|
|
|
|
case Null:
|
2011-09-23 05:06:16 +00:00
|
|
|
llvm_unreachable("Should not have a NULL template argument");
|
2010-12-15 01:34:56 +00:00
|
|
|
|
|
|
|
case Type:
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
Deps = toTemplateArgumentDependence(getAsType()->getDependence());
|
|
|
|
if (isa<PackExpansionType>(getAsType()))
|
|
|
|
Deps |= TemplateArgumentDependence::Dependent;
|
|
|
|
return Deps;
|
2010-12-15 01:34:56 +00:00
|
|
|
|
|
|
|
case Template:
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return toTemplateArgumentDependence(getAsTemplate().getDependence());
|
2011-01-05 18:58:31 +00:00
|
|
|
|
|
|
|
case TemplateExpansion:
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return TemplateArgumentDependence::Dependent |
|
|
|
|
TemplateArgumentDependence::Instantiation;
|
2011-01-05 18:58:31 +00:00
|
|
|
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
case Declaration: {
|
|
|
|
auto *DC = dyn_cast<DeclContext>(getAsDecl());
|
|
|
|
if (!DC)
|
|
|
|
DC = getAsDecl()->getDeclContext();
|
|
|
|
if (DC->isDependentContext())
|
|
|
|
Deps = TemplateArgumentDependence::Dependent |
|
|
|
|
TemplateArgumentDependence::Instantiation;
|
|
|
|
return Deps;
|
|
|
|
}
|
|
|
|
|
2012-09-26 02:36:12 +00:00
|
|
|
case NullPtr:
|
2010-12-15 01:34:56 +00:00
|
|
|
case Integral:
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return TemplateArgumentDependence::None;
|
2010-12-15 01:34:56 +00:00
|
|
|
|
|
|
|
case Expression:
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
Deps = toTemplateArgumentDependence(getAsExpr()->getDependence());
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
if (isa<PackExpansionExpr>(getAsExpr()))
|
|
|
|
Deps |= TemplateArgumentDependence::Dependent |
|
|
|
|
TemplateArgumentDependence::Instantiation;
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return Deps;
|
2010-12-15 01:34:56 +00:00
|
|
|
|
|
|
|
case Pack:
|
2014-07-15 21:32:31 +00:00
|
|
|
for (const auto &P : pack_elements())
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
Deps |= P.getDependence();
|
|
|
|
return Deps;
|
2010-12-15 01:34:56 +00:00
|
|
|
}
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
llvm_unreachable("unhandled ArgKind");
|
|
|
|
}
|
2010-12-15 01:34:56 +00:00
|
|
|
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
bool TemplateArgument::isDependent() const {
|
|
|
|
return getDependence() & TemplateArgumentDependence::Dependent;
|
2010-12-15 01:34:56 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 01:22:09 +00:00
|
|
|
bool TemplateArgument::isInstantiationDependent() const {
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return getDependence() & TemplateArgumentDependence::Instantiation;
|
2011-07-01 01:22:09 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 22:05:00 +00:00
|
|
|
bool TemplateArgument::isPackExpansion() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
case Null:
|
|
|
|
case Declaration:
|
|
|
|
case Integral:
|
2018-07-30 19:24:48 +00:00
|
|
|
case Pack:
|
2011-01-05 18:58:31 +00:00
|
|
|
case Template:
|
2012-09-26 02:36:12 +00:00
|
|
|
case NullPtr:
|
2010-12-20 22:05:00 +00:00
|
|
|
return false;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2011-01-05 18:58:31 +00:00
|
|
|
case TemplateExpansion:
|
|
|
|
return true;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 22:05:00 +00:00
|
|
|
case Type:
|
2011-01-03 17:17:50 +00:00
|
|
|
return isa<PackExpansionType>(getAsType());
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 22:05:00 +00:00
|
|
|
case Expression:
|
2011-01-03 17:17:50 +00:00
|
|
|
return isa<PackExpansionExpr>(getAsExpr());
|
2010-12-20 22:05:00 +00:00
|
|
|
}
|
2012-01-20 21:50:17 +00:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
2010-12-20 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-13 22:49:22 +00:00
|
|
|
bool TemplateArgument::containsUnexpandedParameterPack() const {
|
[AST] Refactor propagation of dependency bits. NFC
Summary:
This changes introduces an enum to represent dependencies as a bitmask
and extract common patterns from code that computes dependency bits into
helper functions.
Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein
Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71920
2020-03-02 16:07:09 +01:00
|
|
|
return getDependence() & TemplateArgumentDependence::UnexpandedPack;
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-13 22:49:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-20 22:23:23 +00:00
|
|
|
Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
|
2013-08-21 23:05:56 +00:00
|
|
|
assert(getKind() == TemplateExpansion);
|
2011-01-14 23:41:42 +00:00
|
|
|
if (TemplateArg.NumExpansions)
|
|
|
|
return TemplateArg.NumExpansions - 1;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
|
|
|
return None;
|
2011-01-14 23:41:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 01:30:39 +00:00
|
|
|
QualType TemplateArgument::getNonTypeTemplateArgumentType() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
case TemplateArgument::Template:
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
return getIntegralType();
|
|
|
|
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
return getAsExpr()->getType();
|
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
return getParamTypeForDecl();
|
|
|
|
|
|
|
|
case TemplateArgument::NullPtr:
|
|
|
|
return getNullPtrType();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
|
|
|
}
|
|
|
|
|
2009-10-29 07:48:15 +00:00
|
|
|
void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
|
2011-01-12 09:06:06 +00:00
|
|
|
const ASTContext &Context) const {
|
2013-08-21 23:05:56 +00:00
|
|
|
ID.AddInteger(getKind());
|
|
|
|
switch (getKind()) {
|
2009-10-29 07:48:15 +00:00
|
|
|
case Null:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type:
|
|
|
|
getAsType().Profile(ID);
|
|
|
|
break;
|
|
|
|
|
2013-08-21 23:05:56 +00:00
|
|
|
case NullPtr:
|
|
|
|
getNullPtrType().Profile(ID);
|
|
|
|
break;
|
|
|
|
|
2009-10-29 07:48:15 +00:00
|
|
|
case Declaration:
|
2020-11-14 17:37:25 -08:00
|
|
|
getParamTypeForDecl().Profile(ID);
|
2020-10-11 20:14:00 -07:00
|
|
|
ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
|
2009-10-29 07:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-11 01:00:40 +00:00
|
|
|
case Template:
|
2011-01-05 18:58:31 +00:00
|
|
|
case TemplateExpansion: {
|
|
|
|
TemplateName Template = getAsTemplateOrTemplatePattern();
|
2009-11-23 12:52:47 +00:00
|
|
|
if (TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast_or_null<TemplateTemplateParmDecl>(
|
2011-01-05 18:58:31 +00:00
|
|
|
Template.getAsTemplateDecl())) {
|
2009-11-23 12:52:47 +00:00
|
|
|
ID.AddBoolean(true);
|
|
|
|
ID.AddInteger(TTP->getDepth());
|
|
|
|
ID.AddInteger(TTP->getPosition());
|
2011-01-05 17:40:24 +00:00
|
|
|
ID.AddBoolean(TTP->isParameterPack());
|
2009-11-23 12:52:47 +00:00
|
|
|
} else {
|
|
|
|
ID.AddBoolean(false);
|
2011-01-05 18:58:31 +00:00
|
|
|
ID.AddPointer(Context.getCanonicalTemplateName(Template)
|
|
|
|
.getAsVoidPointer());
|
2009-11-23 12:52:47 +00:00
|
|
|
}
|
2009-11-11 01:00:40 +00:00
|
|
|
break;
|
2011-01-05 18:58:31 +00:00
|
|
|
}
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2009-10-29 07:48:15 +00:00
|
|
|
case Integral:
|
2020-11-06 18:14:41 -08:00
|
|
|
getAsIntegral().Profile(ID);
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
getIntegralType().Profile(ID);
|
2009-10-29 07:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Expression:
|
|
|
|
getAsExpr()->Profile(ID, Context, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Pack:
|
|
|
|
ID.AddInteger(Args.NumArgs);
|
|
|
|
for (unsigned I = 0; I != Args.NumArgs; ++I)
|
|
|
|
Args.Args[I].Profile(ID, Context);
|
|
|
|
}
|
|
|
|
}
|
2009-10-29 08:12:44 +00:00
|
|
|
|
2010-06-11 00:33:02 +00:00
|
|
|
bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const {
|
|
|
|
if (getKind() != Other.getKind()) return false;
|
|
|
|
|
|
|
|
switch (getKind()) {
|
|
|
|
case Null:
|
|
|
|
case Type:
|
2018-07-30 19:24:48 +00:00
|
|
|
case Expression:
|
2012-09-26 02:36:12 +00:00
|
|
|
case NullPtr:
|
2013-08-21 23:05:56 +00:00
|
|
|
return TypeOrValue.V == Other.TypeOrValue.V;
|
2010-06-11 00:33:02 +00:00
|
|
|
|
2020-11-11 19:05:32 -08:00
|
|
|
case Template:
|
|
|
|
case TemplateExpansion:
|
|
|
|
return TemplateArg.Name == Other.TemplateArg.Name &&
|
|
|
|
TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
|
|
|
|
|
2012-09-26 02:36:12 +00:00
|
|
|
case Declaration:
|
2020-10-11 20:14:00 -07:00
|
|
|
return getAsDecl() == Other.getAsDecl();
|
2012-09-26 02:36:12 +00:00
|
|
|
|
2010-06-11 00:33:02 +00:00
|
|
|
case Integral:
|
|
|
|
return getIntegralType() == Other.getIntegralType() &&
|
2012-06-07 15:09:51 +00:00
|
|
|
getAsIntegral() == Other.getAsIntegral();
|
2010-06-11 00:33:02 +00:00
|
|
|
|
|
|
|
case Pack:
|
|
|
|
if (Args.NumArgs != Other.Args.NumArgs) return false;
|
|
|
|
for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
|
|
|
|
if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 21:50:17 +00:00
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
2010-06-11 00:33:02 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 21:19:48 +00:00
|
|
|
TemplateArgument TemplateArgument::getPackExpansionPattern() const {
|
|
|
|
assert(isPackExpansion());
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-22 21:19:48 +00:00
|
|
|
switch (getKind()) {
|
2011-01-05 17:40:24 +00:00
|
|
|
case Type:
|
2019-10-07 13:58:05 +00:00
|
|
|
return getAsType()->castAs<PackExpansionType>()->getPattern();
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2011-01-05 17:40:24 +00:00
|
|
|
case Expression:
|
|
|
|
return cast<PackExpansionExpr>(getAsExpr())->getPattern();
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2011-01-05 18:58:31 +00:00
|
|
|
case TemplateExpansion:
|
2011-01-14 23:41:42 +00:00
|
|
|
return TemplateArgument(getAsTemplateOrTemplatePattern());
|
2012-09-26 02:36:12 +00:00
|
|
|
|
2011-01-05 17:40:24 +00:00
|
|
|
case Declaration:
|
|
|
|
case Integral:
|
|
|
|
case Pack:
|
|
|
|
case Null:
|
2011-01-05 18:58:31 +00:00
|
|
|
case Template:
|
2012-09-26 02:36:12 +00:00
|
|
|
case NullPtr:
|
2011-01-05 17:40:24 +00:00
|
|
|
return TemplateArgument();
|
2010-12-22 21:19:48 +00:00
|
|
|
}
|
2012-01-20 21:50:17 +00:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
2010-12-22 21:19:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 17:28:41 +00:00
|
|
|
void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
|
|
|
|
bool IncludeType) const {
|
|
|
|
|
2010-12-20 16:52:59 +00:00
|
|
|
switch (getKind()) {
|
|
|
|
case Null:
|
2014-04-02 05:58:29 +00:00
|
|
|
Out << "(no value)";
|
2010-12-20 16:52:59 +00:00
|
|
|
break;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 16:52:59 +00:00
|
|
|
case Type: {
|
2011-06-17 22:11:49 +00:00
|
|
|
PrintingPolicy SubPolicy(Policy);
|
|
|
|
SubPolicy.SuppressStrongLifetime = true;
|
2013-02-22 15:46:01 +00:00
|
|
|
getAsType().print(Out, SubPolicy);
|
2010-12-20 16:52:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 16:52:59 +00:00
|
|
|
case Declaration: {
|
2021-05-12 17:28:41 +00:00
|
|
|
// FIXME: Include the type if it's not obvious from the context.
|
2018-03-01 05:43:23 +00:00
|
|
|
NamedDecl *ND = getAsDecl();
|
2020-09-20 23:16:08 -07:00
|
|
|
if (getParamTypeForDecl()->isRecordType()) {
|
|
|
|
if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
|
|
|
|
TPO->printAsInit(Out);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-01 18:47:27 +00:00
|
|
|
if (auto *VD = dyn_cast<ValueDecl>(ND)) {
|
|
|
|
if (needsAmpersandOnTemplateArg(getParamTypeForDecl(), VD->getType()))
|
|
|
|
Out << "&";
|
|
|
|
}
|
2020-04-14 23:35:35 -07:00
|
|
|
ND->printQualifiedName(Out);
|
2010-12-20 16:52:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-26 02:36:12 +00:00
|
|
|
|
2012-10-05 04:43:29 +00:00
|
|
|
case NullPtr:
|
2021-05-12 17:28:41 +00:00
|
|
|
// FIXME: Include the type if it's not obvious from the context.
|
2012-09-26 02:36:12 +00:00
|
|
|
Out << "nullptr";
|
2012-10-05 04:43:29 +00:00
|
|
|
break;
|
2012-09-26 02:36:12 +00:00
|
|
|
|
2011-01-05 18:58:31 +00:00
|
|
|
case Template:
|
2010-12-20 16:52:59 +00:00
|
|
|
getAsTemplate().print(Out, Policy);
|
|
|
|
break;
|
2011-01-05 18:58:31 +00:00
|
|
|
|
|
|
|
case TemplateExpansion:
|
|
|
|
getAsTemplateOrTemplatePattern().print(Out, Policy);
|
|
|
|
Out << "...";
|
|
|
|
break;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2017-11-21 23:26:08 +00:00
|
|
|
case Integral:
|
2021-05-12 17:28:41 +00:00
|
|
|
printIntegral(*this, Out, Policy, IncludeType);
|
2010-12-20 16:52:59 +00:00
|
|
|
break;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2011-01-05 17:40:24 +00:00
|
|
|
case Expression:
|
2014-05-12 05:36:57 +00:00
|
|
|
getAsExpr()->printPretty(Out, nullptr, Policy);
|
2010-12-20 16:52:59 +00:00
|
|
|
break;
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 16:52:59 +00:00
|
|
|
case Pack:
|
|
|
|
Out << "<";
|
|
|
|
bool First = true;
|
2014-07-15 21:32:31 +00:00
|
|
|
for (const auto &P : pack_elements()) {
|
2010-12-20 16:52:59 +00:00
|
|
|
if (First)
|
|
|
|
First = false;
|
|
|
|
else
|
|
|
|
Out << ", ";
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2021-05-12 17:28:41 +00:00
|
|
|
P.print(Policy, Out, IncludeType);
|
2010-12-20 16:52:59 +00:00
|
|
|
}
|
|
|
|
Out << ">";
|
2018-07-30 19:24:48 +00:00
|
|
|
break;
|
2010-12-20 16:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 13:46:15 +00:00
|
|
|
void TemplateArgument::dump(raw_ostream &Out) const {
|
|
|
|
LangOptions LO; // FIXME! see also TemplateName::dump().
|
|
|
|
LO.CPlusPlus = true;
|
|
|
|
LO.Bool = true;
|
2021-05-12 17:28:41 +00:00
|
|
|
print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
|
2016-01-29 13:46:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 19:38:18 +00:00
|
|
|
LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
|
2016-01-29 13:46:15 +00:00
|
|
|
|
2009-10-29 08:12:44 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateArgumentLoc Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-29 18:45:58 +00:00
|
|
|
SourceRange TemplateArgumentLoc::getSourceRange() const {
|
2009-10-29 08:12:44 +00:00
|
|
|
switch (Argument.getKind()) {
|
|
|
|
case TemplateArgument::Expression:
|
2009-10-29 18:45:58 +00:00
|
|
|
return getSourceExpression()->getSourceRange();
|
2010-09-03 23:50:56 +00:00
|
|
|
|
2009-10-29 08:12:44 +00:00
|
|
|
case TemplateArgument::Declaration:
|
2009-10-29 18:45:58 +00:00
|
|
|
return getSourceDeclExpression()->getSourceRange();
|
2010-09-03 23:50:56 +00:00
|
|
|
|
2012-09-26 02:36:12 +00:00
|
|
|
case TemplateArgument::NullPtr:
|
|
|
|
return getSourceNullPtrExpression()->getSourceRange();
|
|
|
|
|
2009-10-29 18:45:58 +00:00
|
|
|
case TemplateArgument::Type:
|
2010-09-03 23:50:56 +00:00
|
|
|
if (TypeSourceInfo *TSI = getTypeSourceInfo())
|
|
|
|
return TSI->getTypeLoc().getSourceRange();
|
|
|
|
else
|
|
|
|
return SourceRange();
|
|
|
|
|
2011-01-05 18:58:31 +00:00
|
|
|
case TemplateArgument::Template:
|
2011-03-02 17:09:35 +00:00
|
|
|
if (getTemplateQualifierLoc())
|
2018-07-30 19:24:48 +00:00
|
|
|
return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
|
2011-01-05 18:58:31 +00:00
|
|
|
getTemplateNameLoc());
|
|
|
|
return SourceRange(getTemplateNameLoc());
|
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
2011-03-02 17:09:35 +00:00
|
|
|
if (getTemplateQualifierLoc())
|
2018-07-30 19:24:48 +00:00
|
|
|
return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
|
2011-01-05 18:58:31 +00:00
|
|
|
getTemplateEllipsisLoc());
|
|
|
|
return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc());
|
|
|
|
|
2009-10-29 08:12:44 +00:00
|
|
|
case TemplateArgument::Integral:
|
2012-09-26 02:36:12 +00:00
|
|
|
return getSourceIntegralExpression()->getSourceRange();
|
|
|
|
|
2009-10-29 08:12:44 +00:00
|
|
|
case TemplateArgument::Pack:
|
|
|
|
case TemplateArgument::Null:
|
2009-10-29 18:45:58 +00:00
|
|
|
return SourceRange();
|
2009-10-29 08:12:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 21:50:17 +00:00
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
2009-10-29 08:12:44 +00:00
|
|
|
}
|
2010-05-08 17:41:32 +00:00
|
|
|
|
2020-09-23 16:16:00 -04:00
|
|
|
template <typename T>
|
|
|
|
static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
|
2010-05-08 17:41:32 +00:00
|
|
|
switch (Arg.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
2010-08-05 04:58:04 +00:00
|
|
|
// This is bad, but not as bad as crashing because of argument
|
|
|
|
// count mismatches.
|
|
|
|
return DB << "(null template argument)";
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-05-08 17:41:32 +00:00
|
|
|
case TemplateArgument::Type:
|
|
|
|
return DB << Arg.getAsType();
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-05-08 17:41:32 +00:00
|
|
|
case TemplateArgument::Declaration:
|
2012-09-26 02:36:12 +00:00
|
|
|
return DB << Arg.getAsDecl();
|
|
|
|
|
|
|
|
case TemplateArgument::NullPtr:
|
2012-04-06 22:40:38 +00:00
|
|
|
return DB << "nullptr";
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-05-08 17:41:32 +00:00
|
|
|
case TemplateArgument::Integral:
|
2012-06-07 15:09:51 +00:00
|
|
|
return DB << Arg.getAsIntegral().toString(10);
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-05-08 17:41:32 +00:00
|
|
|
case TemplateArgument::Template:
|
2011-01-05 18:58:31 +00:00
|
|
|
return DB << Arg.getAsTemplate();
|
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
|
|
|
|
|
2010-05-08 17:41:32 +00:00
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
// This shouldn't actually ever happen, so it's okay that we're
|
|
|
|
// regurgitating an expression here.
|
|
|
|
// FIXME: We're guessing at LangOptions!
|
2012-02-05 02:13:05 +00:00
|
|
|
SmallString<32> Str;
|
2010-05-08 17:41:32 +00:00
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
LangOptions LangOpts;
|
|
|
|
LangOpts.CPlusPlus = true;
|
|
|
|
PrintingPolicy Policy(LangOpts);
|
2014-05-12 05:36:57 +00:00
|
|
|
Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
|
2010-05-08 17:41:32 +00:00
|
|
|
return DB << OS.str();
|
|
|
|
}
|
2018-07-30 19:24:48 +00:00
|
|
|
|
2010-12-20 16:52:59 +00:00
|
|
|
case TemplateArgument::Pack: {
|
|
|
|
// FIXME: We're guessing at LangOptions!
|
2012-02-05 02:13:05 +00:00
|
|
|
SmallString<32> Str;
|
2010-12-20 16:52:59 +00:00
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
LangOptions LangOpts;
|
|
|
|
LangOpts.CPlusPlus = true;
|
|
|
|
PrintingPolicy Policy(LangOpts);
|
2021-05-12 17:28:41 +00:00
|
|
|
Arg.print(Policy, OS, /*IncludeType*/ true);
|
2010-12-20 16:52:59 +00:00
|
|
|
return DB << OS.str();
|
|
|
|
}
|
2010-05-08 17:41:32 +00:00
|
|
|
}
|
2012-01-20 21:50:17 +00:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateArgument Kind!");
|
2010-05-08 17:41:32 +00:00
|
|
|
}
|
2011-09-22 20:07:09 +00:00
|
|
|
|
2020-09-23 16:16:00 -04:00
|
|
|
const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
|
|
|
|
const TemplateArgument &Arg) {
|
|
|
|
return DiagTemplateArg(DB, Arg);
|
|
|
|
}
|
|
|
|
|
2020-09-21 13:08:17 +02:00
|
|
|
clang::TemplateArgumentLocInfo::TemplateArgumentLocInfo(
|
|
|
|
ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
|
|
|
|
SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
|
|
|
|
TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
|
|
|
|
Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
|
|
|
|
Template->QualifierLocData = QualifierLoc.getOpaqueData();
|
2021-01-14 10:56:53 +00:00
|
|
|
Template->TemplateNameLoc = TemplateNameLoc;
|
|
|
|
Template->EllipsisLoc = EllipsisLoc;
|
2020-09-21 13:08:17 +02:00
|
|
|
Pointer = Template;
|
|
|
|
}
|
|
|
|
|
2011-09-22 20:07:09 +00:00
|
|
|
const ASTTemplateArgumentListInfo *
|
2020-01-22 02:03:05 +02:00
|
|
|
ASTTemplateArgumentListInfo::Create(const ASTContext &C,
|
2011-09-22 20:07:09 +00:00
|
|
|
const TemplateArgumentListInfo &List) {
|
2015-12-24 02:59:37 +00:00
|
|
|
std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
|
2016-10-20 14:27:22 +00:00
|
|
|
void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
|
2015-12-24 02:59:37 +00:00
|
|
|
return new (Mem) ASTTemplateArgumentListInfo(List);
|
2011-09-22 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 02:59:37 +00:00
|
|
|
ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
|
|
|
|
const TemplateArgumentListInfo &Info) {
|
|
|
|
LAngleLoc = Info.getLAngleLoc();
|
|
|
|
RAngleLoc = Info.getRAngleLoc();
|
|
|
|
NumTemplateArgs = Info.size();
|
|
|
|
|
|
|
|
TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
for (unsigned i = 0; i != NumTemplateArgs; ++i)
|
|
|
|
new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
|
2015-12-24 02:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTTemplateKWAndArgsInfo::initializeFrom(
|
2015-12-29 18:15:14 +00:00
|
|
|
SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
|
|
|
|
TemplateArgumentLoc *OutArgArray) {
|
2015-12-24 02:59:37 +00:00
|
|
|
this->TemplateKWLoc = TemplateKWLoc;
|
2011-09-22 20:07:09 +00:00
|
|
|
LAngleLoc = Info.getLAngleLoc();
|
|
|
|
RAngleLoc = Info.getRAngleLoc();
|
|
|
|
NumTemplateArgs = Info.size();
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumTemplateArgs; ++i)
|
|
|
|
new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
|
2011-09-22 20:07:09 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 02:59:37 +00:00
|
|
|
void ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) {
|
|
|
|
assert(TemplateKWLoc.isValid());
|
|
|
|
LAngleLoc = SourceLocation();
|
|
|
|
RAngleLoc = SourceLocation();
|
|
|
|
this->TemplateKWLoc = TemplateKWLoc;
|
|
|
|
NumTemplateArgs = 0;
|
|
|
|
}
|
|
|
|
|
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 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and
> reverted because a dependency commit was reverted.
This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e.
It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb9da1a46a0ca4dba2e49e2426036303.
Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
> Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim
> ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me
> 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall
> 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki
This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786.
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 18e093faf726d15f210ab4917142beec51848258.
2021-01-20 15:25:33 +01:00
|
|
|
void ASTTemplateKWAndArgsInfo::initializeFrom(
|
|
|
|
SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
|
|
|
|
TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
|
|
|
|
this->TemplateKWLoc = TemplateKWLoc;
|
|
|
|
LAngleLoc = Info.getLAngleLoc();
|
|
|
|
RAngleLoc = Info.getRAngleLoc();
|
|
|
|
NumTemplateArgs = Info.size();
|
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumTemplateArgs; ++i) {
|
|
|
|
Deps |= Info[i].getArgument().getDependence();
|
|
|
|
|
|
|
|
new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 18:15:14 +00:00
|
|
|
void ASTTemplateKWAndArgsInfo::copyInto(const TemplateArgumentLoc *ArgArray,
|
|
|
|
TemplateArgumentListInfo &Info) const {
|
2011-09-22 20:07:09 +00:00
|
|
|
Info.setLAngleLoc(LAngleLoc);
|
|
|
|
Info.setRAngleLoc(RAngleLoc);
|
|
|
|
for (unsigned I = 0; I != NumTemplateArgs; ++I)
|
2015-12-29 18:15:14 +00:00
|
|
|
Info.addArgument(ArgArray[I]);
|
2011-09-22 20:07:09 +00:00
|
|
|
}
|