diff options
author | Tanya Lattner <tonic@nondot.org> | 2009-08-22 23:06:10 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2009-08-22 23:06:10 +0000 |
commit | 8a2a4f246b3dc9b36e2c3270f789dc090226b813 (patch) | |
tree | 5943cb69227e293486aad9fe1d7008a8c281db40 | |
parent | 616c94aa56e843fa512c2f0780cc9fc932ed2353 (diff) |
Merge from mainline.
tweak some pointer sema checking stuff (which was added to implement PR4175) to
avoid emitting a warning on "someptr > 0". This is obviously questionable (they
could use != instead) but is reasonable, and the warning "ordered comparison
between pointer and integer" didn't make a ton of sense because 0 is a valid
null pointer constant.
Just silence the warning in this case, it is unlikely to indicate a bug.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_26@79783 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 26 | ||||
-rw-r--r-- | test/Sema/compare.c | 14 |
2 files changed, 19 insertions, 21 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 5f16ef3d13..15a3e40e3f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4350,31 +4350,33 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, return ResultTy; } if (lType->isObjCObjectPointerType() && rType->isObjCObjectPointerType()) { - if (!Context.areComparableObjCPointerTypes(lType, rType)) { + if (!Context.areComparableObjCPointerTypes(lType, rType)) Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); - } ImpCastExprToType(rex, lType); return ResultTy; } } if (lType->isAnyPointerType() && rType->isIntegerType()) { - if (isRelational) - Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer) - << lType << rType << lex->getSourceRange() << rex->getSourceRange(); - else if (!RHSIsNull) - Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer) + if (!RHSIsNull) { + unsigned DiagID = isRelational + ? diag::ext_typecheck_ordered_comparison_of_pointer_integer + : diag::ext_typecheck_comparison_of_pointer_integer; + Diag(Loc, DiagID) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); + } ImpCastExprToType(rex, lType); // promote the integer to pointer return ResultTy; } if (lType->isIntegerType() && rType->isAnyPointerType()) { - if (isRelational) - Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer) - << lType << rType << lex->getSourceRange() << rex->getSourceRange(); - else if (!LHSIsNull) - Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer) + if (!LHSIsNull) { + unsigned DiagID = isRelational + ? diag::ext_typecheck_ordered_comparison_of_pointer_integer + : diag::ext_typecheck_comparison_of_pointer_integer; + + Diag(Loc, DiagID) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); + } ImpCastExprToType(lex, rType); // promote the integer to pointer return ResultTy; } diff --git a/test/Sema/compare.c b/test/Sema/compare.c index b7c5c25ddb..2afaab523b 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -8,8 +8,7 @@ int test(char *C) { // nothing here should warn. return C != 0; } -int equal(char *a, const char *b) -{ +int equal(char *a, const char *b) { return a == b; } @@ -18,21 +17,18 @@ int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) { return a == b; // expected-warning {{comparison of distinct pointer types}} } -int pointers(int *a) -{ - return a > 0; // expected-warning {{ordered comparison between pointer and integer}} +int pointers(int *a) { + return a > 0; // no warning. rdar://7163039 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}} } -int function_pointers(int (*a)(int), int (*b)(int)) -{ +int function_pointers(int (*a)(int), int (*b)(int)) { return a > b; // expected-warning {{ordered comparison of function pointers}} return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}} return a == (void *) 0; return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}} } -int void_pointers(void *foo) -{ +int void_pointers(void *foo) { return foo == NULL; } |