Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Clang] [NFC] Rename isAnyPointerType() and getPointeeOrArrayElementType(). #122938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt,
if (T.isVolatileQualified())
return true;

if (!T->isAnyPointerType() && !T->isReferenceType())
if (!T->isPointerOrObjCObjectPointerType() && !T->isReferenceType())
break;

T = T->getPointeeType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void SuspiciousMemoryComparisonCheck::check(
for (unsigned int ArgIndex = 0; ArgIndex < 2; ++ArgIndex) {
const Expr *ArgExpr = CE->getArg(ArgIndex);
QualType ArgType = ArgExpr->IgnoreImplicit()->getType();
const Type *PointeeType = ArgType->getPointeeOrArrayElementType();
const Type *PointeeType =
ArgType->getPointerOrObjCPointerOrArrayElementType();
assert(PointeeType != nullptr && "PointeeType should always be available.");
QualType PointeeQualifiedType(PointeeType, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
else if (TypePtr->isFloatingType()) {
InitializationString = " = NAN";
AddMathInclude = true;
} else if (TypePtr->isAnyPointerType()) {
} else if (TypePtr->isPointerOrObjCObjectPointerType()) {
if (getLangOpts().CPlusPlus11)
InitializationString = " = nullptr";
else
Expand Down
2 changes: 1 addition & 1 deletion 2 clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static bool isTypedefTypeMatching(const TypedefType *const Typedef,
/// \returns type of the argument
static const Type *argumentType(const CallExpr *const CE, const size_t Idx) {
const QualType QT = CE->getArg(Idx)->IgnoreImpCasts()->getType();
return QT.getTypePtr()->getPointeeOrArrayElementType();
return QT.getTypePtr()->getPointerOrObjCPointerOrArrayElementType();
}

void TypeMismatchCheck::registerMatchers(MatchFinder *Finder) {
Expand Down
17 changes: 11 additions & 6 deletions 17 clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ StyleKind IdentifierNamingCheck::findStyleKind(
return SK_ConstexprVariable;

if (!Type.isNull() && Type.isConstQualified()) {
if (Type.getTypePtr()->isAnyPointerType() &&
if (Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_ConstantPointerParameter])
return SK_ConstantPointerParameter;

Expand All @@ -1232,7 +1232,8 @@ StyleKind IdentifierNamingCheck::findStyleKind(
if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
return SK_ParameterPack;

if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() &&
if (!Type.isNull() &&
Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_PointerParameter])
return SK_PointerParameter;

Expand Down Expand Up @@ -1508,7 +1509,8 @@ StyleKind IdentifierNamingCheck::findStyleKindForVar(
if (Var->isStaticDataMember() && NamingStyles[SK_ClassConstant])
return SK_ClassConstant;

if (Var->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
if (Var->isFileVarDecl() &&
Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_GlobalConstantPointer])
return SK_GlobalConstantPointer;

Expand All @@ -1518,7 +1520,8 @@ StyleKind IdentifierNamingCheck::findStyleKindForVar(
if (Var->isStaticLocal() && NamingStyles[SK_StaticConstant])
return SK_StaticConstant;

if (Var->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
if (Var->isLocalVarDecl() &&
Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_LocalConstantPointer])
return SK_LocalConstantPointer;

Expand All @@ -1535,7 +1538,8 @@ StyleKind IdentifierNamingCheck::findStyleKindForVar(
if (Var->isStaticDataMember() && NamingStyles[SK_ClassMember])
return SK_ClassMember;

if (Var->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
if (Var->isFileVarDecl() &&
Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_GlobalPointer])
return SK_GlobalPointer;

Expand All @@ -1545,7 +1549,8 @@ StyleKind IdentifierNamingCheck::findStyleKindForVar(
if (Var->isStaticLocal() && NamingStyles[SK_StaticVariable])
return SK_StaticVariable;

if (Var->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
if (Var->isLocalVarDecl() &&
Type.getTypePtr()->isPointerOrObjCObjectPointerType() &&
NamingStyles[SK_LocalPointer])
return SK_LocalPointer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType,

// Unless argument and param are both multilevel pointers, the types are not
// convertible.
if (!(ParamType->isAnyPointerType() && ArgType->isAnyPointerType()))
if (!(ParamType->isPointerOrObjCObjectPointerType() &&
ArgType->isPointerOrObjCObjectPointerType()))
return false;

return arePointerTypesCompatible(ArgType, ParamType, IsParamContinuouslyConst,
Expand Down
2 changes: 1 addition & 1 deletion 2 clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline bool isPointerOrPointerToMember(const Type *T) {
}

std::optional<QualType> getPointeeOrArrayElementQualType(QualType T) {
if (T->isAnyPointerType() || T->isMemberPointerType())
if (T->isPointerOrObjCObjectPointerType() || T->isMemberPointerType())
return T->getPointeeType();

if (T->isArrayType())
Expand Down
2 changes: 1 addition & 1 deletion 2 clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ bool isDefaultLibrary(const Decl *D) {
bool isDefaultLibrary(const Type *T) {
if (!T)
return false;
const Type *Underlying = T->getPointeeOrArrayElementType();
const Type *Underlying = T->getPointerOrObjCPointerOrArrayElementType();
if (Underlying->isBuiltinType())
return true;
if (auto *TD = dyn_cast<TemplateTypeParmType>(Underlying))
Expand Down
2 changes: 1 addition & 1 deletion 2 clang/include/clang/AST/CanonicalType.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class CanProxyBase {
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAnyPointerType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isPointerOrObjCObjectPointerType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidPointerType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isFunctionPointerType)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isMemberFunctionPointerType)
Expand Down
31 changes: 21 additions & 10 deletions 31 clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
bool isPointerType() const;
bool isPointerOrReferenceType() const;
bool isSignableType() const;
bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
bool isPointerOrObjCObjectPointerType()
const; // Any C pointer or ObjC object pointer
bool isCountAttributedType() const;
bool isBlockPointerType() const;
bool isVoidPointerType() const;
Expand Down Expand Up @@ -2862,13 +2863,23 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// This should never be used when type qualifiers are meaningful.
const Type *getArrayElementTypeNoTypeQual() const;

/// If this is a pointer type, return the pointee type.
/// If this is a C or ObjC pointer type, return the pointee type. Notably,
/// this does not handle things like member pointers or block pointers.
///
/// If this is an array type, return the array element type.
///
/// This should never be used when type qualifiers are meaningful.
const Type *getPointeeOrArrayElementType() const;
const Type *getPointerOrObjCPointerOrArrayElementType() const;

/// If this is a pointer, ObjC object pointer, or block
/// pointer, this returns the respective pointee.
/// Return the 'pointee type' for any of the following kinds of types,
/// and an empty QualType otherwise.
///
/// - PointerType
/// - ObjCObjectPointerType
/// - BlockPointerType
/// - ReferenceType
/// - MemberPointerType
/// - DecayedType
QualType getPointeeType() const;

/// Return the specified type with any "sugar" removed from the type,
Expand Down Expand Up @@ -8196,7 +8207,7 @@ inline bool Type::isPointerOrReferenceType() const {
return isPointerType() || isReferenceType();
}

inline bool Type::isAnyPointerType() const {
inline bool Type::isPointerOrObjCObjectPointerType() const {
return isPointerType() || isObjCObjectPointerType();
}

Expand Down Expand Up @@ -8656,8 +8667,8 @@ inline bool Type::isUndeducedType() const {
inline bool Type::isOverloadableType() const {
if (!isDependentType())
return isRecordType() || isEnumeralType();
return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
!isMemberPointerType();
return !isArrayType() && !isFunctionType() &&
!isPointerOrObjCObjectPointerType() && !isMemberPointerType();
}

/// Determines whether this type is written as a typedef-name.
Expand Down Expand Up @@ -8690,9 +8701,9 @@ inline const Type *Type::getBaseElementTypeUnsafe() const {
return type;
}

inline const Type *Type::getPointeeOrArrayElementType() const {
inline const Type *Type::getPointerOrObjCPointerOrArrayElementType() const {
const Type *type = this;
if (type->isAnyPointerType())
if (type->isPointerOrObjCObjectPointerType())
return type->getPointeeType().getTypePtr();
else if (type->isArrayType())
return type->getBaseElementTypeUnsafe();
Expand Down
4 changes: 2 additions & 2 deletions 4 clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,7 @@ AST_MATCHER_P(QualType, asString, std::string, Name) {
AST_MATCHER_P(
QualType, pointsTo, internal::Matcher<QualType>,
InnerMatcher) {
return (!Node.isNull() && Node->isAnyPointerType() &&
return (!Node.isNull() && Node->isPointerOrObjCObjectPointerType() &&
InnerMatcher.matches(Node->getPointeeType(), Finder, Builder));
}

Expand Down Expand Up @@ -6605,7 +6605,7 @@ AST_MATCHER(QualType, isAnyCharacter) {
/// varDecl(hasType(isAnyPointer()))
/// matches "int *i" and "Foo *f", but not "int j".
AST_MATCHER(QualType, isAnyPointer) {
return Node->isAnyPointerType();
return Node->isPointerOrObjCObjectPointerType();
}

/// Matches QualType nodes that are const-qualified, i.e., that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class SymbolicRegion : public SubRegion {
// Because pointer arithmetic is represented by ElementRegion layers,
// the base symbol here should not contain any arithmetic.
assert(isa_and_nonnull<SymbolData>(s));
assert(s->getType()->isAnyPointerType() ||
assert(s->getType()->isPointerOrObjCObjectPointerType() ||
s->getType()->isReferenceType() ||
s->getType()->isBlockPointerType());
assert(isa<UnknownSpaceRegion>(sreg) || isa<HeapSpaceRegion>(sreg) ||
Expand Down
17 changes: 11 additions & 6 deletions 17 clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ class SMTConv {
uint64_t FromBitWidth) {
if ((FromTy->isIntegralOrEnumerationType() &&
ToTy->isIntegralOrEnumerationType()) ||
(FromTy->isAnyPointerType() ^ ToTy->isAnyPointerType()) ||
(FromTy->isPointerOrObjCObjectPointerType() ^
ToTy->isPointerOrObjCObjectPointerType()) ||
(FromTy->isBlockPointerType() ^ ToTy->isBlockPointerType()) ||
(FromTy->isReferenceType() ^ ToTy->isReferenceType())) {

Expand Down Expand Up @@ -365,7 +366,8 @@ class SMTConv {

// If the two operands are pointers and the operation is a subtraction,
// the result is of type ptrdiff_t, which is signed
if (LTy->isAnyPointerType() && RTy->isAnyPointerType() && Op == BO_Sub) {
if (LTy->isPointerOrObjCObjectPointerType() &&
RTy->isPointerOrObjCObjectPointerType() && Op == BO_Sub) {
*RetTy = Ctx.getPointerDiffType();
}
}
Expand Down Expand Up @@ -509,8 +511,9 @@ class SMTConv {
Solver->mkFloat(Zero));
}

if (Ty->isIntegralOrEnumerationType() || Ty->isAnyPointerType() ||
Ty->isBlockPointerType() || Ty->isReferenceType()) {
if (Ty->isIntegralOrEnumerationType() ||
Ty->isPointerOrObjCObjectPointerType() || Ty->isBlockPointerType() ||
Ty->isReferenceType()) {

// Skip explicit comparison for boolean types
bool isSigned = Ty->isSignedIntegerOrEnumerationType();
Expand Down Expand Up @@ -613,7 +616,8 @@ class SMTConv {
return;
}

if ((LTy->isAnyPointerType() || RTy->isAnyPointerType()) ||
if ((LTy->isPointerOrObjCObjectPointerType() ||
RTy->isPointerOrObjCObjectPointerType()) ||
(LTy->isBlockPointerType() || RTy->isBlockPointerType()) ||
(LTy->isReferenceType() || RTy->isReferenceType())) {
// TODO: Refactor to Sema::FindCompositePointerType(), and
Expand All @@ -624,7 +628,8 @@ class SMTConv {

// Cast the non-pointer type to the pointer type.
// TODO: Be more strict about this.
if ((LTy->isAnyPointerType() ^ RTy->isAnyPointerType()) ||
if ((LTy->isPointerOrObjCObjectPointerType() ^
RTy->isPointerOrObjCObjectPointerType()) ||
(LTy->isBlockPointerType() ^ RTy->isBlockPointerType()) ||
(LTy->isReferenceType() ^ RTy->isReferenceType())) {
if (LTy->isNullPtrType() || LTy->isBlockPointerType() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ class SValBuilder {
/// space.
/// \param type pointer type.
loc::ConcreteInt makeNullWithType(QualType type) {
// We cannot use the `isAnyPointerType()`.
assert((type->isPointerType() || type->isObjCObjectPointerType() ||
assert((type->isPointerOrObjCObjectPointerType() ||
type->isBlockPointerType() || type->isNullPtrType() ||
type->isReferenceType()) &&
"makeNullWithType must use pointer type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class Loc : public DefinedSVal {
void dumpToStream(raw_ostream &Out) const;

static bool isLocType(QualType T) {
return T->isAnyPointerType() || T->isBlockPointerType() ||
return T->isPointerOrObjCObjectPointerType() || T->isBlockPointerType() ||
T->isReferenceType() || T->isNullPtrType();
}

Expand Down
4 changes: 2 additions & 2 deletions 4 clang/lib/ARCMigrate/ObjCMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
}

static bool TypeIsInnerPointer(QualType T) {
if (!T->isAnyPointerType())
if (!T->isPointerOrObjCObjectPointerType())
return false;
if (T->isObjCObjectPointerType() || T->isObjCBuiltinType() ||
T->isBlockPointerType() || T->isFunctionPointerType() ||
Expand Down Expand Up @@ -1366,7 +1366,7 @@ static bool IsVoidStarType(QualType Ty) {
/// CF object types or of the "void *" variety. It returns true if we don't care about the type
/// such as a non-pointer or pointers which have no ownership issues (such as "int *").
static bool AuditedType (QualType AT) {
if (!AT->isAnyPointerType() && !AT->isBlockPointerType())
if (!AT->isPointerOrObjCObjectPointerType() && !AT->isBlockPointerType())
return true;
// FIXME. There isn't much we can say about CF pointer type; or is there?
if (ento::coreFoundation::isCFObjectRef(AT) ||
Expand Down
10 changes: 5 additions & 5 deletions 10 clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,9 +2980,9 @@ bool ASTContext::isSentinelNullExpr(const Expr *E) {
// nullptr_t is always treated as null.
if (E->getType()->isNullPtrType()) return true;

if (E->getType()->isAnyPointerType() &&
E->IgnoreParenCasts()->isNullPointerConstant(*this,
Expr::NPC_ValueDependentIsNull))
if (E->getType()->isPointerOrObjCObjectPointerType() &&
E->IgnoreParenCasts()->isNullPointerConstant(
*this, Expr::NPC_ValueDependentIsNull))
return true;

// Unfortunately, __null has type 'int'.
Expand Down Expand Up @@ -3518,7 +3518,7 @@ QualType ASTContext::getObjCGCQualType(QualType T,

if (const auto *ptr = T->getAs<PointerType>()) {
QualType Pointee = ptr->getPointeeType();
if (Pointee->isAnyPointerType()) {
if (Pointee->isPointerOrObjCObjectPointerType()) {
QualType ResultType = getObjCGCQualType(Pointee, GCAttr);
return getPointerType(ResultType);
}
Expand Down Expand Up @@ -10101,7 +10101,7 @@ Qualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const {
QualType CT = Ty->getCanonicalTypeInternal();
while (const auto *AT = dyn_cast<ArrayType>(CT))
CT = AT->getElementType();
assert(CT->isAnyPointerType() || CT->isBlockPointerType());
assert(CT->isPointerOrObjCObjectPointerType() || CT->isBlockPointerType());
#endif
}
return GCAttrs;
Expand Down
2 changes: 1 addition & 1 deletion 2 clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ Error ASTNodeImporter::ImportDeclParts(
FunDecl->hasBody()) {
auto getLeafPointeeType = [](const Type *T) {
while (T->isPointerType() || T->isArrayType()) {
T = T->getPointeeOrArrayElementType();
T = T->getPointerOrObjCPointerOrArrayElementType();
}
return T;
};
Expand Down
4 changes: 2 additions & 2 deletions 4 clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ bool CastExpr::CastConsistency() const {

case CK_AnyPointerToBlockPointerCast:
assert(getType()->isBlockPointerType());
assert(getSubExpr()->getType()->isAnyPointerType() &&
assert(getSubExpr()->getType()->isPointerOrObjCObjectPointerType() &&
!getSubExpr()->getType()->isBlockPointerType());
goto CheckNoBasePath;

Expand Down Expand Up @@ -5199,7 +5199,7 @@ QualType ArraySectionExpr::getBaseOriginalType(const Expr *Base) {
OriginalTy = PVD->getOriginalType().getNonReferenceType();

for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
if (OriginalTy->isAnyPointerType())
if (OriginalTy->isPointerOrObjCObjectPointerType())
OriginalTy = OriginalTy->getPointeeType();
else if (OriginalTy->isArrayType())
OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
Expand Down
2 changes: 1 addition & 1 deletion 2 clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
if (!ThisArg)
return nullptr;

if (ThisArg->getType()->isAnyPointerType())
if (ThisArg->getType()->isPointerOrObjCObjectPointerType())
return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();

return ThisArg->getType()->getAsCXXRecordDecl();
Expand Down
2 changes: 1 addition & 1 deletion 2 clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc,
if (auto *FD = dyn_cast_or_null<FunctionDecl>(BaseVD);
FD && FD->isImmediateFunction()) {
Info.FFDiag(Loc, diag::note_consteval_address_accessible)
<< !Type->isAnyPointerType();
<< !Type->isPointerOrObjCObjectPointerType();
Info.Note(FD->getLocation(), diag::note_declared_at);
return false;
}
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.