[cfe-commits] r164143 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/Analysis/additive-folding.cpp test/Sema/compare.c test/Sema/outof-range-constant-compare.c test/SemaCXX/compare.cpp test/SemaCXX/for-range-examples.cpp test/SemaCXX/warn-enum-compare.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 18 10:37:21 PDT 2012
Author: fjahanian
Date: Tue Sep 18 12:37:21 2012
New Revision: 164143
URL: http://llvm.org/viewvc/llvm-project?rev=164143&view=rev
Log:
c: warn when an integer value comparison with an
integral expression have the obvious result.
Patch reviewed by John McCall off line.
// rdar://12202422
Added:
cfe/trunk/test/Sema/outof-range-constant-compare.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Analysis/additive-folding.cpp
cfe/trunk/test/Sema/compare.c
cfe/trunk/test/SemaCXX/compare.cpp
cfe/trunk/test/SemaCXX/for-range-examples.cpp
cfe/trunk/test/SemaCXX/warn-enum-compare.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Sep 18 12:37:21 2012
@@ -196,6 +196,7 @@
def StringPlusInt : DiagGroup<"string-plus-int">;
def StrncatSize : DiagGroup<"strncat-size">;
def TautologicalCompare : DiagGroup<"tautological-compare">;
+def TautologicalOutofRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
def HeaderHygiene : DiagGroup<"header-hygiene">;
def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 18 12:37:21 2012
@@ -4068,6 +4068,9 @@
def warn_lunsigned_always_true_comparison : Warning<
"comparison of unsigned%select{| enum}2 expression %0 is always %1">,
InGroup<TautologicalCompare>;
+def warn_outof_range_compare : Warning<
+ "comparison of literal %0 with expression of type %1 is always "
+ "%select{false|true}2">, InGroup<TautologicalOutofRangeCompare>;
def warn_runsigned_always_true_comparison : Warning<
"comparison of %0 unsigned%select{| enum}2 expression is always %1">,
InGroup<TautologicalCompare>;
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 18 12:37:21 2012
@@ -4301,6 +4301,45 @@
}
}
+static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E,
+ Expr *lit, Expr *other,
+ llvm::APSInt Value,
+ bool rhsLiteral) {
+ BinaryOperatorKind op = E->getOpcode();
+ QualType OtherT = other->getType();
+ const Type *OtherPtrT = S.Context.getCanonicalType(OtherT).getTypePtr();
+ const Type *LitPtrT = S.Context.getCanonicalType(lit->getType()).getTypePtr();
+ if (OtherPtrT == LitPtrT)
+ return;
+ assert((OtherT->isIntegerType() && LitPtrT->isIntegerType())
+ && "comparison with non-integer type");
+ IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+ IntRange LitRange = GetExprRange(S.Context, lit);
+ if (OtherRange.Width >= LitRange.Width)
+ return;
+ std::string PrettySourceValue = Value.toString(10);
+ bool IsTrue = true;
+ if (op == BO_EQ)
+ IsTrue = false;
+ else if (op == BO_NE)
+ IsTrue = true;
+ else if (rhsLiteral) {
+ if (op == BO_GT || op == BO_GE)
+ IsTrue = !LitRange.NonNegative;
+ else // op == BO_LT || op == BO_LE
+ IsTrue = LitRange.NonNegative;
+ }
+ else {
+ if (op == BO_LT || op == BO_LE)
+ IsTrue = !LitRange.NonNegative;
+ else // op == BO_GT || op == BO_GE
+ IsTrue = LitRange.NonNegative;
+ }
+ S.Diag(E->getOperatorLoc(), diag::warn_outof_range_compare)
+ << PrettySourceValue << other->getType() << IsTrue
+ << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
+}
+
/// Analyze the operands of the given comparison. Implements the
/// fallback case from AnalyzeComparison.
static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {
@@ -4317,19 +4356,42 @@
assert(S.Context.hasSameUnqualifiedType(T, E->getRHS()->getType())
&& "comparison with mismatched types");
+ Expr *LHS = E->getLHS()->IgnoreParenImpCasts();
+ Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
+ if (E->isValueDependent())
+ return AnalyzeImpConvsInComparison(S, E);
+
+ bool IsComparisonConstant = false;
+
+ // Check that an integer constant comparison results in a value
+ // of 'true' or 'false'.
+ if (T->isIntegralType(S.Context)) {
+ llvm::APSInt RHSValue;
+ bool IsRHSIntegralLiteral =
+ RHS->isIntegerConstantExpr(RHSValue, S.Context);
+ llvm::APSInt LHSValue;
+ bool IsLHSIntegralLiteral =
+ LHS->isIntegerConstantExpr(LHSValue, S.Context);
+ if (IsRHSIntegralLiteral && !IsLHSIntegralLiteral)
+ DiagnoseOutOfRangeComparison(S, E, RHS, LHS, RHSValue, true);
+ else if (!IsRHSIntegralLiteral && IsLHSIntegralLiteral)
+ DiagnoseOutOfRangeComparison(S, E, LHS, RHS, LHSValue, false);
+ else
+ IsComparisonConstant =
+ (IsRHSIntegralLiteral && IsLHSIntegralLiteral);
+ }
+ else if (!T->hasUnsignedIntegerRepresentation())
+ IsComparisonConstant = E->isIntegerConstantExpr(S.Context);
+
// We don't do anything special if this isn't an unsigned integral
// comparison: we're only interested in integral comparisons, and
// signed comparisons only happen in cases we don't care to warn about.
//
// We also don't care about value-dependent expressions or expressions
// whose result is a constant.
- if (!T->hasUnsignedIntegerRepresentation()
- || E->isValueDependent() || E->isIntegerConstantExpr(S.Context))
+ if (!T->hasUnsignedIntegerRepresentation() || IsComparisonConstant)
return AnalyzeImpConvsInComparison(S, E);
-
- Expr *LHS = E->getLHS()->IgnoreParenImpCasts();
- Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
-
+
// Check to see if one of the (unmodified) operands is of different
// signedness.
Expr *signedOperand, *unsignedOperand;
Modified: cfe/trunk/test/Analysis/additive-folding.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/additive-folding.cpp?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/additive-folding.cpp (original)
+++ cfe/trunk/test/Analysis/additive-folding.cpp Tue Sep 18 12:37:21 2012
@@ -128,10 +128,10 @@
// Tautologies from outside the range of the symbol
void tautologiesOutside(unsigned char a) {
- clang_analyzer_eval(a <= 0x100); // expected-warning{{TRUE}}
- clang_analyzer_eval(a < 0x100); // expected-warning{{TRUE}}
+ clang_analyzer_eval(a <= 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}
+ clang_analyzer_eval(a < 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}
- clang_analyzer_eval(a != 0x100); // expected-warning{{TRUE}}
+ clang_analyzer_eval(a != 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}
clang_analyzer_eval(a != -1); // expected-warning{{TRUE}}
clang_analyzer_eval(a > -1); // expected-warning{{TRUE}}
Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Tue Sep 18 12:37:21 2012
@@ -93,8 +93,8 @@
// (C,b)
(C == (unsigned long) b) +
(C == (unsigned int) b) +
- (C == (unsigned short) b) +
- (C == (unsigned char) b) +
+ (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}
+ (C == (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}
((long) C == b) +
((int) C == b) +
((short) C == b) +
@@ -105,8 +105,8 @@
((signed char) C == (unsigned char) b) +
(C < (unsigned long) b) +
(C < (unsigned int) b) +
- (C < (unsigned short) b) +
- (C < (unsigned char) b) +
+ (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}
+ (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}
((long) C < b) +
((int) C < b) +
((short) C < b) +
@@ -123,8 +123,8 @@
(a == (unsigned char) C) +
((long) a == C) +
((int) a == C) +
- ((short) a == C) +
- ((signed char) a == C) +
+ ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}}
+ ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}}
((long) a == (unsigned long) C) +
((int) a == (unsigned int) C) +
((short) a == (unsigned short) C) +
@@ -135,8 +135,8 @@
(a < (unsigned char) C) +
((long) a < C) +
((int) a < C) +
- ((short) a < C) +
- ((signed char) a < C) +
+ ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}}
+ ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}}
((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}}
((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}}
((short) a < (unsigned short) C) +
@@ -145,8 +145,8 @@
// (0x80000,b)
(0x80000 == (unsigned long) b) +
(0x80000 == (unsigned int) b) +
- (0x80000 == (unsigned short) b) +
- (0x80000 == (unsigned char) b) +
+ (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}
+ (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}
((long) 0x80000 == b) +
((int) 0x80000 == b) +
((short) 0x80000 == b) +
@@ -157,8 +157,8 @@
((signed char) 0x80000 == (unsigned char) b) +
(0x80000 < (unsigned long) b) +
(0x80000 < (unsigned int) b) +
- (0x80000 < (unsigned short) b) +
- (0x80000 < (unsigned char) b) +
+ (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}
+ (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}
((long) 0x80000 < b) +
((int) 0x80000 < b) +
((short) 0x80000 < b) +
@@ -175,8 +175,8 @@
(a == (unsigned char) 0x80000) +
((long) a == 0x80000) +
((int) a == 0x80000) +
- ((short) a == 0x80000) +
- ((signed char) a == 0x80000) +
+ ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}}
+ ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}}
((long) a == (unsigned long) 0x80000) +
((int) a == (unsigned int) 0x80000) +
((short) a == (unsigned short) 0x80000) +
@@ -187,8 +187,8 @@
(a < (unsigned char) 0x80000) +
((long) a < 0x80000) +
((int) a < 0x80000) +
- ((short) a < 0x80000) +
- ((signed char) a < 0x80000) +
+ ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}}
+ ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}}
((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}}
((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}}
((short) a < (unsigned short) 0x80000) +
Added: cfe/trunk/test/Sema/outof-range-constant-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/outof-range-constant-compare.c?rev=164143&view=auto
==============================================================================
--- cfe/trunk/test/Sema/outof-range-constant-compare.c (added)
+++ cfe/trunk/test/Sema/outof-range-constant-compare.c Tue Sep 18 12:37:21 2012
@@ -0,0 +1,149 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s
+// rdar://12202422
+
+int value(void);
+
+int main()
+{
+ int a = value();
+ if (a == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (a < 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (a <= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (a > 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a >= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+
+ if (0x1234567812345678L == a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (0x1234567812345678L != a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (0x1234567812345678L < a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (0x1234567812345678L <= a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (0x1234567812345678L > a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (0x1234567812345678L >= a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (a == 0x1234567812345678LL) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a == -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a < -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a > -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+ if (a <= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}
+ return 0;
+ if (a >= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}}
+ return 0;
+
+
+ if (a == 0x12345678L) // no warning
+ return 1;
+
+ short s = value();
+ if (s == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+ if (s != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ if (s < 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ if (s <= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ if (s > 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+ if (s >= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+
+ if (0x1234567812345678L == s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+ if (0x1234567812345678L != s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ if (0x1234567812345678L < s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+ if (0x1234567812345678L <= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}
+ return 0;
+ if (0x1234567812345678L > s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ if (0x1234567812345678L >= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}
+ return 0;
+ long l = value();
+ if (l == 0x1234567812345678L)
+ return 0;
+ if (l != 0x1234567812345678L)
+ return 0;
+ if (l < 0x1234567812345678L)
+ return 0;
+ if (l <= 0x1234567812345678L)
+ return 0;
+ if (l > 0x1234567812345678L)
+ return 0;
+ if (l >= 0x1234567812345678L)
+ return 0;
+
+ if (0x1234567812345678L == l)
+ return 0;
+ if (0x1234567812345678L != l)
+ return 0;
+ if (0x1234567812345678L < l)
+ return 0;
+ if (0x1234567812345678L <= l)
+ return 0;
+ if (0x1234567812345678L > l)
+ return 0;
+ if (0x1234567812345678L >= l)
+ return 0;
+
+ unsigned un = 0;
+ if (un == 0x0000000000000000L)
+ return 0;
+ if (un != 0x0000000000000000L)
+ return 0;
+ if (un < 0x0000000000000000L)
+ return 0;
+ if (un <= 0x0000000000000000L)
+ return 0;
+ if (un > 0x0000000000000000L)
+ return 0;
+ if (un >= 0x0000000000000000L)
+ return 0;
+
+ if (0x0000000000000000L == un)
+ return 0;
+ if (0x0000000000000000L != un)
+ return 0;
+ if (0x0000000000000000L < un)
+ return 0;
+ if (0x0000000000000000L <= un)
+ return 0;
+ if (0x0000000000000000L > un)
+ return 0;
+ if (0x0000000000000000L >= un)
+ return 0;
+ float fl = 0;
+ if (fl == 0x0000000000000000L) // no warning
+ return 0;
+
+ float dl = 0;
+ if (dl == 0x0000000000000000L) // no warning
+ return 0;
+
+ enum E {
+ yes,
+ no,
+ maybe
+ };
+ enum E e;
+
+ if (e == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'enum E' is always false}}
+ return 0;
+
+ return 1;
+}
Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Tue Sep 18 12:37:21 2012
@@ -89,8 +89,8 @@
// (C,b)
(C == (unsigned long) b) +
(C == (unsigned int) b) +
- (C == (unsigned short) b) +
- (C == (unsigned char) b) +
+ (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}
+ (C == (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}
((long) C == b) +
((int) C == b) +
((short) C == b) +
@@ -101,8 +101,8 @@
((signed char) C == (unsigned char) b) +
(C < (unsigned long) b) +
(C < (unsigned int) b) +
- (C < (unsigned short) b) +
- (C < (unsigned char) b) +
+ (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}
+ (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}
((long) C < b) +
((int) C < b) +
((short) C < b) +
@@ -119,8 +119,8 @@
(a == (unsigned char) C) +
((long) a == C) +
((int) a == C) +
- ((short) a == C) +
- ((signed char) a == C) +
+ ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}}
+ ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}}
((long) a == (unsigned long) C) +
((int) a == (unsigned int) C) +
((short) a == (unsigned short) C) +
@@ -131,8 +131,8 @@
(a < (unsigned char) C) +
((long) a < C) +
((int) a < C) +
- ((short) a < C) +
- ((signed char) a < C) +
+ ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}}
+ ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}}
((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}}
((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}}
((short) a < (unsigned short) C) +
@@ -141,8 +141,8 @@
// (0x80000,b)
(0x80000 == (unsigned long) b) +
(0x80000 == (unsigned int) b) +
- (0x80000 == (unsigned short) b) +
- (0x80000 == (unsigned char) b) +
+ (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}
+ (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}
((long) 0x80000 == b) +
((int) 0x80000 == b) +
((short) 0x80000 == b) +
@@ -153,8 +153,8 @@
((signed char) 0x80000 == (unsigned char) b) +
(0x80000 < (unsigned long) b) +
(0x80000 < (unsigned int) b) +
- (0x80000 < (unsigned short) b) +
- (0x80000 < (unsigned char) b) +
+ (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}
+ (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}
((long) 0x80000 < b) +
((int) 0x80000 < b) +
((short) 0x80000 < b) +
@@ -171,8 +171,8 @@
(a == (unsigned char) 0x80000) +
((long) a == 0x80000) +
((int) a == 0x80000) +
- ((short) a == 0x80000) +
- ((signed char) a == 0x80000) +
+ ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}}
+ ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}}
((long) a == (unsigned long) 0x80000) +
((int) a == (unsigned int) 0x80000) +
((short) a == (unsigned short) 0x80000) +
@@ -183,8 +183,8 @@
(a < (unsigned char) 0x80000) +
((long) a < 0x80000) +
((int) a < 0x80000) +
- ((short) a < 0x80000) +
- ((signed char) a < 0x80000) +
+ ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}}
+ ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}}
((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}}
((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}}
((short) a < (unsigned short) 0x80000) +
Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original)
+++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Tue Sep 18 12:37:21 2012
@@ -122,12 +122,12 @@
for (auto n : range(1, 5)) {
total += n;
}
- assert(total == 10);
+ assert((total == 10));
for (auto n : range(10, 100, 10)) {
total += n;
}
- assert(total == 460);
+ assert((total == 460));
map_range::vector<char> chars;
chars.push_back('a');
@@ -136,7 +136,7 @@
for (char c : chars) {
++total;
}
- assert(total == 463);
+ assert((total == 463));
typedef map_range::tuple<int, double> T;
map_range::vector<T> pairs;
@@ -146,7 +146,7 @@
for (auto a : map(map_range::mem_fun(&T::get<int>), pairs)) {
total += a;
}
- assert(total == 500);
+ assert((total == 500));
}
// PR11793
Modified: cfe/trunk/test/SemaCXX/warn-enum-compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=164143&r1=164142&r2=164143&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-enum-compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-enum-compare.cpp Tue Sep 18 12:37:21 2012
@@ -39,8 +39,8 @@
while (b == c);
while (B1 == name1::B2);
while (B2 == name2::B1);
- while (x == AnonAA);
- while (AnonBB == y);
+ while (x == AnonAA); // expected-warning {{comparison of literal 42 with expression of type 'Foo' is always false}}
+ while (AnonBB == y); // expected-warning {{comparison of literal 45 with expression of type 'Bar' is always false}}
while (AnonAA == AnonAB);
while (AnonAB == AnonBA);
while (AnonBB == AnonAA);
More information about the cfe-commits
mailing list