[cfe-commits] r133405 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp lib/Sema/SemaExpr.cpp
Chandler Carruth
chandlerc at gmail.com
Sun Jun 19 18:23:20 PDT 2011
Author: chandlerc
Date: Sun Jun 19 20:23:19 2011
New Revision: 133405
URL: http://llvm.org/viewvc/llvm-project?rev=133405&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=133405&r1=133404&r2=133405&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Jun 19 20:23:19 2011
@@ -1456,7 +1456,9 @@
/// \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::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 @@
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());
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=133405&r1=133404&r2=133405&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Jun 19 20:23:19 2011
@@ -288,32 +288,6 @@
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();
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=133405&r1=133404&r2=133405&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Jun 19 20:23:19 2011
@@ -8963,7 +8963,10 @@
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());
More information about the cfe-commits
mailing list