diff options
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 64 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaFunctionEffects.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 36 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 40 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 186 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 94 | ||||
| -rw-r--r-- | clang/lib/Sema/TypeLocBuilder.h | 6 |
10 files changed, 253 insertions, 216 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ad2c2e4..a8e3fe6 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2609,6 +2609,18 @@ static ExprResult BuiltinInvoke(Sema &S, CallExpr *TheCall) { Args.drop_front(), TheCall->getRParenLoc()); } +// Performs a similar job to Sema::UsualUnaryConversions, but without any +// implicit promotion of integral/enumeration types. +static ExprResult BuiltinVectorMathConversions(Sema &S, Expr *E) { + // First, convert to an r-value. + ExprResult Res = S.DefaultFunctionArrayLvalueConversion(E); + if (Res.isInvalid()) + return ExprError(); + + // Promote floating-point types. + return S.UsualUnaryFPConversions(Res.get()); +} + ExprResult Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, CallExpr *TheCall) { @@ -3273,6 +3285,46 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, return ExprError(); break; + case Builtin::BI__builtin_elementwise_ldexp: { + if (checkArgCount(TheCall, 2)) + return ExprError(); + + ExprResult A = BuiltinVectorMathConversions(*this, TheCall->getArg(0)); + if (A.isInvalid()) + return ExprError(); + QualType TyA = A.get()->getType(); + if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, + EltwiseBuiltinArgTyRestriction::FloatTy, 1)) + return ExprError(); + + ExprResult Exp = UsualUnaryConversions(TheCall->getArg(1)); + if (Exp.isInvalid()) + return ExprError(); + QualType TyExp = Exp.get()->getType(); + if (checkMathBuiltinElementType(*this, Exp.get()->getBeginLoc(), TyExp, + EltwiseBuiltinArgTyRestriction::IntegerTy, + 2)) + return ExprError(); + + // Check the two arguments are either scalars or vectors of equal length. + const auto *Vec0 = TyA->getAs<VectorType>(); + const auto *Vec1 = TyExp->getAs<VectorType>(); + unsigned Arg0Length = Vec0 ? Vec0->getNumElements() : 0; + unsigned Arg1Length = Vec1 ? Vec1->getNumElements() : 0; + if (Arg0Length != Arg1Length) { + Diag(Exp.get()->getBeginLoc(), + diag::err_typecheck_vector_lengths_not_equal) + << TyA << TyExp << A.get()->getSourceRange() + << Exp.get()->getSourceRange(); + return ExprError(); + } + + TheCall->setArg(0, A.get()); + TheCall->setArg(1, Exp.get()); + TheCall->setType(TyA); + break; + } + // These builtins restrict the element type to floating point // types only, and take in two arguments. case Builtin::BI__builtin_elementwise_minnum: @@ -15992,18 +16044,6 @@ void Sema::CheckAddressOfPackedMember(Expr *rhs) { _2, _3, _4)); } -// Performs a similar job to Sema::UsualUnaryConversions, but without any -// implicit promotion of integral/enumeration types. -static ExprResult BuiltinVectorMathConversions(Sema &S, Expr *E) { - // First, convert to an r-value. - ExprResult Res = S.DefaultFunctionArrayLvalueConversion(E); - if (Res.isInvalid()) - return ExprError(); - - // Promote floating-point types. - return S.UsualUnaryFPConversions(Res.get()); -} - bool Sema::PrepareBuiltinElementwiseMathOneArgCall( CallExpr *TheCall, EltwiseBuiltinArgTyRestriction ArgTyRestr) { if (checkArgCount(TheCall, 1)) diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 3df9f9c..53ff818 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -4730,13 +4730,13 @@ ParmVarDecl *SemaObjC::ActOnMethodParmDeclaration(Scope *S, bool MethodDefinition) { ASTContext &Context = getASTContext(); QualType ArgType; - TypeSourceInfo *DI; + TypeSourceInfo *TSI; if (!ArgInfo.Type) { ArgType = Context.getObjCIdType(); - DI = nullptr; + TSI = nullptr; } else { - ArgType = SemaRef.GetTypeFromParser(ArgInfo.Type, &DI); + ArgType = SemaRef.GetTypeFromParser(ArgInfo.Type, &TSI); } LookupResult R(SemaRef, ArgInfo.Name, ArgInfo.NameLoc, Sema::LookupOrdinaryName, @@ -4753,14 +4753,14 @@ ParmVarDecl *SemaObjC::ActOnMethodParmDeclaration(Scope *S, } } SourceLocation StartLoc = - DI ? DI->getTypeLoc().getBeginLoc() : ArgInfo.NameLoc; + TSI ? TSI->getTypeLoc().getBeginLoc() : ArgInfo.NameLoc; // Temporarily put parameter variables in the translation unit. This is what // ActOnParamDeclarator does in the case of C arguments to the Objective-C // method too. ParmVarDecl *Param = SemaRef.CheckParameter( Context.getTranslationUnitDecl(), StartLoc, ArgInfo.NameLoc, ArgInfo.Name, - ArgType, DI, SC_None); + ArgType, TSI, SC_None); Param->setObjCMethodScopeInfo(ParamIndex); Param->setObjCDeclQualifier( CvtQTToAstBitMask(ArgInfo.DeclSpec.getObjCDeclQualifier())); diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp index 4b63eb7..12cc029 100644 --- a/clang/lib/Sema/SemaFunctionEffects.cpp +++ b/clang/lib/Sema/SemaFunctionEffects.cpp @@ -1302,6 +1302,14 @@ private: return true; } + bool TraverseCXXRecordDecl(CXXRecordDecl *D) override { + // Completely skip local struct/class/union declarations since their + // methods would otherwise be incorrectly interpreted as part of the + // function we are currently traversing. The initial Sema pass will have + // already recorded any nonblocking methods needing analysis. + return true; + } + bool TraverseConstructorInitializer(CXXCtorInitializer *Init) override { ViolationSite PrevVS = VSite; if (Init->isAnyMemberInitializer()) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 2cc6593..983a784 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -949,11 +949,11 @@ static TemplateArgumentLoc translateTemplateArgument(Sema &SemaRef, switch (Arg.getKind()) { case ParsedTemplateArgument::Type: { - TypeSourceInfo *DI; - QualType T = SemaRef.GetTypeFromParser(Arg.getAsType(), &DI); - if (!DI) - DI = SemaRef.Context.getTrivialTypeSourceInfo(T, Arg.getNameLoc()); - return TemplateArgumentLoc(TemplateArgument(T), DI); + TypeSourceInfo *TSI; + QualType T = SemaRef.GetTypeFromParser(Arg.getAsType(), &TSI); + if (!TSI) + TSI = SemaRef.Context.getTrivialTypeSourceInfo(T, Arg.getNameLoc()); + return TemplateArgumentLoc(TemplateArgument(T), TSI); } case ParsedTemplateArgument::NonType: { @@ -4329,7 +4329,7 @@ void Sema::CheckDeductionGuideTemplate(FunctionTemplateDecl *TD) { } DeclResult Sema::ActOnVarTemplateSpecialization( - Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous, + Scope *S, Declarator &D, TypeSourceInfo *TSI, LookupResult &Previous, SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, StorageClass SC, bool IsPartialSpecialization) { // D must be variable template id. @@ -4455,8 +4455,8 @@ DeclResult Sema::ActOnVarTemplateSpecialization( VarTemplatePartialSpecializationDecl *Partial = VarTemplatePartialSpecializationDecl::Create( Context, VarTemplate->getDeclContext(), TemplateKWLoc, - TemplateNameLoc, TemplateParams, VarTemplate, DI->getType(), DI, SC, - CTAI.CanonicalConverted); + TemplateNameLoc, TemplateParams, VarTemplate, TSI->getType(), TSI, + SC, CTAI.CanonicalConverted); Partial->setTemplateArgsAsWritten(TemplateArgs); if (!PrevPartial) @@ -4474,7 +4474,7 @@ DeclResult Sema::ActOnVarTemplateSpecialization( // this explicit specialization or friend declaration. Specialization = VarTemplateSpecializationDecl::Create( Context, VarTemplate->getDeclContext(), TemplateKWLoc, TemplateNameLoc, - VarTemplate, DI->getType(), DI, SC, CTAI.CanonicalConverted); + VarTemplate, TSI->getType(), TSI, SC, CTAI.CanonicalConverted); Specialization->setTemplateArgsAsWritten(TemplateArgs); if (!PrevDecl) diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index bfcd397..40811d4 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -632,34 +632,34 @@ private: ParmVarDecl *OldParam, MultiLevelTemplateArgumentList &Args, llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs, bool TransformingOuterPatterns) { - TypeSourceInfo *OldDI = OldParam->getTypeSourceInfo(); - TypeSourceInfo *NewDI; - if (auto PackTL = OldDI->getTypeLoc().getAs<PackExpansionTypeLoc>()) { + TypeSourceInfo *OldTSI = OldParam->getTypeSourceInfo(); + TypeSourceInfo *NewTSI; + if (auto PackTL = OldTSI->getTypeLoc().getAs<PackExpansionTypeLoc>()) { // Expand out the one and only element in each inner pack. Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, 0u); - NewDI = + NewTSI = SemaRef.SubstType(PackTL.getPatternLoc(), Args, OldParam->getLocation(), OldParam->getDeclName()); - if (!NewDI) + if (!NewTSI) return nullptr; - NewDI = - SemaRef.CheckPackExpansion(NewDI, PackTL.getEllipsisLoc(), + NewTSI = + SemaRef.CheckPackExpansion(NewTSI, PackTL.getEllipsisLoc(), PackTL.getTypePtr()->getNumExpansions()); } else - NewDI = SemaRef.SubstType(OldDI, Args, OldParam->getLocation(), - OldParam->getDeclName()); - if (!NewDI) + NewTSI = SemaRef.SubstType(OldTSI, Args, OldParam->getLocation(), + OldParam->getDeclName()); + if (!NewTSI) return nullptr; // Extract the type. This (for instance) replaces references to typedef // members of the current instantiations with the definitions of those // typedefs, avoiding triggering instantiation of the deduced type during // deduction. - NewDI = ExtractTypeForDeductionGuide( - SemaRef, MaterializedTypedefs, NestedPattern, - TransformingOuterPatterns ? &Args : nullptr) - .transform(NewDI); - if (!NewDI) + NewTSI = ExtractTypeForDeductionGuide( + SemaRef, MaterializedTypedefs, NestedPattern, + TransformingOuterPatterns ? &Args : nullptr) + .transform(NewTSI); + if (!NewTSI) return nullptr; // Resolving a wording defect, we also inherit default arguments from the // constructor. @@ -667,7 +667,7 @@ private: if (OldParam->hasDefaultArg()) { // We don't care what the value is (we won't use it); just create a // placeholder to indicate there is a default argument. - QualType ParamTy = NewDI->getType(); + QualType ParamTy = NewTSI->getType(); NewDefArg = new (SemaRef.Context) OpaqueValueExpr(OldParam->getDefaultArgRange().getBegin(), ParamTy.getNonLValueExprType(SemaRef.Context), @@ -676,13 +676,13 @@ private: : VK_PRValue); } // Handle arrays and functions decay. - auto NewType = NewDI->getType(); + auto NewType = NewTSI->getType(); if (NewType->isArrayType() || NewType->isFunctionType()) NewType = SemaRef.Context.getDecayedType(NewType); ParmVarDecl *NewParam = ParmVarDecl::Create( SemaRef.Context, DC, OldParam->getInnerLocStart(), - OldParam->getLocation(), OldParam->getIdentifier(), NewType, NewDI, + OldParam->getLocation(), OldParam->getIdentifier(), NewType, NewTSI, OldParam->getStorageClass(), NewDefArg.get()); NewParam->setScopeInfo(OldParam->getFunctionScopeDepth(), OldParam->getFunctionScopeIndex()); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 7f85805..5fceacd 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -3156,25 +3156,25 @@ Sema::SubstParmVarDecl(ParmVarDecl *OldParm, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack, bool EvaluateConstraint) { - TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); - TypeSourceInfo *NewDI = nullptr; + TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo(); + TypeSourceInfo *NewTSI = nullptr; - TypeLoc OldTL = OldDI->getTypeLoc(); + TypeLoc OldTL = OldTSI->getTypeLoc(); if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { // We have a function parameter pack. Substitute into the pattern of the // expansion. - NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, - OldParm->getLocation(), OldParm->getDeclName()); - if (!NewDI) + NewTSI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, + OldParm->getLocation(), OldParm->getDeclName()); + if (!NewTSI) return nullptr; - if (NewDI->getType()->containsUnexpandedParameterPack()) { + if (NewTSI->getType()->containsUnexpandedParameterPack()) { // We still have unexpanded parameter packs, which means that // our function parameter is still a function parameter pack. // Therefore, make its type a pack expansion type. - NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), - NumExpansions); + NewTSI = CheckPackExpansion(NewTSI, ExpansionTL.getEllipsisLoc(), + NumExpansions); } else if (ExpectParameterPack) { // We expected to get a parameter pack but didn't (because the type // itself is not a pack expansion type), so complain. This can occur when @@ -3182,18 +3182,18 @@ Sema::SubstParmVarDecl(ParmVarDecl *OldParm, // pack expansion. Diag(OldParm->getLocation(), diag::err_function_parameter_pack_without_parameter_packs) - << NewDI->getType(); + << NewTSI->getType(); return nullptr; } } else { - NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), - OldParm->getDeclName()); + NewTSI = SubstType(OldTSI, TemplateArgs, OldParm->getLocation(), + OldParm->getDeclName()); } - if (!NewDI) + if (!NewTSI) return nullptr; - if (NewDI->getType()->isVoidType()) { + if (NewTSI->getType()->isVoidType()) { Diag(OldParm->getLocation(), diag::err_param_with_void_type); return nullptr; } @@ -3205,7 +3205,7 @@ Sema::SubstParmVarDecl(ParmVarDecl *OldParm, // here, when the instantiated versions of those referenced parameters are in // scope. if (TemplateTypeParmDecl *TTP = - GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) { + GetContainedInventedTypeParmVisitor().Visit(OldTSI->getType())) { if (const TypeConstraint *TC = TTP->getTypeConstraint()) { auto *Inst = cast_or_null<TemplateTypeParmDecl>( FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs)); @@ -3219,12 +3219,10 @@ Sema::SubstParmVarDecl(ParmVarDecl *OldParm, } } - ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), - OldParm->getInnerLocStart(), - OldParm->getLocation(), - OldParm->getIdentifier(), - NewDI->getType(), NewDI, - OldParm->getStorageClass()); + ParmVarDecl *NewParm = CheckParameter( + Context.getTranslationUnitDecl(), OldParm->getInnerLocStart(), + OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(), + NewTSI, OldParm->getStorageClass()); if (!NewParm) return nullptr; diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 28925cc..681bfe0 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1506,17 +1506,17 @@ TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias) { bool Invalid = false; - TypeSourceInfo *DI = D->getTypeSourceInfo(); - if (DI->getType()->isInstantiationDependentType() || - DI->getType()->isVariablyModifiedType()) { - DI = SemaRef.SubstType(DI, TemplateArgs, - D->getLocation(), D->getDeclName()); - if (!DI) { + TypeSourceInfo *TSI = D->getTypeSourceInfo(); + if (TSI->getType()->isInstantiationDependentType() || + TSI->getType()->isVariablyModifiedType()) { + TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(), + D->getDeclName()); + if (!TSI) { Invalid = true; - DI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy); + TSI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy); } } else { - SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); + SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType()); } // HACK: 2012-10-23 g++ has a bug where it gets the value kind of ?: wrong. @@ -1525,7 +1525,7 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, // semantics. See LWG issue 2141 for more information on the bug. The bugs // are fixed in g++ and libstdc++ 4.9.0 (2014-04-22). if (SemaRef.getPreprocessor().NeedsStdLibCxxWorkaroundBefore(2014'04'22)) { - const DecltypeType *DT = DI->getType()->getAs<DecltypeType>(); + const DecltypeType *DT = TSI->getType()->getAs<DecltypeType>(); CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext()); if (DT && RD && isa<ConditionalOperator>(DT->getUnderlyingExpr()) && DT->isReferenceType() && @@ -1534,18 +1534,18 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, D->getIdentifier() && D->getIdentifier()->isStr("type") && SemaRef.getSourceManager().isInSystemHeader(D->getBeginLoc())) // Fold it to the (non-reference) type which g++ would have produced. - DI = SemaRef.Context.getTrivialTypeSourceInfo( - DI->getType().getNonReferenceType()); + TSI = SemaRef.Context.getTrivialTypeSourceInfo( + TSI->getType().getNonReferenceType()); } // Create the new typedef TypedefNameDecl *Typedef; if (IsTypeAlias) Typedef = TypeAliasDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(), - D->getLocation(), D->getIdentifier(), DI); + D->getLocation(), D->getIdentifier(), TSI); else Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(), - D->getLocation(), D->getIdentifier(), DI); + D->getLocation(), D->getIdentifier(), TSI); if (Invalid) Typedef->setInvalidDecl(); @@ -1554,7 +1554,7 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, if (const TagType *oldTagType = D->getUnderlyingType()->getAs<TagType>()) { TagDecl *oldTag = oldTagType->getDecl(); if (oldTag->getTypedefNameForAnonDecl() == D && !Invalid) { - TagDecl *newTag = DI->getType()->castAs<TagType>()->getDecl(); + TagDecl *newTag = TSI->getType()->castAs<TagType>()->getDecl(); assert(!newTag->hasNameForLinkage()); newTag->setTypedefNameForAnonDecl(Typedef); } @@ -1719,15 +1719,15 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, ArrayRef<BindingDecl*> *Bindings) { // Do substitution on the type of the declaration - TypeSourceInfo *DI = SemaRef.SubstType( + TypeSourceInfo *TSI = SemaRef.SubstType( D->getTypeSourceInfo(), TemplateArgs, D->getTypeSpecStartLoc(), - D->getDeclName(), /*AllowDeducedTST*/true); - if (!DI) + D->getDeclName(), /*AllowDeducedTST*/ true); + if (!TSI) return nullptr; - if (DI->getType()->isFunctionType()) { + if (TSI->getType()->isFunctionType()) { SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function) - << D->isStaticDataMember() << DI->getType(); + << D->isStaticDataMember() << TSI->getType(); return nullptr; } @@ -1739,12 +1739,12 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, VarDecl *Var; if (Bindings) Var = DecompositionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), - D->getLocation(), DI->getType(), DI, + D->getLocation(), TSI->getType(), TSI, D->getStorageClass(), *Bindings); else Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), - D->getLocation(), D->getIdentifier(), DI->getType(), - DI, D->getStorageClass()); + D->getLocation(), D->getIdentifier(), TSI->getType(), + TSI, D->getStorageClass()); // In ARC, infer 'retaining' for variables of retainable type. if (SemaRef.getLangOpts().ObjCAutoRefCount && @@ -1810,15 +1810,15 @@ Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) { Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { bool Invalid = false; - TypeSourceInfo *DI = D->getTypeSourceInfo(); - if (DI->getType()->isInstantiationDependentType() || - DI->getType()->isVariablyModifiedType()) { - DI = SemaRef.SubstType(DI, TemplateArgs, - D->getLocation(), D->getDeclName()); - if (!DI) { - DI = D->getTypeSourceInfo(); + TypeSourceInfo *TSI = D->getTypeSourceInfo(); + if (TSI->getType()->isInstantiationDependentType() || + TSI->getType()->isVariablyModifiedType()) { + TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(), + D->getDeclName()); + if (!TSI) { + TSI = D->getTypeSourceInfo(); Invalid = true; - } else if (DI->getType()->isFunctionType()) { + } else if (TSI->getType()->isFunctionType()) { // C++ [temp.arg.type]p3: // If a declaration acquires a function type through a type // dependent on a template-parameter and this causes a @@ -1826,11 +1826,11 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { // function declarator to have function type, the program is // ill-formed. SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) - << DI->getType(); + << TSI->getType(); Invalid = true; } } else { - SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); + SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType()); } Expr *BitWidth = D->getBitWidth(); @@ -1850,16 +1850,10 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { BitWidth = InstantiatedBitWidth.getAs<Expr>(); } - FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), - DI->getType(), DI, - cast<RecordDecl>(Owner), - D->getLocation(), - D->isMutable(), - BitWidth, - D->getInClassInitStyle(), - D->getInnerLocStart(), - D->getAccess(), - nullptr); + FieldDecl *Field = SemaRef.CheckFieldDecl( + D->getDeclName(), TSI->getType(), TSI, cast<RecordDecl>(Owner), + D->getLocation(), D->isMutable(), BitWidth, D->getInClassInitStyle(), + D->getInnerLocStart(), D->getAccess(), nullptr); if (!Field) { cast<Decl>(Owner)->setInvalidDecl(); return nullptr; @@ -1892,19 +1886,19 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { bool Invalid = false; - TypeSourceInfo *DI = D->getTypeSourceInfo(); + TypeSourceInfo *TSI = D->getTypeSourceInfo(); - if (DI->getType()->isVariablyModifiedType()) { + if (TSI->getType()->isVariablyModifiedType()) { SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified) << D; Invalid = true; - } else if (DI->getType()->isInstantiationDependentType()) { - DI = SemaRef.SubstType(DI, TemplateArgs, - D->getLocation(), D->getDeclName()); - if (!DI) { - DI = D->getTypeSourceInfo(); + } else if (TSI->getType()->isInstantiationDependentType()) { + TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(), + D->getDeclName()); + if (!TSI) { + TSI = D->getTypeSourceInfo(); Invalid = true; - } else if (DI->getType()->isFunctionType()) { + } else if (TSI->getType()->isFunctionType()) { // C++ [temp.arg.type]p3: // If a declaration acquires a function type through a type // dependent on a template-parameter and this causes a @@ -1912,16 +1906,17 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { // function declarator to have function type, the program is // ill-formed. SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) - << DI->getType(); + << TSI->getType(); Invalid = true; } } else { - SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); + SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType()); } MSPropertyDecl *Property = MSPropertyDecl::Create( - SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(), - DI, D->getBeginLoc(), D->getGetterId(), D->getSetterId()); + SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), + TSI->getType(), TSI, D->getBeginLoc(), D->getGetterId(), + D->getSetterId()); SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs, StartingScope); @@ -3584,7 +3579,7 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( SmallVector<TypeSourceInfo *, 4> ExpandedParameterPackTypesAsWritten; SmallVector<QualType, 4> ExpandedParameterPackTypes; bool IsExpandedParameterPack = false; - TypeSourceInfo *DI; + TypeSourceInfo *TSI; QualType T; bool Invalid = false; @@ -3594,24 +3589,24 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( ExpandedParameterPackTypes.reserve(D->getNumExpansionTypes()); ExpandedParameterPackTypesAsWritten.reserve(D->getNumExpansionTypes()); for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { - TypeSourceInfo *NewDI = + TypeSourceInfo *NewTSI = SemaRef.SubstType(D->getExpansionTypeSourceInfo(I), TemplateArgs, D->getLocation(), D->getDeclName()); - if (!NewDI) + if (!NewTSI) return nullptr; QualType NewT = - SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation()); + SemaRef.CheckNonTypeTemplateParameterType(NewTSI, D->getLocation()); if (NewT.isNull()) return nullptr; - ExpandedParameterPackTypesAsWritten.push_back(NewDI); + ExpandedParameterPackTypesAsWritten.push_back(NewTSI); ExpandedParameterPackTypes.push_back(NewT); } IsExpandedParameterPack = true; - DI = D->getTypeSourceInfo(); - T = DI->getType(); + TSI = D->getTypeSourceInfo(); + T = TSI->getType(); } else if (D->isPackExpansion()) { // The non-type template parameter pack's type is a pack expansion of types. // Determine whether we need to expand this parameter pack into separate @@ -3637,18 +3632,17 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( if (Expand) { for (unsigned I = 0; I != *NumExpansions; ++I) { Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I); - TypeSourceInfo *NewDI = SemaRef.SubstType(Pattern, TemplateArgs, - D->getLocation(), - D->getDeclName()); - if (!NewDI) + TypeSourceInfo *NewTSI = SemaRef.SubstType( + Pattern, TemplateArgs, D->getLocation(), D->getDeclName()); + if (!NewTSI) return nullptr; QualType NewT = - SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation()); + SemaRef.CheckNonTypeTemplateParameterType(NewTSI, D->getLocation()); if (NewT.isNull()) return nullptr; - ExpandedParameterPackTypesAsWritten.push_back(NewDI); + ExpandedParameterPackTypesAsWritten.push_back(NewTSI); ExpandedParameterPackTypes.push_back(NewT); } @@ -3656,8 +3650,8 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( // expanded parameter pack is the original expansion type, but callers // will end up using the expanded parameter pack types for type-checking. IsExpandedParameterPack = true; - DI = D->getTypeSourceInfo(); - T = DI->getType(); + TSI = D->getTypeSourceInfo(); + T = TSI->getType(); } else { // We cannot fully expand the pack expansion now, so substitute into the // pattern and create a new pack expansion type. @@ -3669,22 +3663,22 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( return nullptr; SemaRef.CheckNonTypeTemplateParameterType(NewPattern, D->getLocation()); - DI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(), - NumExpansions); - if (!DI) + TSI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(), + NumExpansions); + if (!TSI) return nullptr; - T = DI->getType(); + T = TSI->getType(); } } else { // Simple case: substitution into a parameter that is not a parameter pack. - DI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs, - D->getLocation(), D->getDeclName()); - if (!DI) + TSI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs, + D->getLocation(), D->getDeclName()); + if (!TSI) return nullptr; // Check that this type is acceptable for a non-type template parameter. - T = SemaRef.CheckNonTypeTemplateParameterType(DI, D->getLocation()); + T = SemaRef.CheckNonTypeTemplateParameterType(TSI, D->getLocation()); if (T.isNull()) { T = SemaRef.Context.IntTy; Invalid = true; @@ -3696,20 +3690,20 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( Param = NonTypeTemplateParmDecl::Create( SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), - D->getPosition(), D->getIdentifier(), T, DI, ExpandedParameterPackTypes, - ExpandedParameterPackTypesAsWritten); + D->getPosition(), D->getIdentifier(), T, TSI, + ExpandedParameterPackTypes, ExpandedParameterPackTypesAsWritten); else Param = NonTypeTemplateParmDecl::Create( SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), - D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), DI); + D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), TSI); - if (AutoTypeLoc AutoLoc = DI->getTypeLoc().getContainedAutoTypeLoc()) + if (AutoTypeLoc AutoLoc = TSI->getTypeLoc().getContainedAutoTypeLoc()) if (AutoLoc.isConstrained()) { SourceLocation EllipsisLoc; if (IsExpandedParameterPack) EllipsisLoc = - DI->getTypeLoc().getAs<PackExpansionTypeLoc>().getEllipsisLoc(); + TSI->getTypeLoc().getAs<PackExpansionTypeLoc>().getEllipsisLoc(); else if (auto *Constraint = dyn_cast_if_present<CXXFoldExpr>( D->getPlaceholderTypeConstraint())) EllipsisLoc = Constraint->getEllipsisLoc(); @@ -4642,22 +4636,22 @@ TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( VarTemplateSpecializationDecl *PrevDecl) { // Do substitution on the type of the declaration - TypeSourceInfo *DI = + TypeSourceInfo *TSI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs, D->getTypeSpecStartLoc(), D->getDeclName()); - if (!DI) + if (!TSI) return nullptr; - if (DI->getType()->isFunctionType()) { + if (TSI->getType()->isFunctionType()) { SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function) - << D->isStaticDataMember() << DI->getType(); + << D->isStaticDataMember() << TSI->getType(); return nullptr; } // Build the instantiated declaration VarTemplateSpecializationDecl *Var = VarTemplateSpecializationDecl::Create( SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), - VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted); + VarTemplate, TSI->getType(), TSI, D->getStorageClass(), Converted); if (!PrevDecl) { void *InsertPos = nullptr; VarTemplate->findSpecialization(Converted, InsertPos); @@ -5005,16 +4999,16 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( InstParams, InsertPos); // Do substitution on the type of the declaration - TypeSourceInfo *DI = SemaRef.SubstType( + TypeSourceInfo *TSI = SemaRef.SubstType( PartialSpec->getTypeSourceInfo(), TemplateArgs, PartialSpec->getTypeSpecStartLoc(), PartialSpec->getDeclName()); - if (!DI) + if (!TSI) return nullptr; - if (DI->getType()->isFunctionType()) { + if (TSI->getType()->isFunctionType()) { SemaRef.Diag(PartialSpec->getLocation(), diag::err_variable_instantiates_to_function) - << PartialSpec->isStaticDataMember() << DI->getType(); + << PartialSpec->isStaticDataMember() << TSI->getType(); return nullptr; } @@ -5022,8 +5016,8 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( VarTemplatePartialSpecializationDecl *InstPartialSpec = VarTemplatePartialSpecializationDecl::Create( SemaRef.Context, Owner, PartialSpec->getInnerLocStart(), - PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(), - DI, PartialSpec->getStorageClass(), CTAI.CanonicalConverted); + PartialSpec->getLocation(), InstParams, VarTemplate, TSI->getType(), + TSI, PartialSpec->getStorageClass(), CTAI.CanonicalConverted); InstPartialSpec->setTemplateArgsAsWritten(InstTemplateArgs); @@ -6026,14 +6020,14 @@ VarTemplateSpecializationDecl *Sema::CompleteVarTemplateSpecializationDecl( "don't have a definition to instantiate from"); // Do substitution on the type of the declaration - TypeSourceInfo *DI = + TypeSourceInfo *TSI = SubstType(PatternDecl->getTypeSourceInfo(), TemplateArgs, PatternDecl->getTypeSpecStartLoc(), PatternDecl->getDeclName()); - if (!DI) + if (!TSI) return nullptr; // Update the type of this variable template specialization. - VarSpec->setType(DI->getType()); + VarSpec->setType(TSI->getType()); // Convert the declaration into a definition now. VarSpec->setCompleteDefinition(); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index c483930..eb8b135 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2795,13 +2795,14 @@ QualType Sema::GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo) { return QualType(); } - TypeSourceInfo *DI = nullptr; + TypeSourceInfo *TSI = nullptr; if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) { QT = LIT->getType(); - DI = LIT->getTypeSourceInfo(); + TSI = LIT->getTypeSourceInfo(); } - if (TInfo) *TInfo = DI; + if (TInfo) + *TInfo = TSI; return QT; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 8c20078..dffd7c1 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -371,7 +371,7 @@ public: /// may override this function (to take over all type /// transformations) or some set of the TransformXXXType functions /// to alter the transformation. - TypeSourceInfo *TransformType(TypeSourceInfo *DI); + TypeSourceInfo *TransformType(TypeSourceInfo *TSI); /// Transform the given type-with-location into a new /// type, collecting location information in the given builder @@ -387,7 +387,7 @@ public: /// template arguments. /// @{ QualType TransformTypeWithDeducedTST(QualType T); - TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); + TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *TSI); /// @} /// The reason why the value of a statement is not discarded, if any. @@ -4995,15 +4995,15 @@ bool TreeTransform<Derived>::TransformTemplateArgument( } case TemplateArgument::Type: { - TypeSourceInfo *DI = Input.getTypeSourceInfo(); - if (!DI) - DI = InventTypeSourceInfo(Input.getArgument().getAsType()); + TypeSourceInfo *TSI = Input.getTypeSourceInfo(); + if (!TSI) + TSI = InventTypeSourceInfo(Input.getArgument().getAsType()); - DI = getDerived().TransformType(DI); - if (!DI) + TSI = getDerived().TransformType(TSI); + if (!TSI) return true; - Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); + Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI); return false; } @@ -5360,28 +5360,28 @@ QualType TreeTransform<Derived>::TransformType(QualType T) { // Temporary workaround. All of these transformations should // eventually turn into transformations on TypeLocs. - TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, - getDerived().getBaseLocation()); + TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo( + T, getDerived().getBaseLocation()); - TypeSourceInfo *NewDI = getDerived().TransformType(DI); + TypeSourceInfo *NewTSI = getDerived().TransformType(TSI); - if (!NewDI) + if (!NewTSI) return QualType(); - return NewDI->getType(); + return NewTSI->getType(); } -template<typename Derived> -TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { +template <typename Derived> +TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *TSI) { // Refine the base location to the type's location. - TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), + TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(), getDerived().getBaseEntity()); - if (getDerived().AlreadyTransformed(DI->getType())) - return DI; + if (getDerived().AlreadyTransformed(TSI->getType())) + return TSI; TypeLocBuilder TLB; - TypeLoc TL = DI->getTypeLoc(); + TypeLoc TL = TSI->getTypeLoc(); TLB.reserve(TL.getFullDataSize()); QualType Result = getDerived().TransformType(TLB, TL); @@ -5413,27 +5413,27 @@ QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { if (getDerived().AlreadyTransformed(T)) return T; - TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, - getDerived().getBaseLocation()); - TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); - return NewDI ? NewDI->getType() : QualType(); + TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo( + T, getDerived().getBaseLocation()); + TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI); + return NewTSI ? NewTSI->getType() : QualType(); } -template<typename Derived> +template <typename Derived> TypeSourceInfo * -TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { - if (!isa<DependentNameType>(DI->getType())) - return TransformType(DI); +TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *TSI) { + if (!isa<DependentNameType>(TSI->getType())) + return TransformType(TSI); // Refine the base location to the type's location. - TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), + TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(), getDerived().getBaseEntity()); - if (getDerived().AlreadyTransformed(DI->getType())) - return DI; + if (getDerived().AlreadyTransformed(TSI->getType())) + return TSI; TypeLocBuilder TLB; - TypeLoc TL = DI->getTypeLoc(); + TypeLoc TL = TSI->getTypeLoc(); TLB.reserve(TL.getFullDataSize()); auto QTL = TL.getAs<QualifiedTypeLoc>(); @@ -6258,17 +6258,17 @@ template <typename Derived> ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack) { - TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); - TypeSourceInfo *NewDI = nullptr; + TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo(); + TypeSourceInfo *NewTSI = nullptr; - if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { + if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) { // If we're substituting into a pack expansion type and we know the // length we want to expand to, just substitute for the pattern. - TypeLoc OldTL = OldDI->getTypeLoc(); + TypeLoc OldTL = OldTSI->getTypeLoc(); PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); TypeLocBuilder TLB; - TypeLoc NewTL = OldDI->getTypeLoc(); + TypeLoc NewTL = OldTSI->getTypeLoc(); TLB.reserve(NewTL.getFullDataSize()); QualType Result = getDerived().TransformType(TLB, @@ -6286,24 +6286,20 @@ ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( PackExpansionTypeLoc NewExpansionTL = TLB.push<PackExpansionTypeLoc>(Result); NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); - NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); + NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result); } else - NewDI = getDerived().TransformType(OldDI); - if (!NewDI) + NewTSI = getDerived().TransformType(OldTSI); + if (!NewTSI) return nullptr; - if (NewDI == OldDI && indexAdjustment == 0) + if (NewTSI == OldTSI && indexAdjustment == 0) return OldParm; - ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, - OldParm->getDeclContext(), - OldParm->getInnerLocStart(), - OldParm->getLocation(), - OldParm->getIdentifier(), - NewDI->getType(), - NewDI, - OldParm->getStorageClass(), - /* DefArg */ nullptr); + ParmVarDecl *newParm = ParmVarDecl::Create( + SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(), + OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(), + NewTSI, OldParm->getStorageClass(), + /* DefArg */ nullptr); newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), OldParm->getFunctionScopeIndex() + indexAdjustment); getDerived().transformedLocalDecl(OldParm, {newParm}); diff --git a/clang/lib/Sema/TypeLocBuilder.h b/clang/lib/Sema/TypeLocBuilder.h index 0c27088..e84e79a 100644 --- a/clang/lib/Sema/TypeLocBuilder.h +++ b/clang/lib/Sema/TypeLocBuilder.h @@ -113,9 +113,9 @@ public: #endif size_t FullDataSize = Capacity - Index; - TypeSourceInfo *DI = Context.CreateTypeSourceInfo(T, FullDataSize); - memcpy(DI->getTypeLoc().getOpaqueData(), &Buffer[Index], FullDataSize); - return DI; + TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T, FullDataSize); + memcpy(TSI->getTypeLoc().getOpaqueData(), &Buffer[Index], FullDataSize); + return TSI; } /// Copies the type-location information to the given AST context and |
