[cfe-commits] r133383 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp lib/Sema/SemaExpr.cpp test/SemaCXX/null_in_arithmetic_ops.cpp test/SemaCXX/nullptr_in_arithmetic_ops.cpp
Chandler Carruth
chandlerc at gmail.com
Mon Jun 20 08:36:08 PDT 2011
On Mon, Jun 20, 2011 at 8:10 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> 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()
>
I really like this name, but I ended up nuking the predicate altogether
after talking with John. The user I had in mind was in fact not an
appropriate user of it. For now, I suspect 'canDecayToPointerType' will work
well as the predicate. Comments on that one appreciated though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110620/035b20cc/attachment.html>
More information about the cfe-commits
mailing list