On Jun 19, 2011, at 2:05 AM, Chandler Carruth wrote: > Author: chandlerc > Date: Sun Jun 19 04:05:14 2011 > New Revision: 133383 > > URL: http://llvm.org/viewvc/llvm-project?rev=133383&view=rev > Log: > 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.
Comment below about this name… > Modified: > cfe/trunk/include/clang/AST/Type.h > cfe/trunk/lib/AST/Type.cpp > cfe/trunk/lib/Sema/SemaExpr.cpp > cfe/trunk/test/SemaCXX/null_in_arithmetic_ops.cpp > cfe/trunk/test/SemaCXX/nullptr_in_arithmetic_ops.cpp > > Modified: cfe/trunk/include/clang/AST/Type.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=133383&r1=133382&r2=133383&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/Type.h (original) > +++ cfe/trunk/include/clang/AST/Type.h Sun Jun 19 04:05:14 2011 > @@ -1373,6 +1373,7 @@ > bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } > bool isPointerType() const; > bool isAnyPointerType() const; // Any C pointer or ObjC object pointer > + bool isPointerLikeType() const; > bool isBlockPointerType() const; > bool isVoidPointerType() const; > bool isReferenceType() const; > > Modified: cfe/trunk/lib/AST/Type.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=133383&r1=133382&r2=133383&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/Type.cpp (original) > +++ cfe/trunk/lib/AST/Type.cpp Sun Jun 19 04:05:14 2011 > @@ -289,6 +289,31 @@ > } > } > > +/// \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; > + } > +} > + Since this also includes function and array types, I'd like to indicate that in some way… for example isPointerLikeRvalueType() or hasPointerLikeDecayedType() - Doug _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
