ArrayRef-ize ASTContext::getFunctionType and Sema::BuildFunctionType.

No (intended) functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176726 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jordan Rose 2013-03-08 21:51:21 +00:00
parent 303b96f255
commit bea522ff43
24 changed files with 245 additions and 239 deletions

View File

@ -993,8 +993,7 @@ public:
} }
/// \brief Return a normal function type with a typed argument list. /// \brief Return a normal function type with a typed argument list.
QualType getFunctionType(QualType ResultTy, QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args,
const QualType *Args, unsigned NumArgs,
const FunctionProtoType::ExtProtoInfo &EPI) const; const FunctionProtoType::ExtProtoInfo &EPI) const;
/// \brief Return the unique reference to the type for the specified type /// \brief Return the unique reference to the type for the specified type

View File

@ -2797,7 +2797,7 @@ private:
return false; return false;
} }
FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, FunctionProtoType(QualType result, ArrayRef<QualType> args,
QualType canonical, const ExtProtoInfo &epi); QualType canonical, const ExtProtoInfo &epi);
/// NumArgs - The number of arguments this function has, not counting '...'. /// NumArgs - The number of arguments this function has, not counting '...'.

View File

@ -944,12 +944,43 @@ public:
SourceRange Brackets, DeclarationName Entity); SourceRange Brackets, DeclarationName Entity);
QualType BuildExtVectorType(QualType T, Expr *ArraySize, QualType BuildExtVectorType(QualType T, Expr *ArraySize,
SourceLocation AttrLoc); SourceLocation AttrLoc);
/// \brief Build a function type.
///
/// This routine checks the function type according to C++ rules and
/// under the assumption that the result type and parameter types have
/// just been instantiated from a template. It therefore duplicates
/// some of the behavior of GetTypeForDeclarator, but in a much
/// simpler form that is only suitable for this narrow use case.
///
/// \param T The return type of the function.
///
/// \param ParamTypes The parameter types of the function. This array
/// will be modified to account for adjustments to the types of the
/// function parameters.
///
/// \param Variadic Whether this is a variadic function type.
///
/// \param HasTrailingReturn Whether this function has a trailing return type.
///
/// \param Quals The cvr-qualifiers to be applied to the function type.
///
/// \param Loc The location of the entity whose type involves this
/// function type or, if there is no such entity, the location of the
/// type that will have function type.
///
/// \param Entity The name of the entity that involves the function
/// type, if known.
///
/// \returns A suitable function type, if there are no errors.
/// Otherwise, returns a NULL type.
QualType BuildFunctionType(QualType T, QualType BuildFunctionType(QualType T,
QualType *ParamTypes, unsigned NumParamTypes, llvm::MutableArrayRef<QualType> ParamTypes,
bool Variadic, bool HasTrailingReturn, bool Variadic, bool HasTrailingReturn,
unsigned Quals, RefQualifierKind RefQualifier, unsigned Quals, RefQualifierKind RefQualifier,
SourceLocation Loc, DeclarationName Entity, SourceLocation Loc, DeclarationName Entity,
FunctionType::ExtInfo Info); FunctionType::ExtInfo Info);
QualType BuildMemberPointerType(QualType T, QualType Class, QualType BuildMemberPointerType(QualType T, QualType Class,
SourceLocation Loc, SourceLocation Loc,
DeclarationName Entity); DeclarationName Entity);

View File

@ -1974,8 +1974,10 @@ const FunctionType *ASTContext::adjustFunctionType(const FunctionType *T,
const FunctionProtoType *FPT = cast<FunctionProtoType>(T); const FunctionProtoType *FPT = cast<FunctionProtoType>(T);
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.ExtInfo = Info; EPI.ExtInfo = Info;
Result = getFunctionType(FPT->getResultType(), FPT->arg_type_begin(), Result = getFunctionType(FPT->getResultType(),
FPT->getNumArgs(), EPI); ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs()),
EPI);
} }
return cast<FunctionType>(Result.getTypePtr()); return cast<FunctionType>(Result.getTypePtr());
@ -2640,13 +2642,15 @@ static bool isCanonicalResultType(QualType T) {
/// getFunctionType - Return a normal function type with a typed argument /// getFunctionType - Return a normal function type with a typed argument
/// list. isVariadic indicates whether the argument list includes '...'. /// list. isVariadic indicates whether the argument list includes '...'.
QualType QualType
ASTContext::getFunctionType(QualType ResultTy, ASTContext::getFunctionType(QualType ResultTy, ArrayRef<QualType> ArgArray,
const QualType *ArgArray, unsigned NumArgs,
const FunctionProtoType::ExtProtoInfo &EPI) const { const FunctionProtoType::ExtProtoInfo &EPI) const {
size_t NumArgs = ArgArray.size();
// Unique functions, to guarantee there is only one function of a particular // Unique functions, to guarantee there is only one function of a particular
// structure. // structure.
llvm::FoldingSetNodeID ID; llvm::FoldingSetNodeID ID;
FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, *this); FunctionProtoType::Profile(ID, ResultTy, ArgArray.begin(), NumArgs, EPI,
*this);
void *InsertPos = 0; void *InsertPos = 0;
if (FunctionProtoType *FTP = if (FunctionProtoType *FTP =
@ -2689,9 +2693,7 @@ ASTContext::getFunctionType(QualType ResultTy,
CanResultTy = getQualifiedType(CanResultTy.getUnqualifiedType(), Qs); CanResultTy = getQualifiedType(CanResultTy.getUnqualifiedType(), Qs);
} }
Canonical = getFunctionType(CanResultTy, Canonical = getFunctionType(CanResultTy, CanonicalArgs, CanonicalEPI);
CanonicalArgs.data(), NumArgs,
CanonicalEPI);
// Get the new insert position for the node we care about. // Get the new insert position for the node we care about.
FunctionProtoType *NewIP = FunctionProtoType *NewIP =
@ -2724,7 +2726,7 @@ ASTContext::getFunctionType(QualType ResultTy,
FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment);
FunctionProtoType::ExtProtoInfo newEPI = EPI; FunctionProtoType::ExtProtoInfo newEPI = EPI;
newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv); newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv);
new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI); new (FTP) FunctionProtoType(ResultTy, ArgArray, Canonical, newEPI);
Types.push_back(FTP); Types.push_back(FTP);
FunctionProtoTypes.InsertNode(FTP, InsertPos); FunctionProtoTypes.InsertNode(FTP, InsertPos);
return QualType(FTP, 0); return QualType(FTP, 0);
@ -6794,7 +6796,7 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo();
EPI.ExtInfo = einfo; EPI.ExtInfo = einfo;
return getFunctionType(retType, types.begin(), types.size(), EPI); return getFunctionType(retType, types, EPI);
} }
if (lproto) allRTypes = false; if (lproto) allRTypes = false;
@ -6831,8 +6833,10 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo();
EPI.ExtInfo = einfo; EPI.ExtInfo = einfo;
return getFunctionType(retType, proto->arg_type_begin(), return getFunctionType(retType,
proto->getNumArgs(), EPI); ArrayRef<QualType>(proto->arg_type_begin(),
proto->getNumArgs()),
EPI);
} }
if (allLTypes) return lhs; if (allLTypes) return lhs;
@ -7165,8 +7169,10 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) {
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.ExtInfo = getFunctionExtInfo(LHS); EPI.ExtInfo = getFunctionExtInfo(LHS);
QualType ResultType QualType ResultType
= getFunctionType(OldReturnType, FPT->arg_type_begin(), = getFunctionType(OldReturnType,
FPT->getNumArgs(), EPI); ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs()),
EPI);
return ResultType; return ResultType;
} }
} }
@ -7558,7 +7564,7 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
EPI.ExtInfo = EI; EPI.ExtInfo = EI;
EPI.Variadic = Variadic; EPI.Variadic = Variadic;
return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), EPI); return getFunctionType(ResType, ArgTypes, EPI);
} }
GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) {

View File

@ -1619,8 +1619,7 @@ QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>( ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
Importer.Import(FromEPI.ExceptionSpecTemplate)); Importer.Import(FromEPI.ExceptionSpecTemplate));
return Importer.getToContext().getFunctionType(ToResultType, ArgTypes.data(), return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
ArgTypes.size(), ToEPI);
} }
QualType ASTNodeImporter::VisitParenType(const ParenType *T) { QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
@ -2660,8 +2659,8 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
FunctionProtoType::ExtProtoInfo DefaultEPI; FunctionProtoType::ExtProtoInfo DefaultEPI;
FromTy = Importer.getFromContext().getFunctionType( FromTy = Importer.getFromContext().getFunctionType(
FromFPT->getResultType(), FromFPT->getResultType(),
FromFPT->arg_type_begin(), ArrayRef<QualType>(FromFPT->arg_type_begin(),
FromFPT->arg_type_end() - FromFPT->arg_type_begin(), FromFPT->getNumArgs()),
DefaultEPI); DefaultEPI);
usedDifferentExceptionSpec = true; usedDifferentExceptionSpec = true;
} }

