diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-06-20 01:23:19 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-06-20 01:23:19 +0000 |
commit | bc8d7f9fd4346cfcc285868be32b74e019a40f01 (patch) | |
tree | 84a36df59f9b9cf232b57ebbe842dd42db30088f | |
parent | 085d09d14365cef1faa7a376730911227ee39ee3 (diff) |
Restructure the API in Type based on a conversation with Richard Smith.
This makes 'isPointerLikeType' a little less confusing, and pulls the
decay check into a separate interface that is much more clear and
concrete. Also, just implement these as logical wrappers around other
predicates. Having a switch based implementation isn't likely to be
necessary. We can try to optimize them later if they show up on
a profile.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133405 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Type.h | 22 | ||||
-rw-r--r-- | lib/AST/Type.cpp | 26 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 |
3 files changed, 25 insertions, 28 deletions
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 08d6202966..5f5b53a222 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1456,7 +1456,9 @@ public: /// \brief Determine wither this type is a C++ elaborated-type-specifier. bool isElaboratedTypeSpecifier() const; - + + bool canDecayToPointerType() const; + /// hasPointerRepresentation - Whether this type is represented /// natively as a pointer; this includes pointers, references, block /// pointers, and Objective-C interface, qualified id, and qualified @@ -4515,6 +4517,19 @@ inline bool Type::isPointerType() const { inline bool Type::isAnyPointerType() const { return isPointerType() || isObjCObjectPointerType(); } + +/// \brief Tests whether the type behaves like a pointer type. +/// +/// This includes all of the pointer types including block pointers, +/// member pointers, and ObjC Object pointers. +/// +/// Note that this is distinct from hasPointerRepresentation. +/// +/// \returns True for types which behave like pointer types. +inline bool Type::isPointerLikeType() const { + return isAnyPointerType() || isBlockPointerType() || isMemberPointerType(); +} + inline bool Type::isBlockPointerType() const { return isa<BlockPointerType>(CanonicalType); } @@ -4649,6 +4664,11 @@ inline bool Type::isOverloadableType() const { return isDependentType() || isRecordType() || isEnumeralType(); } +/// \brief Determines whether this type can decay to a pointer type. +inline bool Type::canDecayToPointerType() const { + return isFunctionType() || isArrayType(); +} + inline bool Type::hasPointerRepresentation() const { return (isPointerType() || isReferenceType() || isBlockPointerType() || isObjCObjectPointerType() || isNullPtrType()); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index b30f8966b6..583cb5d57c 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -288,32 +288,6 @@ bool Type::isDerivedType() const { return false; } } - -/// \brief Tests whether the type behaves like a pointer type. -/// -/// This includes all of the obviously pointer types including block pointers, -/// member pointers, and ObjC Object pointers. It also includes function and -/// array types which behave as pointers due to decay. -/// -/// \returns True for types which act like pointer types. -bool Type::isPointerLikeType() const { - switch (CanonicalType->getTypeClass()) { - case Pointer: - case BlockPointer: - case MemberPointer: - case ConstantArray: - case IncompleteArray: - case VariableArray: - case DependentSizedArray: - case FunctionProto: - case FunctionNoProto: - case ObjCObjectPointer: - return true; - default: - return false; - } -} - bool Type::isClassType() const { if (const RecordType *RT = getAs<RecordType>()) return RT->getDecl()->isClass(); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 15751d078b..42ec82ac4a 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8963,7 +8963,10 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, QualType LeftType = lhs.get()->getType(); QualType RightType = rhs.get()->getType(); if (LeftNull != RightNull && - !LeftType->isPointerLikeType() && !RightType->isPointerLikeType()) { + !LeftType->isPointerLikeType() && + !LeftType->canDecayToPointerType() && + !RightType->isPointerLikeType() && + !RightType->canDecayToPointerType()) { Diag(OpLoc, diag::warn_null_in_arithmetic_operation) << (LeftNull ? lhs.get()->getSourceRange() : rhs.get()->getSourceRange()); |