r198913 - Make the tautological out of range warning use Sema::DiagRuntimeBehavior so that
Richard Trieu
rtrieu at google.com
Thu Jan 9 20:38:10 PST 2014
Author: rtrieu
Date: Thu Jan 9 22:38:09 2014
New Revision: 198913
URL: http://llvm.org/viewvc/llvm-project?rev=198913&view=rev
Log:
Make the tautological out of range warning use Sema::DiagRuntimeBehavior so that
the warning will not trigger on code protected by compile time checks.
Added:
cfe/trunk/test/SemaCXX/warn-tautological-compare.cpp
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=198913&r1=198912&r2=198913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Jan 9 22:38:09 2014
@@ -4970,9 +4970,11 @@ static void DiagnoseOutOfRangeComparison
else
OS << Value;
- S.Diag(E->getOperatorLoc(), diag::warn_out_of_range_compare)
- << OS.str() << OtherT << IsTrue
- << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
+ S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
+ S.PDiag(diag::warn_out_of_range_compare)
+ << OS.str() << OtherT << IsTrue
+ << E->getLHS()->getSourceRange()
+ << E->getRHS()->getSourceRange());
}
/// Analyze the operands of the given comparison. Implements the
Added: cfe/trunk/test/SemaCXX/warn-tautological-compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-tautological-compare.cpp?rev=198913&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-tautological-compare.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-tautological-compare.cpp Thu Jan 9 22:38:09 2014
@@ -0,0 +1,27 @@
+// Force x86-64 because some of our heuristics are actually based
+// on integer sizes.
+
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -std=c++11 %s
+
+namespace RuntimeBehavior {
+ // Avoid emitting tautological compare warnings when the code already has
+ // compile time checks on variable sizes.
+
+ const int kintmax = 2147483647;
+ void test0(short x) {
+ if (sizeof(x) < sizeof(int) || x < kintmax) {}
+
+ if (x < kintmax) {}
+ // expected-warning at -1{{comparison of constant 2147483647 with expression of type 'short' is always true}}
+ }
+
+ void test1(short x) {
+ if (x < kintmax) {}
+ // expected-warning at -1{{comparison of constant 2147483647 with expression of type 'short' is always true}}
+
+ if (sizeof(x) < sizeof(int))
+ return;
+
+ if (x < kintmax) {}
+ }
+}
More information about the cfe-commits
mailing list