View File

@ -178,7 +178,8 @@ CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
SourceLocation ColonColonLoc, SourceLocation TildeLoc, SourceLocation ColonColonLoc, SourceLocation TildeLoc,
PseudoDestructorTypeStorage DestroyedType) PseudoDestructorTypeStorage DestroyedType)
: Expr(CXXPseudoDestructorExprClass, : Expr(CXXPseudoDestructorExprClass,
Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, Context.getPointerType(Context.getFunctionType(Context.VoidTy,
ArrayRef<QualType>(),
FunctionProtoType::ExtProtoInfo())), FunctionProtoType::ExtProtoInfo())),
VK_RValue, OK_Ordinary, VK_RValue, OK_Ordinary,
/*isTypeDependent=*/(Base->isTypeDependent() || /*isTypeDependent=*/(Base->isTypeDependent() ||

View File

@ -23,10 +23,11 @@ unsigned LambdaMangleContext::getManglingNumber(CXXMethodDecl *CallOperator) {
= CallOperator->getType()->getAs<FunctionProtoType>(); = CallOperator->getType()->getAs<FunctionProtoType>();
ASTContext &Context = CallOperator->getASTContext(); ASTContext &Context = CallOperator->getASTContext();
QualType Key = Context.getFunctionType(Context.VoidTy, QualType Key =
Proto->arg_type_begin(), Context.getFunctionType(Context.VoidTy,
Proto->getNumArgs(), ArrayRef<QualType>(Proto->arg_type_begin(),
FunctionProtoType::ExtProtoInfo()); Proto->getNumArgs()),
FunctionProtoType::ExtProtoInfo());
Key = Context.getCanonicalType(Key); Key = Context.getCanonicalType(Key);
return ++ManglingNumbers[Key->castAs<FunctionProtoType>()]; return ++ManglingNumbers[Key->castAs<FunctionProtoType>()];
} }

View File

@ -1560,8 +1560,8 @@ StringRef FunctionType::getNameForCallConv(CallingConv CC) {
llvm_unreachable("Invalid calling convention."); llvm_unreachable("Invalid calling convention.");
} }
FunctionProtoType::FunctionProtoType(QualType result, const QualType *args, FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> args,
unsigned numArgs, QualType canonical, QualType canonical,
const ExtProtoInfo &epi) const ExtProtoInfo &epi)
: FunctionType(FunctionProto, result, epi.TypeQuals, : FunctionType(FunctionProto, result, epi.TypeQuals,
canonical, canonical,
@ -1570,17 +1570,17 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
result->isVariablyModifiedType(), result->isVariablyModifiedType(),
result->containsUnexpandedParameterPack(), result->containsUnexpandedParameterPack(),
epi.ExtInfo), epi.ExtInfo),
NumArgs(numArgs), NumExceptions(epi.NumExceptions), NumArgs(args.size()), NumExceptions(epi.NumExceptions),
ExceptionSpecType(epi.ExceptionSpecType), ExceptionSpecType(epi.ExceptionSpecType),
HasAnyConsumedArgs(epi.ConsumedArguments != 0), HasAnyConsumedArgs(epi.ConsumedArguments != 0),
Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn), Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn),
RefQualifier(epi.RefQualifier) RefQualifier(epi.RefQualifier)
{ {
assert(NumArgs == numArgs && "function has too many parameters"); assert(NumArgs == args.size() && "function has too many parameters");
// Fill in the trailing argument array. // Fill in the trailing argument array.
QualType *argSlot = reinterpret_cast<QualType*>(this+1); QualType *argSlot = reinterpret_cast<QualType*>(this+1);
for (unsigned i = 0; i != numArgs; ++i) { for (unsigned i = 0; i != NumArgs; ++i) {
if (args[i]->isDependentType()) if (args[i]->isDependentType())
setDependent(); setDependent();
else if (args[i]->isInstantiationDependentType()) else if (args[i]->isInstantiationDependentType())
@ -1594,7 +1594,7 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
if (getExceptionSpecType() == EST_Dynamic) { if (getExceptionSpecType() == EST_Dynamic) {
// Fill in the exception array. // Fill in the exception array.
QualType *exnSlot = argSlot + numArgs; QualType *exnSlot = argSlot + NumArgs;
for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) {
if (epi.Exceptions[i]->isDependentType()) if (epi.Exceptions[i]->isDependentType())
setDependent(); setDependent();
@ -1608,7 +1608,7 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
} }
} else if (getExceptionSpecType() == EST_ComputedNoexcept) { } else if (getExceptionSpecType() == EST_ComputedNoexcept) {
// Store the noexcept expression and context. // Store the noexcept expression and context.
Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs); Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + NumArgs);
*noexSlot = epi.NoexceptExpr; *noexSlot = epi.NoexceptExpr;
if (epi.NoexceptExpr) { if (epi.NoexceptExpr) {
@ -1621,7 +1621,7 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
} else if (getExceptionSpecType() == EST_Uninstantiated) { } else if (getExceptionSpecType() == EST_Uninstantiated) {
// Store the function decl from which we will resolve our // Store the function decl from which we will resolve our
// exception specification. // exception specification.
FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + numArgs); FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + NumArgs);
slot[0] = epi.ExceptionSpecDecl; slot[0] = epi.ExceptionSpecDecl;
slot[1] = epi.ExceptionSpecTemplate; slot[1] = epi.ExceptionSpecTemplate;
// This exception specification doesn't make the type dependent, because // This exception specification doesn't make the type dependent, because
@ -1629,13 +1629,13 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
} else if (getExceptionSpecType() == EST_Unevaluated) { } else if (getExceptionSpecType() == EST_Unevaluated) {
// Store the function decl from which we will resolve our // Store the function decl from which we will resolve our
// exception specification. // exception specification.
FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + numArgs); FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + NumArgs);
slot[0] = epi.ExceptionSpecDecl; slot[0] = epi.ExceptionSpecDecl;
} }
if (epi.ConsumedArguments) { if (epi.ConsumedArguments) {
bool *consumedArgs = const_cast<bool*>(getConsumedArgsBuffer()); bool *consumedArgs = const_cast<bool*>(getConsumedArgsBuffer());
for (unsigned i = 0; i != numArgs; ++i) for (unsigned i = 0; i != NumArgs; ++i)
consumedArgs[i] = epi.ConsumedArguments[i]; consumedArgs[i] = epi.ConsumedArguments[i];
} }
} }

