[cfe-commits] r55778 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaExpr.cpp

Steve Naroff snaroff at apple.com
Thu Sep 4 09:56:15 PDT 2008


Author: snaroff
Date: Thu Sep  4 11:56:14 2008
New Revision: 55778

URL: http://llvm.org/viewvc/llvm-project?rev=55778&view=rev
Log:
Touchup CheckSingleAssignmentConstraints() and CheckCompareOperands() to check for block pointers.
Added a couple FIXME's wrt PointLikeType. If the author reads this, it would be great to get some background on this class (thanks in advance).

Modified:
    cfe/trunk/include/clang/AST/Type.h
    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=55778&r1=55777&r2=55778&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Sep  4 11:56:14 2008
@@ -530,6 +530,9 @@
 };
 
 /// PointerLikeType - Common base class for pointers and references.
+/// FIXME: Add more documentation on this classes design point. For example,
+/// should BlockPointerType inherit from it? Is the concept of a PointerLikeType
+/// in the C++ standard?
 ///
 class PointerLikeType : public Type {
   QualType PointeeType;
@@ -577,6 +580,9 @@
 /// BlockPointerType - pointer to a block type.
 /// This type is to represent types syntactically represented as
 /// "void (^)(int)", etc. Pointee is required to always be a function type.
+/// FIXME: Should BlockPointerType inherit from PointerLikeType? It could
+/// simplfy some type checking code, however PointerLikeType doesn't appear
+/// to be used by the type checker.
 ///
 class BlockPointerType : public Type, public llvm::FoldingSetNode {
   QualType PointeeType;  // Block is some kind of pointer type

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=55778&r1=55777&r2=55778&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep  4 11:56:14 2008
@@ -1578,7 +1578,8 @@
 Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) {
   // C99 6.5.16.1p1: the left operand is a pointer and the right is
   // a null pointer constant.
-  if ((lhsType->isPointerType() || lhsType->isObjCQualifiedIdType()) 
+  if ((lhsType->isPointerType() || lhsType->isObjCQualifiedIdType() ||
+       lhsType->isBlockPointerType()) 
       && rExpr->isNullPointerConstant(Context)) {
     ImpCastExprToType(rExpr, lhsType);
     return Compatible;
@@ -1944,6 +1945,23 @@
     ImpCastExprToType(lex, rType); // promote the integer to pointer
     return Context.IntTy;
   }
+  // Handle block pointers.
+  if (lType->isBlockPointerType() && rType->isIntegerType()) {
+    if (!RHSIsNull)
+      Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+           lType.getAsString(), rType.getAsString(),
+           lex->getSourceRange(), rex->getSourceRange());
+    ImpCastExprToType(rex, lType); // promote the integer to pointer
+    return Context.IntTy;
+  }
+  if (lType->isIntegerType() && rType->isBlockPointerType()) {
+    if (!LHSIsNull)
+      Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+           lType.getAsString(), rType.getAsString(),
+           lex->getSourceRange(), rex->getSourceRange());
+    ImpCastExprToType(lex, rType); // promote the integer to pointer
+    return Context.IntTy;
+  }
   return InvalidOperands(loc, lex, rex);
 }
 





More information about the cfe-commits mailing list