aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/AST/TypeLoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/TypeLoc.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/AST/TypeLoc.cpp101
1 files changed, 73 insertions, 28 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/TypeLoc.cpp b/contrib/llvm-project/clang/lib/AST/TypeLoc.cpp
index 16d953b4bece..66732bba18e2 100644
--- a/contrib/llvm-project/clang/lib/AST/TypeLoc.cpp
+++ b/contrib/llvm-project/clang/lib/AST/TypeLoc.cpp
@@ -11,9 +11,10 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/TypeLoc.h"
-#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
+#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/TemplateBase.h"
@@ -194,15 +195,21 @@ SourceLocation TypeLoc::getBeginLoc() const {
while (true) {
switch (Cur.getTypeLocClass()) {
case Elaborated:
- LeftMost = Cur;
- break;
+ if (Cur.getLocalSourceRange().getBegin().isValid()) {
+ LeftMost = Cur;
+ break;
+ }
+ Cur = Cur.getNextTypeLoc();
+ if (Cur.isNull())
+ break;
+ continue;
case FunctionProto:
if (Cur.castAs<FunctionProtoTypeLoc>().getTypePtr()
->hasTrailingReturn()) {
LeftMost = Cur;
break;
}
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case FunctionNoProto:
case ConstantArray:
case DependentSizedArray:
@@ -240,6 +247,8 @@ SourceLocation TypeLoc::getEndLoc() const {
case IncompleteArray:
case VariableArray:
case FunctionNoProto:
+ // The innermost type with suffix syntax always determines the end of the
+ // type.
Last = Cur;
break;
case FunctionProto:
@@ -248,12 +257,19 @@ SourceLocation TypeLoc::getEndLoc() const {
else
Last = Cur;
break;
+ case ObjCObjectPointer:
+ // `id` and `id<...>` have no star location.
+ if (Cur.castAs<ObjCObjectPointerTypeLoc>().getStarLoc().isInvalid())
+ break;
+ [[fallthrough]];
case Pointer:
case BlockPointer:
case MemberPointer:
case LValueReference:
case RValueReference:
case PackExpansion:
+ // Types with prefix syntax only determine the end of the type if there
+ // is no suffix type.
if (!Last)
Last = Cur;
break;
@@ -351,6 +367,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
case BuiltinType::LongDouble:
case BuiltinType::Float16:
case BuiltinType::Float128:
+ case BuiltinType::Ibm128:
case BuiltinType::ShortAccum:
case BuiltinType::Accum:
case BuiltinType::LongAccum:
@@ -408,6 +425,8 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
#include "clang/Basic/PPCTypes.def"
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
#include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
case BuiltinType::BuiltinFn:
case BuiltinType::IncompleteMatrixIdx:
case BuiltinType::OMPArraySection:
@@ -497,12 +516,16 @@ SourceRange AttributedTypeLoc::getLocalSourceRange() const {
return getAttr() ? getAttr()->getRange() : SourceRange();
}
+SourceRange BTFTagAttributedTypeLoc::getLocalSourceRange() const {
+ return getAttr() ? getAttr()->getRange() : SourceRange();
+}
+
void TypeOfTypeLoc::initializeLocal(ASTContext &Context,
SourceLocation Loc) {
TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo>
::initializeLocal(Context, Loc);
- this->getLocalData()->UnderlyingTInfo = Context.getTrivialTypeSourceInfo(
- getUnderlyingType(), Loc);
+ this->getLocalData()->UnmodifiedTInfo =
+ Context.getTrivialTypeSourceInfo(getUnmodifiedType(), Loc);
}
void UnaryTransformTypeLoc::initializeLocal(ASTContext &Context,
@@ -516,6 +539,8 @@ void UnaryTransformTypeLoc::initializeLocal(ASTContext &Context,
void ElaboratedTypeLoc::initializeLocal(ASTContext &Context,
SourceLocation Loc) {
+ if (isEmpty())
+ return;
setElaboratedKeywordLoc(Loc);
NestedNameSpecifierLocBuilder Builder;
Builder.MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
@@ -546,17 +571,14 @@ DependentTemplateSpecializationTypeLoc::initializeLocal(ASTContext &Context,
setTemplateNameLoc(Loc);
setLAngleLoc(Loc);
setRAngleLoc(Loc);
- TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
- getTypePtr()->getArgs(),
- getArgInfos(), Loc);
+ TemplateSpecializationTypeLoc::initializeArgLocs(
+ Context, getTypePtr()->template_arguments(), getArgInfos(), Loc);
}
-void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context,
- unsigned NumArgs,
- const TemplateArgument *Args,
- TemplateArgumentLocInfo *ArgInfos,
- SourceLocation Loc) {
- for (unsigned i = 0, e = NumArgs; i != e; ++i) {
+void TemplateSpecializationTypeLoc::initializeArgLocs(
+ ASTContext &Context, ArrayRef<TemplateArgument> Args,
+ TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc) {
+ for (unsigned i = 0, e = Args.size(); i != e; ++i) {
switch (Args[i].getKind()) {
case TemplateArgument::Null:
llvm_unreachable("Impossible TemplateArgument");
@@ -564,6 +586,7 @@ void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context,
case TemplateArgument::Integral:
case TemplateArgument::Declaration:
case TemplateArgument::NullPtr:
+ case TemplateArgument::StructuralValue:
ArgInfos[i] = TemplateArgumentLocInfo();
break;
@@ -600,25 +623,43 @@ void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context,
}
}
-DeclarationNameInfo AutoTypeLoc::getConceptNameInfo() const {
- return DeclarationNameInfo(getNamedConcept()->getDeclName(),
- getLocalData()->ConceptNameLoc);
+// Builds a ConceptReference where all locations point at the same token,
+// for use in trivial TypeSourceInfo for constrained AutoType
+static ConceptReference *createTrivialConceptReference(ASTContext &Context,
+ SourceLocation Loc,
+ const AutoType *AT) {
+ DeclarationNameInfo DNI =
+ DeclarationNameInfo(AT->getTypeConstraintConcept()->getDeclName(), Loc,
+ AT->getTypeConstraintConcept()->getDeclName());
+ unsigned size = AT->getTypeConstraintArguments().size();
+ TemplateArgumentLocInfo *TALI = new TemplateArgumentLocInfo[size];
+ TemplateSpecializationTypeLoc::initializeArgLocs(
+ Context, AT->getTypeConstraintArguments(), TALI, Loc);
+ TemplateArgumentListInfo TAListI;
+ for (unsigned i = 0; i < size; ++i) {
+ TAListI.addArgument(
+ TemplateArgumentLoc(AT->getTypeConstraintArguments()[i],
+ TALI[i])); // TemplateArgumentLocInfo()
+ }
+
+ auto *ConceptRef = ConceptReference::Create(
+ Context, NestedNameSpecifierLoc{}, Loc, DNI, nullptr,
+ AT->getTypeConstraintConcept(),
+ ASTTemplateArgumentListInfo::Create(Context, TAListI));
+ delete[] TALI;
+ return ConceptRef;
}
void AutoTypeLoc::initializeLocal(ASTContext &Context, SourceLocation Loc) {
- setNestedNameSpecifierLoc(NestedNameSpecifierLoc());
- setTemplateKWLoc(Loc);
- setConceptNameLoc(Loc);
- setFoundDecl(nullptr);
- setRAngleLoc(Loc);
- setLAngleLoc(Loc);
- TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
- getTypePtr()->getArgs(),
- getArgInfos(), Loc);
+ setRParenLoc(Loc);
setNameLoc(Loc);
+ setConceptReference(nullptr);
+ if (getTypePtr()->isConstrained()) {
+ setConceptReference(
+ createTrivialConceptReference(Context, Loc, getTypePtr()));
+ }
}
-
namespace {
class GetContainedAutoTypeLocVisitor :
@@ -672,6 +713,10 @@ namespace {
return Visit(T.getModifiedLoc());
}
+ TypeLoc VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc T) {
+ return Visit(T.getWrappedLoc());
+ }
+
TypeLoc VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc T) {
return Visit(T.getInnerLoc());
}