View File

@ -420,19 +420,16 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
// Emit subprogram debug descriptor. // Emit subprogram debug descriptor.
if (CGDebugInfo *DI = getDebugInfo()) { if (CGDebugInfo *DI = getDebugInfo()) {
unsigned NumArgs = 0; SmallVector<QualType, 16> ArgTypes;
QualType *ArgsArray = new QualType[Args.size()];
for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
i != e; ++i) { i != e; ++i) {
ArgsArray[NumArgs++] = (*i)->getType(); ArgTypes.push_back((*i)->getType());
} }
QualType FnType = QualType FnType =
getContext().getFunctionType(RetTy, ArgsArray, NumArgs, getContext().getFunctionType(RetTy, ArgTypes,
FunctionProtoType::ExtProtoInfo()); FunctionProtoType::ExtProtoInfo());
delete[] ArgsArray;
DI->setLocation(StartLoc); DI->setLocation(StartLoc);
DI->EmitFunctionStart(GD, FnType, CurFn, Builder); DI->EmitFunctionStart(GD, FnType, CurFn, Builder);
} }

View File

@ -572,14 +572,13 @@ namespace {
} }
QualType getSimpleFunctionType(QualType result, QualType getSimpleFunctionType(QualType result,
const QualType *args, ArrayRef<QualType> args,
unsigned numArgs,
bool variadic = false) { bool variadic = false) {
if (result == Context->getObjCInstanceType()) if (result == Context->getObjCInstanceType())
result = Context->getObjCIdType(); result = Context->getObjCIdType();
FunctionProtoType::ExtProtoInfo fpi; FunctionProtoType::ExtProtoInfo fpi;
fpi.Variadic = variadic; fpi.Variadic = variadic;
return Context->getFunctionType(result, args, numArgs, fpi); return Context->getFunctionType(result, args, fpi);
} }
// Helper function: create a CStyleCastExpr with trivial type source info. // Helper function: create a CStyleCastExpr with trivial type source info.
@ -2358,7 +2357,7 @@ void RewriteModernObjC::SynthSelGetUidFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getFuncType = QualType getFuncType =
getSimpleFunctionType(Context->getObjCSelType(), &ArgTys[0], ArgTys.size()); getSimpleFunctionType(Context->getObjCSelType(), ArgTys);
SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl, SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2456,7 +2455,7 @@ void RewriteModernObjC::SynthSuperContructorFunctionDecl() {
ArgTys.push_back(argT); ArgTys.push_back(argT);
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size()); ArgTys);
SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl, SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2475,8 +2474,7 @@ void RewriteModernObjC::SynthMsgSendFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2490,8 +2488,7 @@ void RewriteModernObjC::SynthMsgSendSuperFunctionDecl() {
SmallVector<QualType, 2> ArgTys; SmallVector<QualType, 2> ArgTys;
ArgTys.push_back(Context->VoidTy); ArgTys.push_back(Context->VoidTy);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], 1, ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2510,8 +2507,7 @@ void RewriteModernObjC::SynthMsgSendStretFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2527,8 +2523,7 @@ void RewriteModernObjC::SynthMsgSendSuperStretFunctionDecl() {
SmallVector<QualType, 2> ArgTys; SmallVector<QualType, 2> ArgTys;
ArgTys.push_back(Context->VoidTy); ArgTys.push_back(Context->VoidTy);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], 1, ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2548,8 +2543,7 @@ void RewriteModernObjC::SynthMsgSendFpretFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->DoubleTy, QualType msgSendType = getSimpleFunctionType(Context->DoubleTy,
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2563,7 +2557,7 @@ void RewriteModernObjC::SynthGetClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2578,7 +2572,7 @@ void RewriteModernObjC::SynthGetSuperClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getObjCClassType()); ArgTys.push_back(Context->getObjCClassType());
QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetSuperClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetSuperClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2593,7 +2587,7 @@ void RewriteModernObjC::SynthGetMetaClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2740,8 +2734,7 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) {
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
QualType castType = QualType castType =
getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), getSimpleFunctionType(returnType, ArgTypes, BoxingMethod->isVariadic());
BoxingMethod->isVariadic());
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -2774,7 +2767,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) {
// Build the expression: __NSContainer_literal(int, ...).arr // Build the expression: __NSContainer_literal(int, ...).arr
QualType IntQT = Context->IntTy; QualType IntQT = Context->IntTy;
QualType NSArrayFType = QualType NSArrayFType =
getSimpleFunctionType(Context->VoidTy, &IntQT, 1, true); getSimpleFunctionType(Context->VoidTy, IntQT, true);
std::string NSArrayFName("__NSContainer_literal"); std::string NSArrayFName("__NSContainer_literal");
FunctionDecl *NSArrayFD = SynthBlockInitFunctionDecl(NSArrayFName); FunctionDecl *NSArrayFD = SynthBlockInitFunctionDecl(NSArrayFName);
DeclRefExpr *NSArrayDRE = DeclRefExpr *NSArrayDRE =
@ -2878,8 +2871,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) {
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
QualType castType = QualType castType =
getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), getSimpleFunctionType(returnType, ArgTypes, ArrayMethod->isVariadic());
ArrayMethod->isVariadic());
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -2912,7 +2904,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral
// Build the expression: __NSContainer_literal(int, ...).arr // Build the expression: __NSContainer_literal(int, ...).arr
QualType IntQT = Context->IntTy; QualType IntQT = Context->IntTy;
QualType NSDictFType = QualType NSDictFType =
getSimpleFunctionType(Context->VoidTy, &IntQT, 1, true); getSimpleFunctionType(Context->VoidTy, IntQT, true);
std::string NSDictFName("__NSContainer_literal"); std::string NSDictFName("__NSContainer_literal");
FunctionDecl *NSDictFD = SynthBlockInitFunctionDecl(NSDictFName); FunctionDecl *NSDictFD = SynthBlockInitFunctionDecl(NSDictFName);
DeclRefExpr *NSDictDRE = DeclRefExpr *NSDictDRE =
@ -3052,8 +3044,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
QualType castType = QualType castType =
getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), getSimpleFunctionType(returnType, ArgTypes, DictMethod->isVariadic());
DictMethod->isVariadic());
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -3195,8 +3186,9 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla
SmallVectorImpl<Expr*> &MsgExprs, SmallVectorImpl<Expr*> &MsgExprs,
ObjCMethodDecl *Method) { ObjCMethodDecl *Method) {
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
QualType castType = getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), QualType castType = getSimpleFunctionType(returnType, ArgTypes,
Method ? Method->isVariadic() : false); Method ? Method->isVariadic()
: false);
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
// build type for containing the objc_msgSend_stret object. // build type for containing the objc_msgSend_stret object.
@ -3635,10 +3627,10 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
CK_BitCast, DRE); CK_BitCast, DRE);
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
// If we don't have a method decl, force a variadic cast.
const ObjCMethodDecl *MD = Exp->getMethodDecl();
QualType castType = QualType castType =
getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), getSimpleFunctionType(returnType, ArgTypes, MD ? MD->isVariadic() : true);
// If we don't have a method decl, force a variadic cast.
Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : true);
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -4744,7 +4736,7 @@ QualType RewriteModernObjC::convertFunctionTypeOfBlocks(const FunctionType *FT)
} }
QualType FuncType; QualType FuncType;
if (modified) if (modified)
FuncType = getSimpleFunctionType(Res, &ArgTypes[0], ArgTypes.size()); FuncType = getSimpleFunctionType(Res, ArgTypes);
else FuncType = QualType(FT, 0); else FuncType = QualType(FT, 0);
return FuncType; return FuncType;
} }
@ -4811,8 +4803,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp
} }
} }
// Now do the pointer to function cast. // Now do the pointer to function cast.
QualType PtrToFuncCastType QualType PtrToFuncCastType = getSimpleFunctionType(Exp->getType(), ArgTypes);
= getSimpleFunctionType(Exp->getType(), &ArgTypes[0], ArgTypes.size());
PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType); PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType);

