aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-13 18:37:02 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-13 18:37:02 +0000
commitdb87bca211deed14f8d5bb9ef25b8e9ee5c8e139 (patch)
tree5703930f1d2150e941f791accf4b6df5085256f7
parenta36c48676c0a48953c1a0885fa333be5851bbf94 (diff)
Added -Wfloat-equal option to the driver. This makes warnings about
floating point comparisons using == or != an opt-in rather than a default warning. Updated test case to use -Wfloat-equal. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44053 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/clang.cpp8
-rw-r--r--test/Sema/floating-point-compare.c2
2 files changed, 9 insertions, 1 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index f568302444..5897da32a3 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -356,6 +356,10 @@ static llvm::cl::opt<bool>
WarnUnusedMacros("Wunused_macros",
llvm::cl::desc("Warn for unused macros in the main translation unit"));
+static llvm::cl::opt<bool>
+WarnFloatEqual("Wfloat-equal",
+ llvm::cl::desc("Warn about equality comparisons of floating point values."));
+
/// InitializeDiagnostics - Initialize the diagnostic object, based on the
/// current command line option settings.
static void InitializeDiagnostics(Diagnostic &Diags) {
@@ -366,6 +370,10 @@ static void InitializeDiagnostics(Diagnostic &Diags) {
// Silence the "macro is not used" warning unless requested.
if (!WarnUnusedMacros)
Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
+
+ // Silence "floating point comparison" warnings unless requested.
+ if (!WarnFloatEqual)
+ Diags.setDiagnosticMapping(diag::warn_floatingpoint_eq, diag::MAP_IGNORE);
}
//===----------------------------------------------------------------------===//
diff --git a/test/Sema/floating-point-compare.c b/test/Sema/floating-point-compare.c
index 62388915a2..cc96be0fd3 100644
--- a/test/Sema/floating-point-compare.c
+++ b/test/Sema/floating-point-compare.c
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -Wfloat-equal -verify %s
int foo(float x, float y) {
return x == y; // expected-warning {{comparing floating point with ==}}