Introduce Type::isAnyPointerType() and convert all clients (suggested by Chris).
I don't love the name, however it simplifies the code and is a worthwhile change. If/when we come up with a better name, we can do a search/replace.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75650 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
index d3f7b5b..7ddf90b 100644
--- a/include/clang/AST/Type.h
+++ b/include/clang/AST/Type.h
@@ -375,6 +375,7 @@
bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; }
bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; }
bool isPointerType() const;
+ bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
bool isBlockPointerType() const;
bool isVoidPointerType() const;
bool isReferenceType() const;
@@ -2120,6 +2121,9 @@
inline bool Type::isPointerType() const {
return isa<PointerType>(CanonicalType.getUnqualifiedType());
}
+inline bool Type::isAnyPointerType() const {
+ return isPointerType() || isObjCObjectPointerType();
+}
inline bool Type::isBlockPointerType() const {
return isa<BlockPointerType>(CanonicalType.getUnqualifiedType());
}
diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h
index 0a42548..2ba370e 100644
--- a/include/clang/Analysis/PathSensitive/SVals.h
+++ b/include/clang/Analysis/PathSensitive/SVals.h
@@ -200,8 +200,7 @@
}
static inline bool IsLocType(QualType T) {
- return T->isPointerType() || T->isObjCObjectPointerType()
- || T->isBlockPointerType();
+ return T->isAnyPointerType() || T->isBlockPointerType();
}
};
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 971f2da..13f35dc 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1088,7 +1088,7 @@
if (T->isPointerType()) {
QualType Pointee = T->getAsPointerType()->getPointeeType();
- if (Pointee->isPointerType() || Pointee->isObjCObjectPointerType()) {
+ if (Pointee->isAnyPointerType()) {
QualType ResultType = getObjCGCQualType(Pointee, GCAttr);
return getPointerType(ResultType);
}
diff --git a/lib/Analysis/CheckObjCInstMethSignature.cpp b/lib/Analysis/CheckObjCInstMethSignature.cpp
index c4e586d..c208a7c 100644
--- a/lib/Analysis/CheckObjCInstMethSignature.cpp
+++ b/lib/Analysis/CheckObjCInstMethSignature.cpp
@@ -30,8 +30,7 @@
// Right now don't compare the compatibility of pointers. That involves
// looking at subtyping relationships. FIXME: Future patch.
- if ((Derived->isPointerType() || Derived->isObjCObjectPointerType()) &&
- (Ancestor->isPointerType() || Ancestor->isObjCObjectPointerType()))
+ if (Derived->isAnyPointerType() && Ancestor->isAnyPointerType())
return true;
return C.typesAreCompatible(Derived, Ancestor);
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 17d2c13..14c4ac6 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -986,7 +986,7 @@
}
Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
- if (!Ops.Ty->isPointerType() && !Ops.Ty->isObjCObjectPointerType()) {
+ if (!Ops.Ty->isAnyPointerType()) {
if (CGF.getContext().getLangOptions().OverflowChecking &&
Ops.Ty->isSignedIntegerType())
return EmitOverflowCheckedBinOp(Ops);
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 3ae9c35..66d2cdc 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -3094,14 +3094,12 @@
}
// C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
// the type of the other operand."
- if ((LHSTy->isPointerType() || LHSTy->isBlockPointerType() ||
- LHSTy->isObjCObjectPointerType()) &&
+ if ((LHSTy->isAnyPointerType() || LHSTy->isBlockPointerType()) &&
RHS->isNullPointerConstant(Context)) {
ImpCastExprToType(RHS, LHSTy); // promote the null to a pointer.
return LHSTy;
}
- if ((RHSTy->isPointerType() || RHSTy->isBlockPointerType() ||
- RHSTy->isObjCObjectPointerType()) &&
+ if ((RHSTy->isAnyPointerType() || RHSTy->isBlockPointerType()) &&
LHS->isNullPointerConstant(Context)) {
ImpCastExprToType(LHS, RHSTy); // promote the null to a pointer.
return RHSTy;
@@ -3823,12 +3821,10 @@
// Put any potential pointer into PExp
Expr* PExp = lex, *IExp = rex;
- if (IExp->getType()->isPointerType() ||
- IExp->getType()->isObjCObjectPointerType())
+ if (IExp->getType()->isAnyPointerType())
std::swap(PExp, IExp);
- if (PExp->getType()->isPointerType() ||
- PExp->getType()->isObjCObjectPointerType()) {
+ if (PExp->getType()->isAnyPointerType()) {
if (IExp->getType()->isIntegerType()) {
QualType PointeeTy = PExp->getType()->getPointeeType();
@@ -3912,8 +3908,7 @@
}
// Either ptr - int or ptr - ptr.
- if (lex->getType()->isPointerType() ||
- lex->getType()->isObjCObjectPointerType()) {
+ if (lex->getType()->isAnyPointerType()) {
QualType lpointee = lex->getType()->getPointeeType();
// The LHS must be an completely-defined object type.
@@ -4293,8 +4288,7 @@
return ResultTy;
}
}
- if ((lType->isPointerType() || lType->isObjCObjectPointerType()) &&
- rType->isIntegerType()) {
+ if (lType->isAnyPointerType() && rType->isIntegerType()) {
if (isRelational)
Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
@@ -4304,8 +4298,7 @@
ImpCastExprToType(rex, lType); // promote the integer to pointer
return ResultTy;
}
- if (lType->isIntegerType() &&
- (rType->isPointerType() || rType->isObjCObjectPointerType())) {
+ if (lType->isIntegerType() && rType->isAnyPointerType()) {
if (isRelational)
Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
@@ -4578,15 +4571,9 @@
Diag(OpLoc, diag::warn_increment_bool) << Op->getSourceRange();
} else if (ResType->isRealType()) {
// OK!
- } else if (ResType->getAsPointerType() ||ResType->isObjCObjectPointerType()) {
- QualType PointeeTy;
+ } else if (ResType->isAnyPointerType()) {
+ QualType PointeeTy = ResType->getPointeeType();
- if (const PointerType *PTy = ResType->getAsPointerType())
- PointeeTy = PTy->getPointeeType();
- else if (const ObjCObjectPointerType *OPT =
- ResType->getAsObjCObjectPointerType())
- PointeeTy = OPT->getPointeeType();
-
// C99 6.5.2.4p2, 6.5.6p2
if (PointeeTy->isVoidType()) {
if (getLangOptions().CPlusPlus) {
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index ac3afa8..144dc50 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -1482,8 +1482,7 @@
QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) {
assert(getLangOptions().CPlusPlus && "This function assumes C++");
QualType T1 = E1->getType(), T2 = E2->getType();
- if(!T1->isPointerType() && !T2->isPointerType() &&
- !T1->isObjCObjectPointerType() && !T2->isObjCObjectPointerType())
+ if(!T1->isAnyPointerType() && !T2->isAnyPointerType())
return QualType();
// C++0x 5.9p2