View File

@ -485,14 +485,13 @@ namespace {
} }
QualType getSimpleFunctionType(QualType result, QualType getSimpleFunctionType(QualType result,
const QualType *args, ArrayRef<QualType> args,
unsigned numArgs,
bool variadic = false) { bool variadic = false) {
if (result == Context->getObjCInstanceType()) if (result == Context->getObjCInstanceType())
result = Context->getObjCIdType(); result = Context->getObjCIdType();
FunctionProtoType::ExtProtoInfo fpi; FunctionProtoType::ExtProtoInfo fpi;
fpi.Variadic = variadic; fpi.Variadic = variadic;
return Context->getFunctionType(result, args, numArgs, fpi); return Context->getFunctionType(result, args, fpi);
} }
// Helper function: create a CStyleCastExpr with trivial type source info. // Helper function: create a CStyleCastExpr with trivial type source info.
@ -2263,7 +2262,7 @@ void RewriteObjC::SynthSelGetUidFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getFuncType = QualType getFuncType =
getSimpleFunctionType(Context->getObjCSelType(), &ArgTys[0], ArgTys.size()); getSimpleFunctionType(Context->getObjCSelType(), ArgTys);
SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl, SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2359,7 +2358,7 @@ void RewriteObjC::SynthSuperContructorFunctionDecl() {
ArgTys.push_back(argT); ArgTys.push_back(argT);
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size()); ArgTys);
SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl, SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2378,8 +2377,7 @@ void RewriteObjC::SynthMsgSendFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2401,8 +2399,7 @@ void RewriteObjC::SynthMsgSendSuperFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2421,8 +2418,7 @@ void RewriteObjC::SynthMsgSendStretFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2446,8 +2442,7 @@ void RewriteObjC::SynthMsgSendSuperStretFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2467,8 +2462,7 @@ void RewriteObjC::SynthMsgSendFpretFunctionDecl() {
assert(!argT.isNull() && "Can't find 'SEL' type"); assert(!argT.isNull() && "Can't find 'SEL' type");
ArgTys.push_back(argT); ArgTys.push_back(argT);
QualType msgSendType = getSimpleFunctionType(Context->DoubleTy, QualType msgSendType = getSimpleFunctionType(Context->DoubleTy,
&ArgTys[0], ArgTys.size(), ArgTys, /*isVariadic=*/true);
true /*isVariadic*/);
MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl, MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2482,7 +2476,7 @@ void RewriteObjC::SynthGetClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getClassType = getSimpleFunctionType(Context->getObjCIdType(), QualType getClassType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2497,7 +2491,7 @@ void RewriteObjC::SynthGetSuperClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getObjCClassType()); ArgTys.push_back(Context->getObjCClassType());
QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetSuperClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetSuperClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2512,7 +2506,7 @@ void RewriteObjC::SynthGetMetaClassFunctionDecl() {
SmallVector<QualType, 16> ArgTys; SmallVector<QualType, 16> ArgTys;
ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst()));
QualType getClassType = getSimpleFunctionType(Context->getObjCIdType(), QualType getClassType = getSimpleFunctionType(Context->getObjCIdType(),
&ArgTys[0], ArgTys.size()); ArgTys);
GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl, GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(), SourceLocation(),
SourceLocation(), SourceLocation(),
@ -2642,8 +2636,9 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo
Context->getPointerType(Context->VoidTy), Context->getPointerType(Context->VoidTy),
CK_BitCast, STDRE); CK_BitCast, STDRE);
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
QualType castType = getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), QualType castType = getSimpleFunctionType(returnType, ArgTypes,
Method ? Method->isVariadic() : false); Method ? Method->isVariadic()
: false);
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -3024,10 +3019,10 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
CK_BitCast, DRE); CK_BitCast, DRE);
// Now do the "normal" pointer to function cast. // Now do the "normal" pointer to function cast.
// If we don't have a method decl, force a variadic cast.
const ObjCMethodDecl *MD = Exp->getMethodDecl();
QualType castType = QualType castType =
getSimpleFunctionType(returnType, &ArgTypes[0], ArgTypes.size(), getSimpleFunctionType(returnType, ArgTypes, MD ? MD->isVariadic() : true);
// If we don't have a method decl, force a variadic cast.
Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : true);
castType = Context->getPointerType(castType); castType = Context->getPointerType(castType);
cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast, cast = NoTypeInfoCStyleCastExpr(Context, castType, CK_BitCast,
cast); cast);
@ -3806,7 +3801,7 @@ QualType RewriteObjC::convertFunctionTypeOfBlocks(const FunctionType *FT) {
// FIXME. Does this work if block takes no argument but has a return type // FIXME. Does this work if block takes no argument but has a return type
// which is of block type? // which is of block type?
if (HasBlockType) if (HasBlockType)
FuncType = getSimpleFunctionType(Res, &ArgTypes[0], ArgTypes.size()); FuncType = getSimpleFunctionType(Res, ArgTypes);
else FuncType = QualType(FT, 0); else FuncType = QualType(FT, 0);
return FuncType; return FuncType;
} }
@ -3873,8 +3868,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) {
} }
} }
// Now do the pointer to function cast. // Now do the pointer to function cast.
QualType PtrToFuncCastType QualType PtrToFuncCastType = getSimpleFunctionType(Exp->getType(), ArgTypes);
= getSimpleFunctionType(Exp->getType(), &ArgTypes[0], ArgTypes.size());
PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType); PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType);

View File

@ -2563,7 +2563,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S) {
SmallVector<QualType, 16> ParamTypes(OldProto->arg_type_begin(), SmallVector<QualType, 16> ParamTypes(OldProto->arg_type_begin(),
OldProto->arg_type_end()); OldProto->arg_type_end());
NewQType = Context.getFunctionType(NewFuncType->getResultType(), NewQType = Context.getFunctionType(NewFuncType->getResultType(),
ParamTypes.data(), ParamTypes.size(), ParamTypes,
OldProto->getExtProtoInfo()); OldProto->getExtProtoInfo());
New->setType(NewQType); New->setType(NewQType);
New->setHasInheritedPrototype(); New->setHasInheritedPrototype();
@ -2646,8 +2646,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S) {
diag::note_previous_declaration); diag::note_previous_declaration);
} }
New->setType(Context.getFunctionType(MergedReturn, &ArgTypes[0], New->setType(Context.getFunctionType(MergedReturn, ArgTypes,
ArgTypes.size(),
OldProto->getExtProtoInfo())); OldProto->getExtProtoInfo()));
return MergeCompatibleFunctionDecls(New, Old, S); return MergeCompatibleFunctionDecls(New, Old, S);
} }
@ -5701,8 +5700,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
T = Context.getObjCObjectPointerType(T); T = Context.getObjCObjectPointerType(T);
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(R)) { if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(R)) {
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
R = Context.getFunctionType(T, FPT->arg_type_begin(), R = Context.getFunctionType(T,
FPT->getNumArgs(), EPI); ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs()),
EPI);
} }
else if (isa<FunctionNoProtoType>(R)) else if (isa<FunctionNoProtoType>(R))
R = Context.getFunctionNoProtoType(T); R = Context.getFunctionNoProtoType(T);
@ -5997,8 +5998,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.ExceptionSpecType = EST_BasicNoexcept; EPI.ExceptionSpecType = EST_BasicNoexcept;
NewFD->setType(Context.getFunctionType(FPT->getResultType(), NewFD->setType(Context.getFunctionType(FPT->getResultType(),
FPT->arg_type_begin(), ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs(), EPI)); FPT->getNumArgs()),
EPI));
} }
} }
@ -6382,7 +6384,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
EPI.Variadic = true; EPI.Variadic = true;
EPI.ExtInfo = FT->getExtInfo(); EPI.ExtInfo = FT->getExtInfo();
QualType R = Context.getFunctionType(FT->getResultType(), 0, 0, EPI); QualType R = Context.getFunctionType(FT->getResultType(),
ArrayRef<QualType>(),
EPI);
NewFD->setType(R); NewFD->setType(R);
} }
@ -6583,8 +6587,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.TypeQuals |= Qualifiers::Const; EPI.TypeQuals |= Qualifiers::Const;
MD->setType(Context.getFunctionType(FPT->getResultType(), MD->setType(Context.getFunctionType(FPT->getResultType(),
FPT->arg_type_begin(), ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs(), EPI)); FPT->getNumArgs()),
EPI));
} }
} }

