[cfe-commits] r71189 - in /cfe/branches/Apple/Dib: lib/Sema/SemaExpr.cpp test/Sema/block-misc.c

Mike Stump mrs at apple.com
Thu May 7 15:28:13 PDT 2009


Author: mrs
Date: Thu May  7 17:28:13 2009
New Revision: 71189

URL: http://llvm.org/viewvc/llvm-project?rev=71189&view=rev
Log:
Merge in 71171:

Tighten up relationals with blocks and ints.  Radar 6441502

Modified:
    cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
    cfe/branches/Apple/Dib/test/Sema/block-misc.c

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp?rev=71189&r1=71188&r2=71189&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp Thu May  7 17:28:13 2009
@@ -2795,8 +2795,10 @@
   // pointer constants in case both operands are null pointer constants.
   if ((LHSPT || LHSBPT) && (RHSPT || RHSBPT)) { // C99 6.5.15p3,6
     // get the "pointed to" types
-    QualType lhptee = LHSPT ? LHSPT->getPointeeType() : LHSBPT->getPointeeType();
-    QualType rhptee = RHSPT ? RHSPT->getPointeeType() : RHSBPT->getPointeeType();
+    QualType lhptee = (LHSPT ? LHSPT->getPointeeType()
+                       : LHSBPT->getPointeeType());
+      QualType rhptee = (RHSPT ? RHSPT->getPointeeType()
+                         : RHSBPT->getPointeeType());
 
     // ignore qualifiers on void (C99 6.5.15p3, clause 6)
     if (lhptee->isVoidType()
@@ -3518,7 +3520,8 @@
   // Enforce type constraints: C99 6.5.6p3.
 
   // Handle the common case first (both operands are arithmetic).
-  if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) {
+  if (lex->getType()->isArithmeticType()
+      && rex->getType()->isArithmeticType()) {
     if (CompLHSTy) *CompLHSTy = compType;
     return compType;
   }
@@ -3680,7 +3683,8 @@
   QualType lType = lex->getType();
   QualType rType = rex->getType();
 
-  if (!lType->isFloatingType() && !(lType->isBlockPointerType() && isRelational)) {
+  if (!lType->isFloatingType()
+      && !(lType->isBlockPointerType() && isRelational)) {
     // For non-floating point types, check for self-comparisons of the form
     // x == x, x != x, x < x, etc.  These always evaluate to a constant, and
     // often indicate logic errors in the program.
@@ -3880,23 +3884,13 @@
     return ResultTy;
   }
   // Handle block pointers.
-  if (lType->isBlockPointerType() && rType->isIntegerType()) {
-    if (isRelational)
-      Diag(Loc, diag::err_typecheck_invalid_operands)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-    else if (!RHSIsNull)
-      Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+  if (!isRelational && RHSIsNull
+      && lType->isBlockPointerType() && rType->isIntegerType()) {
     ImpCastExprToType(rex, lType); // promote the integer to pointer
     return ResultTy;
   }
-  if (lType->isIntegerType() && rType->isBlockPointerType()) {
-    if (isRelational)
-      Diag(Loc, diag::err_typecheck_invalid_operands)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-    else if (!LHSIsNull)
-      Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+  if (!isRelational && LHSIsNull
+      && lType->isIntegerType() && rType->isBlockPointerType()) {
     ImpCastExprToType(lex, rType); // promote the integer to pointer
     return ResultTy;
   }
@@ -4931,7 +4925,7 @@
 }
 
 void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
-  assert(ParamInfo.getIdentifier() == 0 && "block-id should have no identifier!");
+  assert(ParamInfo.getIdentifier()==0 && "block-id should have no identifier!");
 
   ProcessDeclAttributes(CurBlock->TheDecl, ParamInfo);
 

Modified: cfe/branches/Apple/Dib/test/Sema/block-misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Sema/block-misc.c?rev=71189&r1=71188&r2=71189&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Sema/block-misc.c (original)
+++ cfe/branches/Apple/Dib/test/Sema/block-misc.c Thu May  7 17:28:13 2009
@@ -171,4 +171,12 @@
   (void)(bp > bp); // expected-error {{invalid operands}}
   (void)(bp > vp); // expected-error {{invalid operands}}
   f(1 ? bp : rp); // expected-error {{incompatible operand types ('void (^)(int)' and 'void (*)(int)')}}
+  (void)(bp == 1); // expected-error {{invalid operands to binary expression}}
+  (void)(bp == 0);
+  (void)(1 == bp); // expected-error {{invalid operands to binary expression}}
+  (void)(0 == bp);
+  (void)(bp < 1); // expected-error {{invalid operands to binary expression}}
+  (void)(bp < 0); // expected-error {{invalid operands to binary expression}}
+  (void)(1 < bp); // expected-error {{invalid operands to binary expression}}
+  (void)(0 < bp); // expected-error {{invalid operands to binary expression}}
 }





More information about the cfe-commits mailing list