Skip to content

Commit 1961f9f

Browse files
authored
[clang][NFC] Add Type::isPointerOrReferenceType() (#101206)
Seems to be a common pattern.
1 parent 20d723e commit 1961f9f

File tree

12 files changed

+23
-23
lines changed

12 files changed

+23
-23
lines changed

clang/include/clang/AST/Type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
25092509
bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
25102510
bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
25112511
bool isPointerType() const;
2512+
bool isPointerOrReferenceType() const;
25122513
bool isSignableType() const;
25132514
bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
25142515
bool isCountAttributedType() const;
@@ -7996,6 +7997,10 @@ inline bool Type::isPointerType() const {
79967997
return isa<PointerType>(CanonicalType);
79977998
}
79987999

8000+
inline bool Type::isPointerOrReferenceType() const {
8001+
return isPointerType() || isReferenceType();
8002+
}
8003+
79998004
inline bool Type::isAnyPointerType() const {
80008005
return isPointerType() || isObjCObjectPointerType();
80018006
}

clang/include/clang/Sema/Overload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ class Sema;
984984
unsigned getNumParams() const {
985985
if (IsSurrogate) {
986986
QualType STy = Surrogate->getConversionType();
987-
while (STy->isPointerType() || STy->isReferenceType())
987+
while (STy->isPointerOrReferenceType())
988988
STy = STy->getPointeeType();
989989
return STy->castAs<FunctionProtoType>()->getNumParams();
990990
}

clang/lib/AST/ExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool CXXTypeidExpr::isMostDerived(ASTContext &Context) const {
152152
const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Context);
153153
if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
154154
QualType Ty = DRE->getDecl()->getType();
155-
if (!Ty->isPointerType() && !Ty->isReferenceType())
155+
if (!Ty->isPointerOrReferenceType())
156156
return true;
157157
}
158158

clang/lib/AST/Interp/Context.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ std::optional<PrimType> Context::classify(QualType T) const {
176176
T->isFunctionType())
177177
return PT_FnPtr;
178178

179-
if (T->isReferenceType() || T->isPointerType() ||
180-
T->isObjCObjectPointerType())
179+
if (T->isPointerOrReferenceType() || T->isObjCObjectPointerType())
181180
return PT_Ptr;
182181

183182
if (const auto *AT = T->getAs<AtomicType>())

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6484,7 +6484,7 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
64846484

64856485
case APValue::LValue: {
64866486
// Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
6487-
assert((T->isPointerType() || T->isReferenceType()) &&
6487+
assert((T->isPointerOrReferenceType()) &&
64886488
"unexpected type for LValue template arg");
64896489

64906490
if (V.isNullPointer()) {

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
7575
const IdentifierInfo* QualType::getBaseTypeIdentifier() const {
7676
const Type* ty = getTypePtr();
7777
NamedDecl *ND = nullptr;
78-
if (ty->isPointerType() || ty->isReferenceType())
78+
if (ty->isPointerOrReferenceType())
7979
return ty->getPointeeType().getBaseTypeIdentifier();
8080
else if (ty->isRecordType())
8181
ND = ty->castAs<RecordType>()->getDecl();

clang/lib/Analysis/Consumed.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static bool isCallableInState(const CallableWhenAttr *CWAttr,
141141
}
142142

143143
static bool isConsumableType(const QualType &QT) {
144-
if (QT->isPointerType() || QT->isReferenceType())
144+
if (QT->isPointerOrReferenceType())
145145
return false;
146146

147147
if (const CXXRecordDecl *RD = QT->getAsCXXRecordDecl())
@@ -151,7 +151,7 @@ static bool isConsumableType(const QualType &QT) {
151151
}
152152

153153
static bool isAutoCastType(const QualType &QT) {
154-
if (QT->isPointerType() || QT->isReferenceType())
154+
if (QT->isPointerOrReferenceType())
155155
return false;
156156

157157
if (const CXXRecordDecl *RD = QT->getAsCXXRecordDecl())
@@ -186,10 +186,6 @@ static bool isTestingFunction(const FunctionDecl *FunDecl) {
186186
return FunDecl->hasAttr<TestTypestateAttr>();
187187
}
188188

189-
static bool isPointerOrRef(QualType ParamType) {
190-
return ParamType->isPointerType() || ParamType->isReferenceType();
191-
}
192-
193189
static ConsumedState mapConsumableAttrState(const QualType QT) {
194190
assert(isConsumableType(QT));
195191

@@ -648,7 +644,7 @@ bool ConsumedStmtVisitor::handleCall(const CallExpr *Call, const Expr *ObjArg,
648644
setStateForVarOrTmp(StateMap, PInfo, mapReturnTypestateAttrState(RT));
649645
else if (isRValueRef(ParamType) || isConsumableType(ParamType))
650646
setStateForVarOrTmp(StateMap, PInfo, consumed::CS_Consumed);
651-
else if (isPointerOrRef(ParamType) &&
647+
else if (ParamType->isPointerOrReferenceType() &&
652648
(!ParamType->getPointeeType().isConstQualified() ||
653649
isSetOnReadPtrType(ParamType)))
654650
setStateForVarOrTmp(StateMap, PInfo, consumed::CS_Unknown);

clang/lib/Analysis/ThreadSafetyCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static StringRef ClassifyDiagnostic(QualType VDT) {
9797
if (const auto *TD = TT->getDecl())
9898
if (const auto *CA = TD->getAttr<CapabilityAttr>())
9999
return ClassifyDiagnostic(CA);
100-
} else if (VDT->isPointerType() || VDT->isReferenceType())
100+
} else if (VDT->isPointerOrReferenceType())
101101
return ClassifyDiagnostic(VDT->getPointeeType());
102102

103103
return "mutex";

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5887,7 +5887,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) {
58875887

58885888
static QualType getCoreType(QualType Ty) {
58895889
do {
5890-
if (Ty->isPointerType() || Ty->isReferenceType())
5890+
if (Ty->isPointerOrReferenceType())
58915891
Ty = Ty->getPointeeType();
58925892
else if (Ty->isArrayType())
58935893
Ty = Ty->castAsArrayTypeUnsafe()->getElementType();
@@ -9339,7 +9339,7 @@ static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT) {
93399339
if (PT->isDependentType())
93409340
return InvalidKernelParam;
93419341

9342-
if (PT->isPointerType() || PT->isReferenceType()) {
9342+
if (PT->isPointerOrReferenceType()) {
93439343
QualType PointeeType = PT->getPointeeType();
93449344
if (PointeeType.getAddressSpace() == LangAS::opencl_generic ||
93459345
PointeeType.getAddressSpace() == LangAS::opencl_private ||
@@ -10789,10 +10789,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1078910789
if (getLangOpts().getOpenCLCompatibleVersion() >= 200) {
1079010790
if(const PipeType *PipeTy = PT->getAs<PipeType>()) {
1079110791
QualType ElemTy = PipeTy->getElementType();
10792-
if (ElemTy->isReferenceType() || ElemTy->isPointerType()) {
10793-
Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type );
10794-
D.setInvalidType();
10795-
}
10792+
if (ElemTy->isPointerOrReferenceType()) {
10793+
Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type);
10794+
D.setInvalidType();
10795+
}
1079610796
}
1079710797
}
1079810798
// WebAssembly tables can't be used as function parameters.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5992,7 +5992,7 @@ static void handleMSAllocatorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
59925992
// Warn if the return type is not a pointer or reference type.
59935993
if (auto *FD = dyn_cast<FunctionDecl>(D)) {
59945994
QualType RetTy = FD->getReturnType();
5995-
if (!RetTy->isPointerType() && !RetTy->isReferenceType()) {
5995+
if (!RetTy->isPointerOrReferenceType()) {
59965996
S.Diag(AL.getLoc(), diag::warn_declspec_allocator_nonpointer)
59975997
<< AL.getRange() << RetTy;
59985998
return;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ getUuidAttrOfType(Sema &SemaRef, QualType QT,
711711
llvm::SmallSetVector<const UuidAttr *, 1> &UuidAttrs) {
712712
// Optionally remove one level of pointer, reference or array indirection.
713713
const Type *Ty = QT.getTypePtr();
714-
if (QT->isPointerType() || QT->isReferenceType())
714+
if (QT->isPointerOrReferenceType())
715715
Ty = QT->getPointeeType().getTypePtr();
716716
else if (QT->isArrayType())
717717
Ty = Ty->getBaseElementTypeUnsafe();

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6719,7 +6719,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
67196719
auto *VD = const_cast<ValueDecl *>(Base.dyn_cast<const ValueDecl *>());
67206720
// For a non-type template-parameter of pointer or reference type,
67216721
// the value of the constant expression shall not refer to
6722-
assert(ParamType->isPointerType() || ParamType->isReferenceType() ||
6722+
assert(ParamType->isPointerOrReferenceType() ||
67236723
ParamType->isNullPtrType());
67246724
// -- a temporary object
67256725
// -- a string literal

0 commit comments

Comments
 (0)