View File

@ -4194,8 +4194,10 @@ updateExceptionSpec(Sema &S, FunctionDecl *FD, const FunctionProtoType *FPT,
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
ExceptSpec.getEPI(EPI); ExceptSpec.getEPI(EPI);
const FunctionProtoType *NewFPT = cast<FunctionProtoType>( const FunctionProtoType *NewFPT = cast<FunctionProtoType>(
S.Context.getFunctionType(FPT->getResultType(), FPT->arg_type_begin(), S.Context.getFunctionType(FPT->getResultType(),
FPT->getNumArgs(), EPI)); ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs()),
EPI));
FD->setType(QualType(NewFPT, 0)); FD->setType(QualType(NewFPT, 0));
} }
@ -4357,8 +4359,10 @@ void Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD) {
FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo();
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = MD; EPI.ExceptionSpecDecl = MD;
MD->setType(Context.getFunctionType(ReturnType, &ArgType, MD->setType(Context.getFunctionType(ReturnType,
ExpectedParams, EPI)); ArrayRef<QualType>(&ArgType,
ExpectedParams),
EPI));
} }
if (ShouldDeleteSpecialMember(MD, CSM)) { if (ShouldDeleteSpecialMember(MD, CSM)) {
@ -4387,7 +4391,7 @@ void Sema::CheckExplicitlyDefaultedMemberExceptionSpec(
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
computeImplicitExceptionSpec(*this, MD->getLocation(), MD).getEPI(EPI); computeImplicitExceptionSpec(*this, MD->getLocation(), MD).getEPI(EPI);
const FunctionProtoType *ImplicitType = cast<FunctionProtoType>( const FunctionProtoType *ImplicitType = cast<FunctionProtoType>(
Context.getFunctionType(Context.VoidTy, 0, 0, EPI)); Context.getFunctionType(Context.VoidTy, ArrayRef<QualType>(), EPI));
// Ensure that it matches. // Ensure that it matches.
CheckEquivalentExceptionSpec( CheckEquivalentExceptionSpec(
@ -5640,8 +5644,10 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R,
EPI.TypeQuals = 0; EPI.TypeQuals = 0;
EPI.RefQualifier = RQ_None; EPI.RefQualifier = RQ_None;
return Context.getFunctionType(Context.VoidTy, Proto->arg_type_begin(), return Context.getFunctionType(Context.VoidTy,
Proto->getNumArgs(), EPI); ArrayRef<QualType>(Proto->arg_type_begin(),
Proto->getNumArgs()),
EPI);
} }
/// CheckConstructor - Checks a fully-formed constructor for /// CheckConstructor - Checks a fully-formed constructor for
@ -5821,7 +5827,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R,
EPI.Variadic = false; EPI.Variadic = false;
EPI.TypeQuals = 0; EPI.TypeQuals = 0;
EPI.RefQualifier = RQ_None; EPI.RefQualifier = RQ_None;
return Context.getFunctionType(Context.VoidTy, 0, 0, EPI); return Context.getFunctionType(Context.VoidTy, ArrayRef<QualType>(), EPI);
} }
/// CheckConversionDeclarator - Called by ActOnDeclarator to check the /// CheckConversionDeclarator - Called by ActOnDeclarator to check the
@ -5902,7 +5908,8 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
// of the errors above fired) and with the conversion type as the // of the errors above fired) and with the conversion type as the
// return type. // return type.
if (D.isInvalidType()) if (D.isInvalidType())
R = Context.getFunctionType(ConvType, 0, 0, Proto->getExtProtoInfo()); R = Context.getFunctionType(ConvType, ArrayRef<QualType>(),
Proto->getExtProtoInfo());
// C++0x explicit conversion operators. // C++0x explicit conversion operators.
if (D.getDeclSpec().isExplicitSpecified()) if (D.getDeclSpec().isExplicitSpecified())
@ -7532,7 +7539,9 @@ CXXConstructorDecl *Sema::DeclareImplicitDefaultConstructor(
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = DefaultCon; EPI.ExceptionSpecDecl = DefaultCon;
DefaultCon->setType(Context.getFunctionType(Context.VoidTy, 0, 0, EPI)); DefaultCon->setType(Context.getFunctionType(Context.VoidTy,
ArrayRef<QualType>(),
EPI));
// We don't need to use SpecialMemberIsTrivial here; triviality for default // We don't need to use SpecialMemberIsTrivial here; triviality for default
// constructors is easy to compute. // constructors is easy to compute.
@ -7697,7 +7706,7 @@ void Sema::DeclareInheritedConstructors(CXXRecordDecl *ClassDecl) {
BaseCtorType->getExtProtoInfo(); BaseCtorType->getExtProtoInfo();
ExtInfo.Variadic = false; ExtInfo.Variadic = false;
NewCtorType = Context.getFunctionType(BaseCtorType->getResultType(), NewCtorType = Context.getFunctionType(BaseCtorType->getResultType(),
Args.data(), params, ExtInfo) Args, ExtInfo)
.getTypePtr(); .getTypePtr();
} }
const Type *CanonicalNewCtorType = const Type *CanonicalNewCtorType =
@ -7843,7 +7852,9 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(CXXRecordDecl *ClassDecl) {
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = Destructor; EPI.ExceptionSpecDecl = Destructor;
Destructor->setType(Context.getFunctionType(Context.VoidTy, 0, 0, EPI)); Destructor->setType(Context.getFunctionType(Context.VoidTy,
ArrayRef<QualType>(),
EPI));
AddOverriddenMethods(ClassDecl, Destructor); AddOverriddenMethods(ClassDecl, Destructor);
@ -7947,7 +7958,9 @@ void Sema::AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
FunctionProtoType::ExtProtoInfo EPI = DtorType->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = DtorType->getExtProtoInfo();
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = Destructor; EPI.ExceptionSpecDecl = Destructor;
Destructor->setType(Context.getFunctionType(Context.VoidTy, 0, 0, EPI)); Destructor->setType(Context.getFunctionType(Context.VoidTy,
ArrayRef<QualType>(),
EPI));
// FIXME: If the destructor has a body that could throw, and the newly created // FIXME: If the destructor has a body that could throw, and the newly created
// spec doesn't allow exceptions, we should emit a warning, because this // spec doesn't allow exceptions, we should emit a warning, because this
@ -8347,7 +8360,7 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = CopyAssignment; EPI.ExceptionSpecDecl = CopyAssignment;
CopyAssignment->setType(Context.getFunctionType(RetType, &ArgType, 1, EPI)); CopyAssignment->setType(Context.getFunctionType(RetType, ArgType, EPI));
// Add the parameter to the operator. // Add the parameter to the operator.
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment, ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment,
@ -8797,7 +8810,7 @@ CXXMethodDecl *Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = MoveAssignment; EPI.ExceptionSpecDecl = MoveAssignment;
MoveAssignment->setType(Context.getFunctionType(RetType, &ArgType, 1, EPI)); MoveAssignment->setType(Context.getFunctionType(RetType, ArgType, EPI));
// Add the parameter to the operator. // Add the parameter to the operator.
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, MoveAssignment, ParmVarDecl *FromParam = ParmVarDecl::Create(Context, MoveAssignment,
@ -9151,7 +9164,7 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = CopyConstructor; EPI.ExceptionSpecDecl = CopyConstructor;
CopyConstructor->setType( CopyConstructor->setType(
Context.getFunctionType(Context.VoidTy, &ArgType, 1, EPI)); Context.getFunctionType(Context.VoidTy, ArgType, EPI));
// Add the parameter to the constructor. // Add the parameter to the constructor.
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyConstructor, ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyConstructor,
@ -9338,7 +9351,7 @@ CXXConstructorDecl *Sema::DeclareImplicitMoveConstructor(
EPI.ExceptionSpecType = EST_Unevaluated; EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = MoveConstructor; EPI.ExceptionSpecDecl = MoveConstructor;
MoveConstructor->setType( MoveConstructor->setType(
Context.getFunctionType(Context.VoidTy, &ArgType, 1, EPI)); Context.getFunctionType(Context.VoidTy, ArgType, EPI));
// Add the parameter to the constructor. // Add the parameter to the constructor.
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, MoveConstructor, ParmVarDecl *FromParam = ParmVarDecl::Create(Context, MoveConstructor,

View File

@ -203,10 +203,11 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
Old->isExternC()) { Old->isExternC()) {
FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = NewProto->getExtProtoInfo();
EPI.ExceptionSpecType = EST_DynamicNone; EPI.ExceptionSpecType = EST_DynamicNone;
QualType NewType = Context.getFunctionType(NewProto->getResultType(), QualType NewType =
NewProto->arg_type_begin(), Context.getFunctionType(NewProto->getResultType(),
NewProto->getNumArgs(), ArrayRef<QualType>(NewProto->arg_type_begin(),
EPI); NewProto->getNumArgs()),
EPI);
New->setType(NewType); New->setType(NewType);
return false; return false;
} }
@ -227,10 +228,11 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
// Update the type of the function with the appropriate exception // Update the type of the function with the appropriate exception
// specification. // specification.
QualType NewType = Context.getFunctionType(NewProto->getResultType(), QualType NewType =
NewProto->arg_type_begin(), Context.getFunctionType(NewProto->getResultType(),
NewProto->getNumArgs(), ArrayRef<QualType>(NewProto->arg_type_begin(),
EPI); NewProto->getNumArgs()),
EPI);
New->setType(NewType); New->setType(NewType);
// If exceptions are disabled, suppress the warning about missing // If exceptions are disabled, suppress the warning about missing

View File

@ -9485,8 +9485,7 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.HasTrailingReturn = false; EPI.HasTrailingReturn = false;
EPI.TypeQuals |= DeclSpec::TQ_const; EPI.TypeQuals |= DeclSpec::TQ_const;
T = Context.getFunctionType(Context.DependentTy, /*Args=*/0, /*NumArgs=*/0, T = Context.getFunctionType(Context.DependentTy, ArrayRef<QualType>(), EPI);
EPI);
Sig = Context.getTrivialTypeSourceInfo(T); Sig = Context.getTrivialTypeSourceInfo(T);
} }
@ -9665,7 +9664,7 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
if (isa<FunctionNoProtoType>(FTy)) { if (isa<FunctionNoProtoType>(FTy)) {
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExtInfo = Ext; EPI.ExtInfo = Ext;
BlockTy = Context.getFunctionType(RetTy, 0, 0, EPI); BlockTy = Context.getFunctionType(RetTy, ArrayRef<QualType>(), EPI);
// Otherwise, if we don't need to change anything about the function type, // Otherwise, if we don't need to change anything about the function type,
// preserve its sugar structure. // preserve its sugar structure.
@ -9679,17 +9678,18 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.TypeQuals = 0; // FIXME: silently? EPI.TypeQuals = 0; // FIXME: silently?
EPI.ExtInfo = Ext; EPI.ExtInfo = Ext;
BlockTy = Context.getFunctionType(RetTy, BlockTy =
FPT->arg_type_begin(), Context.getFunctionType(RetTy,
FPT->getNumArgs(), ArrayRef<QualType>(FPT->arg_type_begin(),
EPI); FPT->getNumArgs()),
EPI);
} }
// If we don't have a function type, just build one from nothing. // If we don't have a function type, just build one from nothing.
} else { } else {
FunctionProtoType::ExtProtoInfo EPI; FunctionProtoType::ExtProtoInfo EPI;
EPI.ExtInfo = FunctionType::ExtInfo().withNoReturn(NoReturn); EPI.ExtInfo = FunctionType::ExtInfo().withNoReturn(NoReturn);
BlockTy = Context.getFunctionType(RetTy, 0, 0, EPI); BlockTy = Context.getFunctionType(RetTy, ArrayRef<QualType>(), EPI);
} }
DiagnoseUnusedParameters(BSI->TheDecl->param_begin(), DiagnoseUnusedParameters(BSI->TheDecl->param_begin(),
@ -11845,10 +11845,11 @@ ExprResult RebuildUnknownAnyExpr::VisitCallExpr(CallExpr *E) {
// Rebuild the function type, replacing the result type with DestType. // Rebuild the function type, replacing the result type with DestType.
if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FnType)) if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FnType))
DestType = S.Context.getFunctionType(DestType, DestType =
Proto->arg_type_begin(), S.Context.getFunctionType(DestType,
Proto->getNumArgs(), ArrayRef<QualType>(Proto->arg_type_begin(),
Proto->getExtProtoInfo()); Proto->getNumArgs()),
Proto->getExtProtoInfo());
else else
DestType = S.Context.getFunctionNoProtoType(DestType, DestType = S.Context.getFunctionNoProtoType(DestType,
FnType->getExtInfo()); FnType->getExtInfo());

