From: Alp Toker Date: Tue, 21 Jan 2014 23:35:24 +0000 (+0000) Subject: Correct various uses of 'argument' that in fact refer to function parameters X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e5a73f4d3d429d0fda24b364d851e7fe32de6a9;p=clang Correct various uses of 'argument' that in fact refer to function parameters Cleanup only. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199773 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 4c5256cd4e..34c8fc1d2b 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -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. diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 7665f32e67..acff54bba2 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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 @@ -6967,28 +6964,29 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, if (LangOpts.ObjCAutoRefCount && !FunctionTypesMatchOnNSConsumedAttrs(rproto, lproto)) return QualType(); - - // Check argument compatibility + + // Check parameter type compatibility SmallVector 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(); - - types.push_back(argtype); + paramType = paramType.getUnqualifiedType(); + + 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()) { - argTy = Enum->getDecl()->getIntegerType(); - if (argTy.isNull()) + if (const EnumType *Enum = paramTy->getAs()) { + 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; diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 921f02f8d7..02b3a10fa5 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -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(); 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(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)) { diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h index 94ca9e21e5..9b7797cb8e 100644 --- a/lib/CodeGen/CodeGenTypes.h +++ b/lib/CodeGen/CodeGenTypes.h @@ -136,8 +136,8 @@ 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, /// and/or incomplete argument types, this will return the opaque type. diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index c706ab6ff0..8af151e78d 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -67,10 +67,10 @@ static bool hasFunctionProto(const Decl *D) { return isa(D) || isa(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(FnTy)->getNumParams(); if (const BlockDecl *BD = dyn_cast(D)) @@ -78,7 +78,7 @@ static unsigned getFunctionOrMethodNumArgs(const Decl *D) { return cast(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(FnTy)->getParamType(Idx); if (const BlockDecl *BD = dyn_cast(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, - const AttributeList &Attr, - unsigned AttrArgNum, - const Expr *IdxExpr, - uint64_t &Idx) -{ +static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D, + const AttributeList &Attr, + unsigned AttrArgNum, + const Expr *IdxExpr, + 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), - ArgumentIdx)) + if (!checkFunctionOrMethodParameterIndex(S, D, Attr, 2, Attr.getArgAsExpr(1), + ArgumentIdx)) return; uint64_t TypeTagIdx; - if (!checkFunctionOrMethodArgumentIndex(S, D, Attr, 3, Attr.getArgAsExpr(2), - TypeTagIdx)) + 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(); diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index c053d6c40d..5007047ea6 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -554,8 +554,8 @@ CXType clang_getArgType(CXType X, unsigned i) { return MakeCXType(QualType(), GetTU(X)); if (const FunctionProtoType *FD = T->getAs()) { - 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));