diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-06-19 09:05:14 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-06-19 09:05:14 +0000 |
commit | 2af68e4761ed30181540dafb5572993daffa4910 (patch) | |
tree | a53c7e2d4eaf30c6511feb0524827b53d470e982 /lib/AST/Type.cpp | |
parent | e3d49b44ad0596b2998ecf2e7ca78d59188920e5 (diff) |
Add test cases for false positives on -Wnull-arithmetic from Richard
Trieu, and fix them by checking for array and function types as well as
pointer types.
I've added a predicate method on Type to bundle together the logic we're
using here: isPointerLikeType(). I'd welcome better names for this
predicate, this is the best I came up with. It's implemented as a switch
to be a touch lighter weight than all the chained isa<...> casts that
would result otherwise.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 080bca2198..b30f8966b6 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -289,6 +289,31 @@ bool Type::isDerivedType() const { } } +/// \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(); |