View File

@ -1595,8 +1595,7 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
EPI.Variadic = Proto->isVariadic(); EPI.Variadic = Proto->isVariadic();
ExpectedFunctionType ExpectedFunctionType
= Context.getFunctionType(Context.VoidTy, ArgTypes.data(), = Context.getFunctionType(Context.VoidTy, ArgTypes, EPI);
ArgTypes.size(), EPI);
} }
for (LookupResult::iterator D = FoundDelete.begin(), for (LookupResult::iterator D = FoundDelete.begin(),
@ -1898,7 +1897,7 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
EST_BasicNoexcept : EST_DynamicNone; EST_BasicNoexcept : EST_DynamicNone;
} }
QualType FnType = Context.getFunctionType(Return, &Argument, 1, EPI); QualType FnType = Context.getFunctionType(Return, Argument, EPI);
FunctionDecl *Alloc = FunctionDecl *Alloc =
FunctionDecl::Create(Context, GlobalCtx, SourceLocation(), FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
SourceLocation(), Name, SourceLocation(), Name,

View File

@ -385,7 +385,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
EPI.HasTrailingReturn = true; EPI.HasTrailingReturn = true;
EPI.TypeQuals |= DeclSpec::TQ_const; EPI.TypeQuals |= DeclSpec::TQ_const;
QualType MethodTy = Context.getFunctionType(Context.DependentTy, QualType MethodTy = Context.getFunctionType(Context.DependentTy,
/*Args=*/0, /*NumArgs=*/0, EPI); ArrayRef<QualType>(),
EPI);
MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy); MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy);
ExplicitParams = false; ExplicitParams = false;
ExplicitResultType = false; ExplicitResultType = false;
@ -628,16 +629,18 @@ static void addFunctionPointerConversion(Sema &S,
{ {
FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
ExtInfo.TypeQuals = 0; ExtInfo.TypeQuals = 0;
FunctionTy = S.Context.getFunctionType(Proto->getResultType(), FunctionTy =
Proto->arg_type_begin(), S.Context.getFunctionType(Proto->getResultType(),
Proto->getNumArgs(), ArrayRef<QualType>(Proto->arg_type_begin(),
ExtInfo); Proto->getNumArgs()),
ExtInfo);
FunctionPtrTy = S.Context.getPointerType(FunctionTy); FunctionPtrTy = S.Context.getPointerType(FunctionTy);
} }
FunctionProtoType::ExtProtoInfo ExtInfo; FunctionProtoType::ExtProtoInfo ExtInfo;
ExtInfo.TypeQuals = Qualifiers::Const; ExtInfo.TypeQuals = Qualifiers::Const;
QualType ConvTy = S.Context.getFunctionType(FunctionPtrTy, 0, 0, ExtInfo); QualType ConvTy =
S.Context.getFunctionType(FunctionPtrTy, ArrayRef<QualType>(), ExtInfo);
SourceLocation Loc = IntroducerRange.getBegin(); SourceLocation Loc = IntroducerRange.getBegin();
DeclarationName Name DeclarationName Name
@ -701,15 +704,16 @@ static void addBlockPointerConversion(Sema &S,
ExtInfo.TypeQuals = 0; ExtInfo.TypeQuals = 0;
QualType FunctionTy QualType FunctionTy
= S.Context.getFunctionType(Proto->getResultType(), = S.Context.getFunctionType(Proto->getResultType(),
Proto->arg_type_begin(), ArrayRef<QualType>(Proto->arg_type_begin(),
Proto->getNumArgs(), Proto->getNumArgs()),
ExtInfo); ExtInfo);
BlockPtrTy = S.Context.getBlockPointerType(FunctionTy); BlockPtrTy = S.Context.getBlockPointerType(FunctionTy);
} }
FunctionProtoType::ExtProtoInfo ExtInfo; FunctionProtoType::ExtProtoInfo ExtInfo;
ExtInfo.TypeQuals = Qualifiers::Const; ExtInfo.TypeQuals = Qualifiers::Const;
QualType ConvTy = S.Context.getFunctionType(BlockPtrTy, 0, 0, ExtInfo); QualType ConvTy = S.Context.getFunctionType(BlockPtrTy, ArrayRef<QualType>(),
ExtInfo);
SourceLocation Loc = IntroducerRange.getBegin(); SourceLocation Loc = IntroducerRange.getBegin();
DeclarationName Name DeclarationName Name
@ -821,8 +825,8 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
= CallOperator->getType()->getAs<FunctionProtoType>(); = CallOperator->getType()->getAs<FunctionProtoType>();
QualType FunctionTy QualType FunctionTy
= Context.getFunctionType(LSI->ReturnType, = Context.getFunctionType(LSI->ReturnType,
Proto->arg_type_begin(), ArrayRef<QualType>(Proto->arg_type_begin(),
Proto->getNumArgs(), Proto->getNumArgs()),
Proto->getExtProtoInfo()); Proto->getExtProtoInfo());
CallOperator->setType(FunctionTy); CallOperator->setType(FunctionTy);
} }

