Correct various uses of 'argument' that in fact refer to function parameters

Cleanup only.

llvm-svn: 199773
This commit is contained in:
Alp Toker 2014-01-21 23:35:24 +00:00
parent 111d3485af
commit 601b22c377
6 changed files with 74 additions and 81 deletions

View File

@ -2887,7 +2887,7 @@ CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
CINDEX_LINKAGE CXType clang_getResultType(CXType T);
/**
* \brief Retrieve the number of non-variadic arguments associated with a
* \brief Retrieve the number of non-variadic parameters associated with a
* function type.
*
* If a non-function type is passed in, -1 is returned.
@ -2895,7 +2895,7 @@ CINDEX_LINKAGE CXType clang_getResultType(CXType T);
CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
/**
* \brief Retrieve the type of an argument of a function type.
* \brief Retrieve the type of a parameter of a function type.
*
* If a non-function type is passed in or the function does not have enough
* parameters, an invalid type is returned.

View File

@ -6950,11 +6950,8 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
if (lproto && rproto) { // two C99 style function prototypes
assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() &&
"C++ shouldn't be here");
unsigned lproto_nargs = lproto->getNumParams();
unsigned rproto_nargs = rproto->getNumParams();
// Compatible functions must have the same number of arguments
if (lproto_nargs != rproto_nargs)
// Compatible functions must have the same number of parameters
if (lproto->getNumParams() != rproto->getNumParams())
return QualType();
// Variadic and non-variadic functions aren't compatible
@ -6968,27 +6965,28 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
!FunctionTypesMatchOnNSConsumedAttrs(rproto, lproto))
return QualType();
// Check argument compatibility
// Check parameter type compatibility
SmallVector<QualType, 10> types;
for (unsigned i = 0; i < lproto_nargs; i++) {
QualType largtype = lproto->getParamType(i).getUnqualifiedType();
QualType rargtype = rproto->getParamType(i).getUnqualifiedType();
QualType argtype = mergeFunctionParameterTypes(
largtype, rargtype, OfBlockPointer, Unqualified);
if (argtype.isNull()) return QualType();
for (unsigned i = 0, n = lproto->getNumParams(); i < n; i++) {
QualType lParamType = lproto->getParamType(i).getUnqualifiedType();
QualType rParamType = rproto->getParamType(i).getUnqualifiedType();
QualType paramType = mergeFunctionParameterTypes(
lParamType, rParamType, OfBlockPointer, Unqualified);
if (paramType.isNull())
return QualType();
if (Unqualified)
argtype = argtype.getUnqualifiedType();
paramType = paramType.getUnqualifiedType();
types.push_back(argtype);
types.push_back(paramType);
if (Unqualified) {
largtype = largtype.getUnqualifiedType();
rargtype = rargtype.getUnqualifiedType();
lParamType = lParamType.getUnqualifiedType();
rParamType = rParamType.getUnqualifiedType();
}
if (getCanonicalType(argtype) != getCanonicalType(largtype))
if (getCanonicalType(paramType) != getCanonicalType(lParamType))
allLTypes = false;
if (getCanonicalType(argtype) != getCanonicalType(rargtype))
if (getCanonicalType(paramType) != getCanonicalType(rParamType))
allRTypes = false;
}
@ -7012,20 +7010,19 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
// The only types actually affected are promotable integer
// types and floats, which would be passed as a different
// type depending on whether the prototype is visible.
unsigned proto_nargs = proto->getNumParams();
for (unsigned i = 0; i < proto_nargs; ++i) {
QualType argTy = proto->getParamType(i);
for (unsigned i = 0, n = proto->getNumParams(); i < n; ++i) {
QualType paramTy = proto->getParamType(i);
// Look at the converted type of enum types, since that is the type used
// to pass enum values.
if (const EnumType *Enum = argTy->getAs<EnumType>()) {
argTy = Enum->getDecl()->getIntegerType();
if (argTy.isNull())
if (const EnumType *Enum = paramTy->getAs<EnumType>()) {
paramTy = Enum->getDecl()->getIntegerType();
if (paramTy.isNull())
return QualType();
}
if (argTy->isPromotableIntegerType() ||
getCanonicalType(argTy).getUnqualifiedType() == FloatTy)
if (paramTy->isPromotableIntegerType() ||
getCanonicalType(paramTy).getUnqualifiedType() == FloatTy)
return QualType();
}
@ -7346,10 +7343,8 @@ bool ASTContext::FunctionTypesMatchOnNSConsumedAttrs(
FunctionProtoType::ExtProtoInfo ToEPI =
ToFunctionType->getExtProtoInfo();
if (FromEPI.ConsumedParameters && ToEPI.ConsumedParameters)
for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams();
ArgIdx != NumArgs; ++ArgIdx) {
if (FromEPI.ConsumedParameters[ArgIdx] !=
ToEPI.ConsumedParameters[ArgIdx])
for (unsigned i = 0, n = FromFunctionType->getNumParams(); i != n; ++i) {
if (FromEPI.ConsumedParameters[i] != ToEPI.ConsumedParameters[i])
return false;
}
return true;

View File

@ -186,13 +186,12 @@ static bool isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT) {
return isSafeToConvert(RD, CGT, AlreadyChecked);
}
/// isFuncTypeArgumentConvertible - Return true if the specified type in a
/// function argument or result position can be converted to an IR type at this
/// isFuncParamTypeConvertible - Return true if the specified type in a
/// function parameter or result position can be converted to an IR type at this
/// point. This boils down to being whether it is complete, as well as whether
/// we've temporarily deferred expanding the type because we're in a recursive
/// context.
bool CodeGenTypes::isFuncTypeArgumentConvertible(QualType Ty) {
bool CodeGenTypes::isFuncParamTypeConvertible(QualType Ty) {
// If this isn't a tagged type, we can convert it!
const TagType *TT = Ty->getAs<TagType>();
if (TT == 0) return true;
@ -217,17 +216,17 @@ bool CodeGenTypes::isFuncTypeArgumentConvertible(QualType Ty) {
/// Code to verify a given function type is complete, i.e. the return type
/// and all of the argument types are complete. Also check to see if we are in
/// and all of the parameter types are complete. Also check to see if we are in
/// a RS_StructPointer context, and if so whether any struct types have been
/// pended. If so, we don't want to ask the ABI lowering code to handle a type
/// that cannot be converted to an IR type.
bool CodeGenTypes::isFuncTypeConvertible(const FunctionType *FT) {
if (!isFuncTypeArgumentConvertible(FT->getResultType()))
if (!isFuncParamTypeConvertible(FT->getResultType()))
return false;
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT))
for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++)
if (!isFuncTypeArgumentConvertible(FPT->getParamType(i)))
if (!isFuncParamTypeConvertible(FPT->getParamType(i)))
return false;
return true;
@ -493,7 +492,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
break;
}
// While we're converting the argument types for a function, we don't want
// While we're converting the parameter types for a function, we don't want
// to recursively convert any pointed-to structs. Converting directly-used
// structs is ok though.
if (!RecordsBeingLaidOut.insert(Ty)) {

View File

@ -136,7 +136,7 @@ public:
/// be converted to an LLVM type (i.e. doesn't depend on an incomplete tag
/// type).
bool isFuncTypeConvertible(const FunctionType *FT);
bool isFuncTypeArgumentConvertible(QualType Ty);
bool isFuncParamTypeConvertible(QualType Ty);
/// GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable,
/// given a CXXMethodDecl. If the method to has an incomplete return type,

View File

@ -67,10 +67,10 @@ static bool hasFunctionProto(const Decl *D) {
return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
}
/// getFunctionOrMethodNumArgs - Return number of function or method
/// arguments. It is an error to call this on a K&R function (use
/// getFunctionOrMethodNumParams - Return number of function or method
/// parameters. It is an error to call this on a K&R function (use
/// hasFunctionProto first).
static unsigned getFunctionOrMethodNumArgs(const Decl *D) {
static unsigned getFunctionOrMethodNumParams(const Decl *D) {
if (const FunctionType *FnTy = D->getFunctionType())
return cast<FunctionProtoType>(FnTy)->getNumParams();
if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
@ -78,7 +78,7 @@ static unsigned getFunctionOrMethodNumArgs(const Decl *D) {
return cast<ObjCMethodDecl>(D)->param_size();
}
static QualType getFunctionOrMethodArgType(const Decl *D, unsigned Idx) {
static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx) {
if (const FunctionType *FnTy = D->getFunctionType())
return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
@ -208,16 +208,15 @@ static bool checkAttrMutualExclusion(Sema &S, Decl *D,
return false;
}
/// \brief Check if IdxExpr is a valid argument index for a function or
/// \brief Check if IdxExpr is a valid parameter index for a function or
/// instance method D. May output an error.
///
/// \returns true if IdxExpr is a valid index.
static bool checkFunctionOrMethodArgumentIndex(Sema &S, const Decl *D,
static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D,
const AttributeList &Attr,
unsigned AttrArgNum,
const Expr *IdxExpr,
uint64_t &Idx)
{
uint64_t &Idx) {
assert(isFunctionOrMethod(D));
// In C++ the implicit 'this' function parameter also counts.
@ -225,8 +224,8 @@ static bool checkFunctionOrMethodArgumentIndex(Sema &S, const Decl *D,
bool HP = hasFunctionProto(D);
bool HasImplicitThisParam = isInstanceMethod(D);
bool IV = HP && isFunctionOrMethodVariadic(D);
unsigned NumArgs = (HP ? getFunctionOrMethodNumArgs(D) : 0) +
HasImplicitThisParam;
unsigned NumParams =
(HP ? getFunctionOrMethodNumParams(D) : 0) + HasImplicitThisParam;
llvm::APSInt IdxInt;
if (IdxExpr->isTypeDependent() || IdxExpr->isValueDependent() ||
@ -238,7 +237,7 @@ static bool checkFunctionOrMethodArgumentIndex(Sema &S, const Decl *D,
}
Idx = IdxInt.getLimitedValue();
if (Idx < 1 || (!IV && Idx > NumArgs)) {
if (Idx < 1 || (!IV && Idx > NumParams)) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
<< Attr.getName() << AttrArgNum << IdxExpr->getSourceRange();
return false;
@ -1193,13 +1192,13 @@ static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {
for (unsigned i = 0; i < Attr.getNumArgs(); ++i) {
Expr *Ex = Attr.getArgAsExpr(i);
uint64_t Idx;
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr, i + 1, Ex, Idx))
if (!checkFunctionOrMethodParameterIndex(S, D, Attr, i + 1, Ex, Idx))
return;
// Is the function argument a pointer type?
// FIXME: Should also highlight argument in decl in the diagnostic.
if (!attrNonNullArgCheck(S, getFunctionOrMethodArgType(D, Idx),
Attr, Ex->getSourceRange()))
if (!attrNonNullArgCheck(S, getFunctionOrMethodParamType(D, Idx), Attr,
Ex->getSourceRange()))
continue;
NonNullArgs.push_back(Idx);
@ -1208,8 +1207,8 @@ static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {
// If no arguments were specified to __attribute__((nonnull)) then all pointer
// arguments have a nonnull attribute.
if (NonNullArgs.empty()) {
for (unsigned i = 0, e = getFunctionOrMethodNumArgs(D); i != e; ++i) {
QualType T = getFunctionOrMethodArgType(D, i).getNonReferenceType();
for (unsigned i = 0, e = getFunctionOrMethodNumParams(D); i != e; ++i) {
QualType T = getFunctionOrMethodParamType(D, i).getNonReferenceType();
possibleTransparentUnionPointerType(T);
if (T->isAnyPointerType() || T->isBlockPointerType())
NonNullArgs.push_back(i);
@ -1298,11 +1297,11 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const AttributeList &AL) {
for (unsigned i = 1; i < AL.getNumArgs(); ++i) {
Expr *Ex = AL.getArgAsExpr(i);
uint64_t Idx;
if (!checkFunctionOrMethodArgumentIndex(S, D, AL, i, Ex, Idx))
if (!checkFunctionOrMethodParameterIndex(S, D, AL, i, Ex, Idx))
return;
// Is the function argument a pointer type?
QualType T = getFunctionOrMethodArgType(D, Idx);
QualType T = getFunctionOrMethodParamType(D, Idx);
int Err = -1; // No error
switch (K) {
case OwnershipAttr::Takes:
@ -2363,12 +2362,12 @@ static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
/// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
static void handleFormatArgAttr(Sema &S, Decl *D, const AttributeList &Attr) {
Expr *IdxExpr = Attr.getArgAsExpr(0);
uint64_t ArgIdx;
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr, 1, IdxExpr, ArgIdx))
uint64_t Idx;
if (!checkFunctionOrMethodParameterIndex(S, D, Attr, 1, IdxExpr, Idx))
return;
// make sure the format string is really a string
QualType Ty = getFunctionOrMethodArgType(D, ArgIdx);
QualType Ty = getFunctionOrMethodParamType(D, Idx);
bool not_nsstring_type = !isNSStringType(Ty, S.Context);
if (not_nsstring_type &&
@ -2393,7 +2392,7 @@ static void handleFormatArgAttr(Sema &S, Decl *D, const AttributeList &Attr) {
return;
}
// We cannot use the ArgIdx returned from checkFunctionOrMethodArgumentIndex
// We cannot use the Idx returned from checkFunctionOrMethodParameterIndex
// because that has corrected for the implicit this parameter, and is zero-
// based. The attribute expects what the user wrote explicitly.
llvm::APSInt Val;
@ -2509,7 +2508,7 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
// In C++ the implicit 'this' function parameter also counts, and they are
// counted from one.
bool HasImplicitThisParam = isInstanceMethod(D);
unsigned NumArgs = getFunctionOrMethodNumArgs(D) + HasImplicitThisParam;
unsigned NumArgs = getFunctionOrMethodNumParams(D) + HasImplicitThisParam;
IdentifierInfo *II = Attr.getArgAsIdent(0)->Ident;
StringRef Format = II->getName();
@ -2559,7 +2558,7 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
}
// make sure the format string is really a string
QualType Ty = getFunctionOrMethodArgType(D, ArgIdx);
QualType Ty = getFunctionOrMethodParamType(D, ArgIdx);
if (Kind == CFStringFormat) {
if (!isCFStringType(Ty, S.Context)) {
@ -3271,19 +3270,19 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D,
}
uint64_t ArgumentIdx;
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr, 2, Attr.getArgAsExpr(1),
if (!checkFunctionOrMethodParameterIndex(S, D, Attr, 2, Attr.getArgAsExpr(1),
ArgumentIdx))
return;
uint64_t TypeTagIdx;
if (!checkFunctionOrMethodArgumentIndex(S, D, Attr, 3, Attr.getArgAsExpr(2),
if (!checkFunctionOrMethodParameterIndex(S, D, Attr, 3, Attr.getArgAsExpr(2),
TypeTagIdx))
return;
bool IsPointer = (Attr.getName()->getName() == "pointer_with_type_tag");
if (IsPointer) {
// Ensure that buffer has a pointer type.
QualType BufferTy = getFunctionOrMethodArgType(D, ArgumentIdx);
QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
if (!BufferTy->isPointerType()) {
S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only)
<< Attr.getName();

View File

@ -554,8 +554,8 @@ CXType clang_getArgType(CXType X, unsigned i) {
return MakeCXType(QualType(), GetTU(X));
if (const FunctionProtoType *FD = T->getAs<FunctionProtoType>()) {
unsigned numArgs = FD->getNumParams();
if (i >= numArgs)
unsigned numParams = FD->getNumParams();
if (i >= numParams)
return MakeCXType(QualType(), GetTU(X));
return MakeCXType(FD->getParamType(i), GetTU(X));