diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 44 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExceptionSpec.cpp | 44 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 33 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 2 |
7 files changed, 64 insertions, 81 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d24cf6a7bef..59953dc9e6c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7110,12 +7110,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, const FunctionProtoType *FPT = R->getAs<FunctionProtoType>(); if ((Name.getCXXOverloadedOperator() == OO_Delete || Name.getCXXOverloadedOperator() == OO_Array_Delete) && - getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec()) { - FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); - EPI.ExceptionSpecType = EST_BasicNoexcept; - NewFD->setType(Context.getFunctionType(FPT->getReturnType(), - FPT->getParamTypes(), EPI)); - } + getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec()) + NewFD->setType(Context.getFunctionType( + FPT->getReturnType(), FPT->getParamTypes(), + FPT->getExtProtoInfo().withExceptionSpec(EST_BasicNoexcept))); } // Filter out previous declarations that don't match the scope. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8a760a8267c..77285edbc0a 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -4818,8 +4818,8 @@ static FunctionProtoType::ExtProtoInfo getImplicitMethodEPI(Sema &S, FunctionProtoType::ExtProtoInfo EPI; // Build an exception specification pointing back at this member. - EPI.ExceptionSpecType = EST_Unevaluated; - EPI.ExceptionSpecDecl = MD; + EPI.ExceptionSpec.Type = EST_Unevaluated; + EPI.ExceptionSpec.SourceDecl = MD; // Set the calling convention to the default for C++ instance methods. EPI.ExtInfo = EPI.ExtInfo.withCallingConv( @@ -4834,14 +4834,10 @@ void Sema::EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD) return; // Evaluate the exception specification. - ImplicitExceptionSpecification ExceptSpec = - computeImplicitExceptionSpec(*this, Loc, MD); - - FunctionProtoType::ExtProtoInfo EPI; - ExceptSpec.getEPI(EPI); + auto ESI = computeImplicitExceptionSpec(*this, Loc, MD).getExceptionSpec(); // Update the type of the special member to use it. - UpdateExceptionSpec(MD, EPI); + UpdateExceptionSpec(MD, ESI); // A user-provided destructor can be defined outside the class. When that // happens, be sure to update the exception specification on both @@ -4849,7 +4845,7 @@ void Sema::EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD) const FunctionProtoType *CanonicalFPT = MD->getCanonicalDecl()->getType()->castAs<FunctionProtoType>(); if (CanonicalFPT->getExceptionSpecType() == EST_Unevaluated) - UpdateExceptionSpec(MD->getCanonicalDecl(), EPI); + UpdateExceptionSpec(MD->getCanonicalDecl(), ESI); } void Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD) { @@ -4995,8 +4991,8 @@ void Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD) { // -- it is implicitly considered to have the same exception-specification // as if it had been implicitly declared, FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo(); - EPI.ExceptionSpecType = EST_Unevaluated; - EPI.ExceptionSpecDecl = MD; + EPI.ExceptionSpec.Type = EST_Unevaluated; + EPI.ExceptionSpec.SourceDecl = MD; MD->setType(Context.getFunctionType(ReturnType, ArrayRef<QualType>(&ArgType, ExpectedParams), @@ -5030,7 +5026,8 @@ void Sema::CheckExplicitlyDefaultedMemberExceptionSpec( CallingConv CC = Context.getDefaultCallingConvention(/*IsVariadic=*/false, /*IsCXXMethod=*/true); FunctionProtoType::ExtProtoInfo EPI(CC); - computeImplicitExceptionSpec(*this, MD->getLocation(), MD).getEPI(EPI); + EPI.ExceptionSpec = computeImplicitExceptionSpec(*this, MD->getLocation(), MD) + .getExceptionSpec(); const FunctionProtoType *ImplicitType = cast<FunctionProtoType>( Context.getFunctionType(Context.VoidTy, None, EPI)); @@ -8744,8 +8741,8 @@ private: // Build an unevaluated exception specification for this constructor. const FunctionProtoType *FPT = DerivedType->castAs<FunctionProtoType>(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); - EPI.ExceptionSpecType = EST_Unevaluated; - EPI.ExceptionSpecDecl = DerivedCtor; + EPI.ExceptionSpec.Type = EST_Unevaluated; + EPI.ExceptionSpec.SourceDecl = DerivedCtor; DerivedCtor->setType(Context.getFunctionType(FPT->getReturnType(), FPT->getParamTypes(), EPI)); @@ -9002,8 +8999,8 @@ void Sema::AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, // the only thing of interest in the destructor type is its extended info. // The return and arguments are fixed. FunctionProtoType::ExtProtoInfo EPI = DtorType->getExtProtoInfo(); - EPI.ExceptionSpecType = EST_Unevaluated; - EPI.ExceptionSpecDecl = Destructor; + EPI.ExceptionSpec.Type = EST_Unevaluated; + EPI.ExceptionSpec.SourceDecl = Destructor; Destructor->setType(Context.getFunctionType(Context.VoidTy, None, EPI)); // FIXME: If the destructor has a body that could throw, and the newly created @@ -12981,9 +12978,9 @@ Sema::checkExceptionSpecification(ExceptionSpecificationType EST, ArrayRef<SourceRange> DynamicExceptionRanges, Expr *NoexceptExpr, SmallVectorImpl<QualType> &Exceptions, - FunctionProtoType::ExtProtoInfo &EPI) { + FunctionProtoType::ExceptionSpecInfo &ESI) { Exceptions.clear(); - EPI.ExceptionSpecType = EST; + ESI.Type = EST; if (EST == EST_Dynamic) { Exceptions.reserve(DynamicExceptions.size()); for (unsigned ei = 0, ee = DynamicExceptions.size(); ei != ee; ++ei) { @@ -13004,11 +13001,10 @@ Sema::checkExceptionSpecification(ExceptionSpecificationType EST, if (!CheckSpecifiedExceptionType(ET, DynamicExceptionRanges[ei])) Exceptions.push_back(ET); } - EPI.NumExceptions = Exceptions.size(); - EPI.Exceptions = Exceptions.data(); + ESI.Exceptions = Exceptions; return; } - + if (EST == EST_ComputedNoexcept) { // If an error occurred, there's no expression here. if (NoexceptExpr) { @@ -13017,15 +13013,15 @@ Sema::checkExceptionSpecification(ExceptionSpecificationType EST, Context.BoolTy) && "Parser should have made sure that the expression is boolean"); if (NoexceptExpr && DiagnoseUnexpandedParameterPack(NoexceptExpr)) { - EPI.ExceptionSpecType = EST_BasicNoexcept; + ESI.Type = EST_BasicNoexcept; return; } - + if (!NoexceptExpr->isValueDependent()) NoexceptExpr = VerifyIntegerConstantExpression(NoexceptExpr, nullptr, diag::err_noexcept_needs_constant_expression, /*AllowFold*/ false).get(); - EPI.NoexceptExpr = NoexceptExpr; + ESI.NoexceptExpr = NoexceptExpr; } return; } diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp index b92fcbd2a0d..192b273c7c3 100644 --- a/clang/lib/Sema/SemaExceptionSpec.cpp +++ b/clang/lib/Sema/SemaExceptionSpec.cpp @@ -132,21 +132,19 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT) { return SourceDecl->getType()->castAs<FunctionProtoType>(); } -void Sema::UpdateExceptionSpec(FunctionDecl *FD, - const FunctionProtoType::ExtProtoInfo &EPI) { - const FunctionProtoType *Proto = FD->getType()->castAs<FunctionProtoType>(); +void +Sema::UpdateExceptionSpec(FunctionDecl *FD, + const FunctionProtoType::ExceptionSpecInfo &ESI) { + const FunctionProtoType *Proto = + FD->getType()->castAs<FunctionProtoType>(); // Overwrite the exception spec and rebuild the function type. - FunctionProtoType::ExtProtoInfo NewEPI = Proto->getExtProtoInfo(); - NewEPI.ExceptionSpecType = EPI.ExceptionSpecType; - NewEPI.NumExceptions = EPI.NumExceptions; - NewEPI.Exceptions = EPI.Exceptions; - NewEPI.NoexceptExpr = EPI.NoexceptExpr; - FD->setType(Context.getFunctionType(Proto->getReturnType(), - Proto->getParamTypes(), NewEPI)); + FD->setType(Context.getFunctionType( + Proto->getReturnType(), Proto->getParamTypes(), + Proto->getExtProtoInfo().withExceptionSpec(ESI))); // If we've fully resolved the exception specification, notify listeners. - if (!isUnresolvedExceptionSpec(EPI.ExceptionSpecType)) + if (!isUnresolvedExceptionSpec(ESI.Type)) if (auto *Listener = getASTMutationListener()) Listener->ResolvedExceptionSpec(FD); } @@ -227,32 +225,28 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { (Old->getLocation().isInvalid() || Context.getSourceManager().isInSystemHeader(Old->getLocation())) && Old->isExternC()) { - FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo(); - EPI.ExceptionSpecType = EST_DynamicNone; - QualType NewType = Context.getFunctionType(NewProto->getReturnType(), - NewProto->getParamTypes(), EPI); - New->setType(NewType); + New->setType(Context.getFunctionType( + NewProto->getReturnType(), NewProto->getParamTypes(), + NewProto->getExtProtoInfo().withExceptionSpec(EST_DynamicNone))); return false; } const FunctionProtoType *OldProto = Old->getType()->castAs<FunctionProtoType>(); - FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo(); - EPI.ExceptionSpecType = OldProto->getExceptionSpecType(); - if (EPI.ExceptionSpecType == EST_Dynamic) { - EPI.NumExceptions = OldProto->getNumExceptions(); - EPI.Exceptions = OldProto->exception_begin(); - } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { + FunctionProtoType::ExceptionSpecInfo ESI = OldProto->getExceptionSpecType(); + if (ESI.Type == EST_Dynamic) { + ESI.Exceptions = OldProto->exceptions(); + } else if (ESI.Type == EST_ComputedNoexcept) { // FIXME: We can't just take the expression from the old prototype. It // likely contains references to the old prototype's parameters. } // Update the type of the function with the appropriate exception // specification. - QualType NewType = Context.getFunctionType(NewProto->getReturnType(), - NewProto->getParamTypes(), EPI); - New->setType(NewType); + New->setType(Context.getFunctionType( + NewProto->getReturnType(), NewProto->getParamTypes(), + NewProto->getExtProtoInfo().withExceptionSpec(ESI))); // Warn about the lack of exception specification. SmallString<128> ExceptionSpecString; diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 425297cdb35..eb7924f473a 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2072,13 +2072,12 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, if (!getLangOpts().CPlusPlus11) { BadAllocType = Context.getTypeDeclType(getStdBadAlloc()); assert(StdBadAlloc && "Must have std::bad_alloc declared"); - EPI.ExceptionSpecType = EST_Dynamic; - EPI.NumExceptions = 1; - EPI.Exceptions = &BadAllocType; + EPI.ExceptionSpec.Type = EST_Dynamic; + EPI.ExceptionSpec.Exceptions = llvm::makeArrayRef(BadAllocType); } } else { - EPI.ExceptionSpecType = getLangOpts().CPlusPlus11 ? - EST_BasicNoexcept : EST_DynamicNone; + EPI.ExceptionSpec = + getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone; } QualType Params[] = { Param1, Param2 }; diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 06170b5e3ad..d0997ccb2b4 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -735,8 +735,7 @@ static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC) { // FIXME: Calling convention! FunctionProtoType::ExtProtoInfo EPI = ConvProto->getExtProtoInfo(); EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC_C); - EPI.ExceptionSpecType = EST_None; - EPI.NumExceptions = 0; + EPI.ExceptionSpec = EST_None; QualType ExpectedType = R.getSema().Context.getFunctionType(R.getLookupName().getCXXNameType(), None, EPI); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index accec95bf70..cddd5b188d5 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3131,13 +3131,12 @@ static void InstantiateExceptionSpec(Sema &SemaRef, FunctionDecl *New, } } - FunctionProtoType::ExtProtoInfo EPI; - EPI.ExceptionSpecType = Proto->getExceptionSpecType(); - EPI.NumExceptions = Exceptions.size(); - EPI.Exceptions = Exceptions.data(); - EPI.NoexceptExpr = NoexceptExpr; + FunctionProtoType::ExceptionSpecInfo ESI; + ESI.Type = Proto->getExceptionSpecType(); + ESI.Exceptions = Exceptions; + ESI.NoexceptExpr = NoexceptExpr; - SemaRef.UpdateExceptionSpec(New, EPI); + SemaRef.UpdateExceptionSpec(New, ESI); } void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, @@ -3151,9 +3150,7 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, if (Inst.isInvalid()) { // We hit the instantiation depth limit. Clear the exception specification // so that our callers don't have to cope with EST_Uninstantiated. - FunctionProtoType::ExtProtoInfo EPI; - EPI.ExceptionSpecType = EST_None; - UpdateExceptionSpec(Decl, EPI); + UpdateExceptionSpec(Decl, EST_None); return; } @@ -3218,14 +3215,14 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, // DR1330: In C++11, defer instantiation of a non-trivial // exception specification. if (SemaRef.getLangOpts().CPlusPlus11 && - EPI.ExceptionSpecType != EST_None && - EPI.ExceptionSpecType != EST_DynamicNone && - EPI.ExceptionSpecType != EST_BasicNoexcept) { + EPI.ExceptionSpec.Type != EST_None && + EPI.ExceptionSpec.Type != EST_DynamicNone && + EPI.ExceptionSpec.Type != EST_BasicNoexcept) { FunctionDecl *ExceptionSpecTemplate = Tmpl; - if (EPI.ExceptionSpecType == EST_Uninstantiated) - ExceptionSpecTemplate = EPI.ExceptionSpecTemplate; + if (EPI.ExceptionSpec.Type == EST_Uninstantiated) + ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate; ExceptionSpecificationType NewEST = EST_Uninstantiated; - if (EPI.ExceptionSpecType == EST_Unevaluated) + if (EPI.ExceptionSpec.Type == EST_Unevaluated) NewEST = EST_Unevaluated; // Mark the function has having an uninstantiated exception specification. @@ -3233,9 +3230,9 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, = New->getType()->getAs<FunctionProtoType>(); assert(NewProto && "Template instantiation without function prototype?"); EPI = NewProto->getExtProtoInfo(); - EPI.ExceptionSpecType = NewEST; - EPI.ExceptionSpecDecl = New; - EPI.ExceptionSpecTemplate = ExceptionSpecTemplate; + EPI.ExceptionSpec.Type = NewEST; + EPI.ExceptionSpec.SourceDecl = New; + EPI.ExceptionSpec.SourceTemplate = ExceptionSpecTemplate; New->setType(SemaRef.Context.getFunctionType( NewProto->getReturnType(), NewProto->getParamTypes(), EPI)); } else { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 47df3a69aab..b6b024c89ab 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2994,7 +2994,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, DynamicExceptionRanges, NoexceptExpr, Exceptions, - EPI); + EPI.ExceptionSpec); T = Context.getFunctionType(T, ParamTys, EPI); } |