View File

@ -722,7 +722,7 @@ static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC) {
EPI.NumExceptions = 0; EPI.NumExceptions = 0;
QualType ExpectedType QualType ExpectedType
= R.getSema().Context.getFunctionType(R.getLookupName().getCXXNameType(), = R.getSema().Context.getFunctionType(R.getLookupName().getCXXNameType(),
0, 0, EPI); ArrayRef<QualType>(), EPI);
// Perform template argument deduction against the type that we would // Perform template argument deduction against the type that we would
// expect the function to have. // expect the function to have.

View File

@ -5946,8 +5946,9 @@ Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD,
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.TypeQuals |= Qualifiers::Const; EPI.TypeQuals |= Qualifiers::Const;
FT = Context.getFunctionType(FPT->getResultType(), FT = Context.getFunctionType(FPT->getResultType(),
FPT->arg_type_begin(), ArrayRef<QualType>(FPT->arg_type_begin(),
FPT->getNumArgs(), EPI); FPT->getNumArgs()),
EPI);
} }
} }

View File

@ -2417,8 +2417,7 @@ Sema::SubstituteExplicitTemplateArguments(
return TDK_SubstitutionFailure; return TDK_SubstitutionFailure;
if (FunctionType) { if (FunctionType) {
*FunctionType = BuildFunctionType(ResultType, *FunctionType = BuildFunctionType(ResultType, ParamTypes,
ParamTypes.data(), ParamTypes.size(),
Proto->isVariadic(), Proto->isVariadic(),
Proto->hasTrailingReturn(), Proto->hasTrailingReturn(),
Proto->getTypeQuals(), Proto->getTypeQuals(),

View File

@ -1090,8 +1090,8 @@ static QualType adjustFunctionTypeForInstantiation(ASTContext &Context,
FunctionProtoType::ExtProtoInfo NewEPI = NewFunc->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo NewEPI = NewFunc->getExtProtoInfo();
NewEPI.ExtInfo = OrigFunc->getExtInfo(); NewEPI.ExtInfo = OrigFunc->getExtInfo();
return Context.getFunctionType(NewFunc->getResultType(), return Context.getFunctionType(NewFunc->getResultType(),
NewFunc->arg_type_begin(), ArrayRef<QualType>(NewFunc->arg_type_begin(),
NewFunc->getNumArgs(), NewFunc->getNumArgs()),
NewEPI); NewEPI);
} }
@ -2585,8 +2585,8 @@ static void InstantiateExceptionSpec(Sema &SemaRef, FunctionDecl *New,
EPI.NoexceptExpr = NoexceptExpr; EPI.NoexceptExpr = NoexceptExpr;
New->setType(SemaRef.Context.getFunctionType(NewProto->getResultType(), New->setType(SemaRef.Context.getFunctionType(NewProto->getResultType(),
NewProto->arg_type_begin(), ArrayRef<QualType>(NewProto->arg_type_begin(),
NewProto->getNumArgs(), NewProto->getNumArgs()),
EPI)); EPI));
} }
@ -2604,8 +2604,8 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo(); FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
EPI.ExceptionSpecType = EST_None; EPI.ExceptionSpecType = EST_None;
Decl->setType(Context.getFunctionType(Proto->getResultType(), Decl->setType(Context.getFunctionType(Proto->getResultType(),
Proto->arg_type_begin(), ArrayRef<QualType>(Proto->arg_type_begin(),
Proto->getNumArgs(), Proto->getNumArgs()),
EPI)); EPI));
return; return;
} }
@ -2685,8 +2685,8 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
EPI.ExceptionSpecDecl = New; EPI.ExceptionSpecDecl = New;
EPI.ExceptionSpecTemplate = ExceptionSpecTemplate; EPI.ExceptionSpecTemplate = ExceptionSpecTemplate;
New->setType(SemaRef.Context.getFunctionType(NewProto->getResultType(), New->setType(SemaRef.Context.getFunctionType(NewProto->getResultType(),
NewProto->arg_type_begin(), ArrayRef<QualType>(NewProto->arg_type_begin(),
NewProto->getNumArgs(), NewProto->getNumArgs()),
EPI)); EPI));
} else { } else {
::InstantiateExceptionSpec(SemaRef, New, Proto, TemplateArgs); ::InstantiateExceptionSpec(SemaRef, New, Proto, TemplateArgs);

View File

@ -1630,40 +1630,8 @@ QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize,
return Context.getDependentSizedExtVectorType(T, ArraySize, AttrLoc); return Context.getDependentSizedExtVectorType(T, ArraySize, AttrLoc);
} }
/// \brief Build a function type.
///
/// This routine checks the function type according to C++ rules and
/// under the assumption that the result type and parameter types have
/// just been instantiated from a template. It therefore duplicates
/// some of the behavior of GetTypeForDeclarator, but in a much
/// simpler form that is only suitable for this narrow use case.
///
/// \param T The return type of the function.
///
/// \param ParamTypes The parameter types of the function. This array
/// will be modified to account for adjustments to the types of the
/// function parameters.
///
/// \param NumParamTypes The number of parameter types in ParamTypes.
///
/// \param Variadic Whether this is a variadic function type.
///
/// \param HasTrailingReturn Whether this function has a trailing return type.
///
/// \param Quals The cvr-qualifiers to be applied to the function type.
///
/// \param Loc The location of the entity whose type involves this
/// function type or, if there is no such entity, the location of the
/// type that will have function type.
///
/// \param Entity The name of the entity that involves the function
/// type, if known.
///
/// \returns A suitable function type, if there are no
/// errors. Otherwise, returns a NULL type.
QualType Sema::BuildFunctionType(QualType T, QualType Sema::BuildFunctionType(QualType T,
QualType *ParamTypes, llvm::MutableArrayRef<QualType> ParamTypes,
unsigned NumParamTypes,
bool Variadic, bool HasTrailingReturn, bool Variadic, bool HasTrailingReturn,
unsigned Quals, unsigned Quals,
RefQualifierKind RefQualifier, RefQualifierKind RefQualifier,
@ -1683,7 +1651,7 @@ QualType Sema::BuildFunctionType(QualType T,
} }
bool Invalid = false; bool Invalid = false;
for (unsigned Idx = 0; Idx < NumParamTypes; ++Idx) { for (unsigned Idx = 0, Cnt = ParamTypes.size(); Idx < Cnt; ++Idx) {
// FIXME: Loc is too inprecise here, should use proper locations for args. // FIXME: Loc is too inprecise here, should use proper locations for args.
QualType ParamType = Context.getAdjustedParameterType(ParamTypes[Idx]); QualType ParamType = Context.getAdjustedParameterType(ParamTypes[Idx]);
if (ParamType->isVoidType()) { if (ParamType->isVoidType()) {
@ -1709,7 +1677,7 @@ QualType Sema::BuildFunctionType(QualType T,
EPI.RefQualifier = RefQualifier; EPI.RefQualifier = RefQualifier;
EPI.ExtInfo = Info; EPI.ExtInfo = Info;
return Context.getFunctionType(T, ParamTypes, NumParamTypes, EPI); return Context.getFunctionType(T, ParamTypes, EPI);
} }
/// \brief Build a member pointer type \c T Class::*. /// \brief Build a member pointer type \c T Class::*.
@ -2786,7 +2754,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
Exceptions, Exceptions,
EPI); EPI);
T = Context.getFunctionType(T, ArgTys.data(), ArgTys.size(), EPI); T = Context.getFunctionType(T, ArgTys, EPI);
} }
break; break;
@ -2926,8 +2894,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
EPI.RefQualifier = RQ_None; EPI.RefQualifier = RQ_None;
T = Context.getFunctionType(FnTy->getResultType(), T = Context.getFunctionType(FnTy->getResultType(),
FnTy->arg_type_begin(), ArrayRef<QualType>(FnTy->arg_type_begin(),
FnTy->getNumArgs(), EPI); FnTy->getNumArgs()),
EPI);
// Rebuild any parens around the identifier in the function type. // Rebuild any parens around the identifier in the function type.
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
if (D.getTypeObject(i).Kind != DeclaratorChunk::Paren) if (D.getTypeObject(i).Kind != DeclaratorChunk::Paren)

View File

@ -713,8 +713,7 @@ public:
/// By default, performs semantic analysis when building the function type. /// By default, performs semantic analysis when building the function type.
/// Subclasses may override this routine to provide different behavior. /// Subclasses may override this routine to provide different behavior.
QualType RebuildFunctionProtoType(QualType T, QualType RebuildFunctionProtoType(QualType T,
QualType *ParamTypes, llvm::MutableArrayRef<QualType> ParamTypes,
unsigned NumParamTypes,
bool Variadic, bool HasTrailingReturn, bool Variadic, bool HasTrailingReturn,
unsigned Quals, unsigned Quals,
RefQualifierKind RefQualifier, RefQualifierKind RefQualifier,
@ -4266,9 +4265,7 @@ TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
ResultType != T->getResultType() || ResultType != T->getResultType() ||
T->getNumArgs() != ParamTypes.size() || T->getNumArgs() != ParamTypes.size() ||
!std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Result = getDerived().RebuildFunctionProtoType(ResultType, Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
ParamTypes.data(),
ParamTypes.size(),
T->isVariadic(), T->isVariadic(),
T->hasTrailingReturn(), T->hasTrailingReturn(),
T->getTypeQuals(), T->getTypeQuals(),
@ -8850,13 +8847,11 @@ TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
return ExprError(); return ExprError();
} }
QualType functionType = getDerived().RebuildFunctionProtoType( QualType functionType =
exprResultType, getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
paramTypes.data(), oldBlock->isVariadic(),
paramTypes.size(), false, 0, RQ_None,
oldBlock->isVariadic(), exprFunctionType->getExtInfo());
false, 0, RQ_None,
exprFunctionType->getExtInfo());
blockScope->FunctionType = functionType; blockScope->FunctionType = functionType;
// Set the parameters on the block decl. // Set the parameters on the block decl.
@ -9072,15 +9067,15 @@ TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
} }
template<typename Derived> template<typename Derived>
QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, QualType TreeTransform<Derived>::RebuildFunctionProtoType(
QualType *ParamTypes, QualType T,
unsigned NumParamTypes, llvm::MutableArrayRef<QualType> ParamTypes,
bool Variadic, bool Variadic,
bool HasTrailingReturn, bool HasTrailingReturn,
unsigned Quals, unsigned Quals,
RefQualifierKind RefQualifier, RefQualifierKind RefQualifier,
const FunctionType::ExtInfo &Info) { const FunctionType::ExtInfo &Info) {
return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, return SemaRef.BuildFunctionType(T, ParamTypes, Variadic,
HasTrailingReturn, Quals, RefQualifier, HasTrailingReturn, Quals, RefQualifier,
getDerived().getBaseLocation(), getDerived().getBaseLocation(),
getDerived().getBaseEntity(), getDerived().getBaseEntity(),

View File

@ -4395,8 +4395,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) {
} else if (EST == EST_Unevaluated) { } else if (EST == EST_Unevaluated) {
EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx);
} }
return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, return Context.getFunctionType(ResultType, ParamTypes, EPI);
EPI);
} }
case TYPE_UNRESOLVED_USING: { case TYPE_UNRESOLVED_USING: {